解决了的。解决方案如下,多亏了@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

所有以“那个”开头的电影。
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();
  });
});

最佳答案

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

关于node.js - node_redis ZRANGEBYLEX返回“ERR min或max无效字符串范围项”错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35423985/

10-11 06:52