Closed akeyboardlife closed 5 years ago
Hi @akeyboardlife!
It is actually a good idea, which I would really encourage, to use a key/value store such as Redis as storage for the microservice. Resgate's resource IDs (rid) translates well to the key in the key/value store. Redis' hashes should translate well to Resgate's models, and Redis' lists should translate fairly well to Resgate's collections.
Now, I must admit, I haven't used Redis in any project myself, so I have little experience with it. We've more used simpler key/value stores such as LevelDB or BadgerDB, or if we've needed proper indexing and such, we've used MongoDB.
But the sharding of a Redis cluster would probably work well with the sort of sharding (briefly described on Resgate.io).
In the backlog, I have a story to make a generic storage service with NATS/Resgate. It is not yet decided what sort of storage it will use, but Redis is one of the possible options.
The RES protocol revolves around resources, and events are always sent on a resource. You subscribe to a resource, and then you will receive the events for that resource. But if you only want events, and you don't need any resource data, you can use a static empty dummy model. The resource could then be considered more like a streaming channel.
For a node.js service, it would look like this:
nats.subscribe("get.test.channel.myevents", (msg, reply) => {
nats.publish(reply, '{"result":{"model":{}}}');
});
// To publish a foo event
nats.publish("event.test.channel.myevents.foo", '{"bar":42}');
The web client would fetch dummy-model as usual:
let client = new ResClient('ws://localhost:8080');
client.get('test.channel.myevents').then(channel => {
channel.on('foo', (e) => {
console.log("Foo event: ", e);
});
});
There are golang Redis implementation that support Clustering.
https://github.com/tidwall/redcon
Also for storgae and indexing using badger i am using https://github.com/mosuka/blast It supports clustering and federation also which has just been finished: https://github.com/mosuka/blast/tree/federation This federation logic can be used for Cete below. Its really nice.
For a Key Value store that also supports Federation and Clustering use https://github.com/mosuka/cete Its builton the same base foundation as Blast, in that it uses Badger with Raft.
I’m closing this issue because it has been inactive for a few months
For those looking further into support for Redis, you might want to check out the BadgerDB middleware in the go-res package for Go. A similar middleware for Redis should be rather basic to create.
I personally use Redis as the backend storage.
How to let the client listen to certain event based on the resource id without a cached resource?