gpt4 book ai didi

redis - 为什么我不能在Redis的此排序集上使用ZRANGEBYLEX?

转载 作者:行者123 更新时间:2023-12-03 06:41:25 24 4
gpt4 key购买 nike

在redis文档中,有ZRANGEBYLEX的示例

ZADD myindex 0 0056:0028.44:90
ZADD myindex 0 0034:0011.00:832
ZRANGEBYLEX myindex [0056:0010.00 [0056:0030.00
1) "0056:0028.44:90"

这很简单。

但是,如果我想对以下示例应用相同的技术,
127.0.0.1:6379> zadd feedbacks 1 feedback1 2 feedback2 3 feedback3 1 feedback4
(integer) 4
127.0.0.1:6379> ZRANGEBYLEX feedbacks [feed [feed
(empty list or set)

我得到一个空集。

我希望看到四个值( feedback1feedback4)

为什么 ZRANGEBYLEX在我的测试样本上失败?

最佳答案

失败是因为他们的分数不同。 ZRANGEBYLEX仅适用于相同分数的子集。

参见https://redis.io/commands/ZRANGEBYLEX

When all the elements in a sorted set are inserted with the same score, in order to force lexicographical ordering, this command returns all the elements in the sorted set at key with a value between min and max.

If the elements in the sorted set have different scores, the returned elements are unspecified.



排序集具有在相同分数子集中按字典顺序排序的属性。这给了他们第二个用例,按字典顺序排序,但是在这种情况下,您添加了所有具有相同分数的元素。

因此,您必须选择如何使用排序集:
  • 按分数排序(以可预测顺序使用相同分数的lex排序)
  • 按字典顺序排序,所有元素的得分都相同

  • 不能同时拥有。然后,您需要两个排序的集合。

    关于redis - 为什么我不能在Redis的此排序集上使用ZRANGEBYLEX?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59997507/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com