gpt4 book ai didi

ruby-on-rails - 为什么 redis 返回更多的值而不是计数?

转载 作者:可可西里 更新时间:2023-11-01 11:04:50 25 4
gpt4 key购买 nike

我正在使用 Ruby on Rails 将 key 存储到 redis 中。我的哈希下有20000多个键。我试图在全部获取时限制 10 个。但是 redis 返回的是 11 而不是 10。为什么返回 11?

我的哈希,

127.0.0.1:6379> HLEN myhash
(integer) 14148

在下面的示例中,我查询了 4 条记录,但返回了 5 条具有相应值的记录,

127.0.0.1:6379> HSCAN my_hash 0 match * count 4
1) "896"
2) 1) "player 1"
2) "{\"id\":\"13192\",\"name\":\"Ram\"}"
3) "player 2"
4) "{\"id\":\"5429\",\"name\":\"Gopal\"}"
5) "player 3"
6) "{\"id\":\"2614\",\"name\":\"Venu\"}"
7) "player 4"
8) "{\"id\":\"9645\",\"name\":\"Sam\"}"
9) "player 5"
10) "{\"id\":\"2358\",\"name\":\"Rohit\"}"

为什么这里是 5?

最佳答案

documented COUNT 的含义是它是关于在 HSCAN 调用上要做多少工作的提示,它不是要返回的元素的严格数量。

While SCAN does not provide guarantees about the number of elements returned at every iteration, it is possible to empirically adjust the behavior of SCAN using the COUNT option. Basically with COUNT the user specified the amount of work that should be done at every call in order to retrieve elements from the collection. This is just a hint for the implementation....

When iterating the key space, or a Set, Hash or Sorted Set that is big enough to be represented by a hash table, assuming no MATCH option is used, the server will usually return count or a bit more than count elements per call.

关于ruby-on-rails - 为什么 redis 返回更多的值而不是计数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56870988/

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