【发布时间】:2016-12-12 14:36:08
【问题描述】:
我有一个简单的redis set,上面有超过 1 万条笔记。我使用sadd添加数据
如何按分区读取这个集合?
我的意思是读取前 100 000 个键,然后读取 200 000 个键?
【问题讨论】:
标签: redis node-redis
我有一个简单的redis set,上面有超过 1 万条笔记。我使用sadd添加数据
如何按分区读取这个集合?
我的意思是读取前 100 000 个键,然后读取 200 000 个键?
【问题讨论】:
标签: redis node-redis
我不确定你所说的“按分区”是什么意思,但如果你想分块阅读,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 done
【讨论】:
apps。参数应该怎么写?
items = r.sscan("apps", 400000, None, 700000)?