Skip to content
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

Merged
merged 1 commit into from Jul 2, 2018
Merged

Conversation

stockholmux
Copy link
Member

Redis 5.0 RC-1 was released on Tuesday. This release includes new sorted set and stream commands.

@chenosaurus
Copy link

will this be merged soon? Waiting to use the new stream methods in node.

@stockholmux
Copy link
Member Author

@chenosaurus You can use it now with redis.addCommand - that's what I do in the mean time.

stipsan pushed a commit to stipsan/ioredis-mock that referenced this pull request Jun 23, 2018
…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();
```
stipsan added a commit to stipsan/ioredis-mock that referenced this pull request Jun 23, 2018
## 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();
```
@Kezzo
Copy link

Kezzo commented Jun 30, 2018

Would be nice if this could be merged. redis.addCommand works, but having direct support via a function in https://github.com/NodeRedis/node_redis is just comfortable and saves time from everyone trying to understand why the function doesn't exist. It's especially confusion because both the GitHub repository and the npm page of the main module claim that the plugin supports ALL commands:

This is a complete and feature rich Redis client for node.js. It supports all Redis commands and focuses on high performance.

@BridgeAR BridgeAR merged commit 651d159 into NodeRedis:master Jul 2, 2018
@BridgeAR
Copy link
Member

BridgeAR commented Jul 2, 2018

Thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants