node_redis ZRANGEBYLEX返回“ERR min或max无效字符串范围项”错误

时间:2016-02-16 04:48:55

标签: node.js redis node-redis

解决。解决方案如下,感谢@hobbs,我纠正了它。

我正在使用node_redis包。

以下是我通过cli使用ZRANGEBYLEX命令的方法。

127.0.0.1:6379> zadd movie 0 "Creed:2015:id1"
(integer) 1
127.0.0.1:6379> zadd movie 0 "Secret in Their Eyes:2015:id2"
(integer) 1
127.0.0.1:6379> zadd movie 0 "Spotlight:2015:id3"
(integer) 1
127.0.0.1:6379> zadd movie 0 "The Lobster:2015:id4"
(integer) 1
127.0.0.1:6379> zadd movie 0 "The Corpse of Anna Fritz:2015:id5"
(integer) 1
127.0.0.1:6379> zadd movie 0 "The Martian:2015:id6"
(integer) 1
127.0.0.1:6379> zadd movie 0 "The Revenant:2015:id7"
(integer) 1
127.0.0.1:6379> zadd movie 0 "Steve Jobs:2015:id8"
(integer) 1

获取所有以“The”字开头的电影。

127.0.0.1:6379> zrangebylex movie "[The" "(The\xff"
1) "The Corpse of Anna Fritz:2015:id5"
2) "The Lobster:2015:id4"
3) "The Martian:2015:id6"
4) "The Revenant:2015:id7"

到目前为止,非常好。

前两项。

zrangebylex movie "[The" "(The\xff" limit 0 2
1) "The Corpse of Anna Fritz:2015:id5"
2) "The Lobster:2015:id4"

这是我尝试用Node.js做同样的事情,但是我收到了一个错误。

var redis = require("redis");
var client = redis.createClient();

app.get('/redis', function(req, res) {
  var args2 = ["movie", "The", "The", 'LIMIT', 0, 2];
  client.zrangebylex(args2, function(err, response) {
    if (err) throw err;
    console.log(response);
  });
});

这是完整的错误日志。

Error: ERR min or max not valid string range item
www-0     at Error (native)
www-0     at HiredisReplyParser.return_data (/Users/me/Desktop/project/node_modules/redis/lib/parsers/hiredis.js:14:28)
www-0     at HiredisReplyParser.execute (/Users/me/Desktop/project/node_modules/redis/lib/parsers/hiredis.js:24:22)
www-0     at Socket.<anonymous> (/Users/me/Desktop/project/node_modules/redis/index.js:131:27)
www-0     at emitOne (events.js:77:13)
www-0     at Socket.emit (events.js:169:7)
www-0     at readableAddChunk (_stream_readable.js:146:16)
www-0     at Socket.Readable.push (_stream_readable.js:110:10)
www-0     at TCP.onread (net.js:523:20)

app.get('/redis', function(req, res) {
  var args2 = ["movie", "[The", '(The\xff', 'LIMIT', "0", "2"];
  client.zrangebylex(args2, function(err, response) {
    if (err) throw err;
    console.log(response);
    res.end();
  });
});

2 个答案:

答案 0 :(得分:2)

您没有发送相同的参数 - 特别是您的范围没有{(1}}限制所需的“(”或“[”字符。)您也不包括ZRANGEBYLEX。 {1}}在上限。

答案 1 :(得分:0)

@hobbs是对的。解决方案如下。

app.get('/redis', function(req, res) {
  var args2 = ["movie", "[The", '(The\xff', 'LIMIT', "0", "2"];
  client.zrangebylex(args2, function(err, response) {
    if (err) throw err;
    console.log(response);
    res.end();
  });
});