SSCAN 集合迭代器

2020-12-19  本文已影响0人  闲云野鹤_23dd

SSCAN

语法

SSCAN setKey cursor [MATCH pattern] [COUNT count]

SSCAN 是 SCAN命令相似,不过SSCAN 命令用于迭代 集合(set类型)中的元素

MATCH 子句

正则匹配集合中的key。

COUNT 子句

每次读取集合中key的数量,如果数据集合较小,会不起作用,直接返回所有元素

例子

准备set类型 数据

127.0.0.1:6379[11]> SMEMBERS set1
1) "b3"
2) "a2"
3) "a1"
4) "a"
5) "b1"
127.0.0.1:6379[11]> SADD set1 x x1 x2 x3 y y1 y2 y3
(integer) 8
127.0.0.1:6379[11]> SMEMBERS set1
 1) "a"
 2) "b1"
 3) "y2"
 4) "a1"
 5) "y3"
 6) "y"
 7) "x2"
 8) "a2"
 9) "b3"
10) "y1"
11) "x"
12) "x1"
13) "x3"
127.0.0.1:6379[11]> 

SSCAN演示

127.0.0.1:6379[11]> SSCAN set1 0  ## 遍历set1中的key
1) "7"
2)  1) "a2"
    2) "b3"
    3) "a1"
    4) "y1"
    5) "x"
    6) "x1"
    7) "x3"
    8) "y2"
    9) "x2"
   10) "y3"
   11) "y"
127.0.0.1:6379[11]> SSCAN set1 7 
1) "0"
2) 1) "a"
   2) "b1"
127.0.0.1:6379[11]> SSCAN set1 0 count 20 ## 遍历set1中的key,每次读取20个元素
1) "0"
2)  1) "a2"
    2) "b3"
    3) "a1"
    4) "y1"
    5) "x"
    6) "x1"
    7) "x3"
    8) "y2"
    9) "x2"
   10) "y3"
   11) "y"
   12) "a"
   13) "b1"
127.0.0.1:6379[11]> SSCAN set1 0 match y* count 20 ## 遍历set1中以y开头的key,每次读取20个元素
1) "0"
2) 1) "y1"
   2) "y2"
   3) "y3"
   4) "y"
127.0.0.1:6379[11]> SSCAN set1 0 match y* count 6 ## 遍历set1中以y开头的key,每次读取6个元素
1) "1"
2) 1) "y1"
127.0.0.1:6379[11]> 

上一篇下一篇

猜你喜欢

热点阅读