【问题标题】:Howto read sets in Redis?如何在 Redis 中读取集合?
【发布时间】:2016-12-12 14:36:08
【问题描述】:

我有一个简单的redis set,上面有超过 1 万条笔记。我使用sadd添加数据

如何按分区读取这个集合?

我的意思是读取前 100 000 个键,然后读取 200 000 个键?

【问题讨论】:

    标签: redis node-redis


    【解决方案1】:

    我不确定你所说的“按分区”是什么意思,但如果你想分块阅读,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
    

    【讨论】:

    • 我在 Python 中有一个函数,它接受参数:self、name、cursor、match、count。我设置的是apps。参数应该怎么写?
    • 对吗? items = r.sscan("apps", 400000, None, 700000)?
    猜你喜欢
    • 2011-11-19
    • 1970-01-01
    • 2015-07-12
    • 2021-11-02
    • 2012-02-01
    • 2019-09-24
    • 1970-01-01
    • 1970-01-01
    • 2012-07-03
    相关资源
    最近更新 更多