New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added commands for Redis 5 rc1 #20
Conversation
will this be merged soon? Waiting to use the new stream methods in node. |
@chenosaurus You can use it now with |
…449) Support basic stream operations (https://redis.io/topics/streams-intro) for the upcoming Redis 5 release. Some features are missing, such as consumer groups, capped streams or some of the auxiliary commands. Event ids are auto incremented integers in the form of `1-0`, `2-0`, etc. Events are stored internally as an array of arrays and for every event an additional record is kept whether the event has been already polled or not. ``` const redis = new MockRedis({ mystream: [ ["1-0", ["key1", "val1", "key2", "val2"]], ["2-0", ["key1", "val1", "key2", "val2"]] ], "stream:mystream:1-0": {polled: false}, "stream:mystream:2-0": {polled: false}, }) ``` To poll events in a blocking manner is supported and the poll happens every 100ms. ``` // This will resolve once a new event becomes available. redis.xread("BLOCK", "0", "STREAMS", "mystream", "$").then(console.log); // After 1 second add a new event, that will resolve the waiting `XREAD` // command. setTimeout(() => redis.xadd("mystream", "*", "key", "val"), 1000); ``` `ioredis` doesn't support Redis streams yet, but there is [pull request for `redis-commands`](NodeRedis/redis-commands#20) to add support. In the meantime `ioredis`' `createBuiltinCommand` can be used to add support manually: ``` import Redis from "ioredis"; const {string: xadd} = Redis.prototype.createBuiltinCommand("xadd"); const {string: xread} = Redis.prototype.createBuiltinCommand("xread"); Redis.prototype.xadd = xadd; Redis.prototype.xread = xread; const redis = new Redis(); ```
## Added ### `xadd`, `xlen`, `xrange`, `xrevrange` and `xread` for stream support (#449 @critocrito) Support basic stream operations (https://redis.io/topics/streams-intro) for the upcoming Redis 5 release. Some features are missing, such as consumer groups, capped streams or some of the auxiliary commands. Event ids are auto incremented integers in the form of `1-0`, `2-0`, etc. Events are stored internally as an array of arrays and for every event an additional record is kept whether the event has been already polled or not. ``` const redis = new MockRedis({ mystream: [ ["1-0", ["key1", "val1", "key2", "val2"]], ["2-0", ["key1", "val1", "key2", "val2"]] ], "stream:mystream:1-0": {polled: false}, "stream:mystream:2-0": {polled: false}, }) ``` To poll events in a blocking manner is supported and the poll happens every 100ms. ``` // This will resolve once a new event becomes available. redis.xread("BLOCK", "0", "STREAMS", "mystream", "$").then(console.log); // After 1 second add a new event, that will resolve the waiting `XREAD` // command. setTimeout(() => redis.xadd("mystream", "*", "key", "val"), 1000); ``` `ioredis` doesn't support Redis streams yet, but there is [pull request for `redis-commands`](NodeRedis/redis-commands#20) to add support. In the meantime `ioredis`' `createBuiltinCommand` can be used to add support manually: ``` import Redis from "ioredis"; const {string: xadd} = Redis.prototype.createBuiltinCommand("xadd"); const {string: xread} = Redis.prototype.createBuiltinCommand("xread"); Redis.prototype.xadd = xadd; Redis.prototype.xread = xread; const redis = new Redis(); ```
Would be nice if this could be merged.
|
Thanks a lot. |
Redis 5.0 RC-1 was released on Tuesday. This release includes new sorted set and stream commands.