【问题标题】:ZRANGEBYLEX command on redis using jedis api doesnot return any result使用 jedis api 在 redis 上的 ZRANGEBYLEX 命令不返回任何结果
【发布时间】:2015-09-28 14:46:31
【问题描述】:

在 REDIS CLI 中执行时,以下命令返回预期结果(位置名称前缀为“new alban”)。

127.0.0.1:6379> zrangebylex my_places_data_set "[new alban" "[new alban\xff"

  1. “新奥尔巴尼...”
  2. “新奥尔巴尼...”
  3. “新奥尔巴尼河...”

但是,当使用 jedis api 调用此命令时,它不会返回上述前缀的任何结果,但如果我完成单词则返回。

没有结果 - 管道。zrangeByLex(my_places_data_set, "[new alban", "[new alban\xff", 0, 5); em>

返回结果 - 管道。zrangeByLex(my_places_data_set, "[new albany", "[new albany\xff", 0, 5); em>

如果我使用 xff 而不是 \xff 会发生以下情况

没有结果 - 管道。zrangeByLex(my_places_data_set, "[new alban", "[new albanxff", 0, 5);

返回结果 - 管道。zrangeByLex(my_places_data_set, "[new albany", "[new albanyxff", 0, 5);

返回结果 - 管道。zrangeByLex(my_places_data_set, "[new albany", "[new albaxff", 0, 5);

附: Jedis api 签名:zrangeByLex(String key, String min, String max, int offset, int count)

【问题讨论】:

    标签: redis jedis


    【解决方案1】:

    我通过手动将十六进制代码附加到前缀解决了这个问题

    byte[] prefixByte = ("[" + prefix).getBytes();
    byte[] prefixByteExtended = Arrays.copyOf(prefixByte, prefixByte.length + 1);
    prefixByteExtended[prefixByte.length] = (byte) 0xFF;
    pipeline.zrangeByLex(my_places_data_set, ("[" + prefix), new String(prefixByteExtended), 0, 5));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-11
      • 2017-12-28
      • 2015-12-20
      • 2012-10-31
      • 2018-11-03
      • 1970-01-01
      • 2015-04-21
      • 1970-01-01
      相关资源
      最近更新 更多