我有一个简单的redis set,有超过100万条笔记。我使用sadd添加数据
如何按分区读取此集?
我是说先读10万把钥匙然后再读200,000把钥匙?
发布于 2016-12-12 14:57:28
我不知道您所说的“通过分区”是什么意思,但是如果您想分块地阅读它,SSCAN就是您的朋友。
SSCAN key cursor [MATCH pattern] [COUNT count]从光标中的值0开始,每次都得到下一个游标id和COUNT元素。当没有更多可读的内容时,您将得到0的游标。
例如:
# let's add 14 elements to a set
127.0.0.1:6379> SADD myset e1 e2 e3 e4 e5 e6 e7 e8 e9 e10 e11 e12 e13 e14
(integer) 14
# now let's scan it from the "beginning" (notice that it's not ordered)
127.0.0.1:6379> SSCAN myset 0 COUNT 10
1) "3"
2) 1) "e8"
2) "e10"
3) "e2"
4) "e11"
5) "e7"
6) "e3"
7) "e14"
8) "e4"
9) "e6"
10) "e9"
# we got a cursor id of 3, let's give that to the next iteration!
127.0.0.1:6379> SSCAN myset 3 COUNT 10
1) "0"
2) 1) "e13"
2) "e12"
3) "e5"
4) "e1"
# now we got a cursor id of 0, meaning we're donehttps://stackoverflow.com/questions/41103221
复制相似问题