Has anyone put together Redis Pub/Sub + Meteor Pub/Sub?

Has anyone been able to get Redis pub/sub working with Meteor’s pub/sub? It seems like a perfect fit.

I know that Slavko had a package, redis-livedata, but as far as I know it has some issues and hasn’t been maintained in years. I also think it tried to do a bit too much, such as editing Redis data from client.

1 Like

If I understand correctly - I think this is what redis-oplog is doing, using redis pub/sub messaging to handle realtime changes by publishing to same channel with name matching the collection name.

1 Like

Yeah it sounds like they basically have it working. I just wish they would expose a way to work with Redis directly instead of using it behind the scenes.

1 Like

As far as I know, redis-oplog just makes use of the redis pub/sub mechanism. It doesn’t make use of any redis “database” methods.

Redis is actually one of the easiest databases to use with Meteor - even reactively, since it has inbuilt notifications of mutations. When used with Promises it’s also insanely fast.

1 Like

It sounds like it. Are you using it in your app? I would love to see some samples of it working with Meteor’s reactivity system.

@msavin We can file a feature request: to expose a way to work with Redis directly (or expose redis methods) using redis-oplog. @diaconutheodor, the creator of redis-oplog can say something about this. He’s done a great job on performance.

Indeed - I brought it up in the thread but it doesn’t look like there was much interest. I think this could be pretty easy to DIY - you would mainly need to use a Redis package off NPM. I am just unfamiliar with the internals of Meteor’s pub/sub and how to get the two to play along.

Yes, we are.

We use node-redis with hand-rolled Promise wrappers. However, you could equally well just follow the doc and wrap everything in Bluebird Promises (you may need to jump through some small hoops with this approach, as BB Promises don’t play nicely with Fibers).

Basically, set up and subscribe to redis keyspace notifications. Then use Meteor’s pub/sub API (this.added/changed/removed) to publish mutations to clients when notified.

However, if you want an isomorphic client/server API you’ll have to roll your own. From memory, @slava wrote a “miniredis” for a small subset of redis methods, which could perhaps be used as a base. We were happy with server-only redis for our app.

1 Like