]>
Commit | Line | Data |
---|---|---|
98578b57 PN |
1 | start_server default.conf {} { |
2 | test {SADD, SCARD, SISMEMBER, SMEMBERS basics} { | |
3 | r sadd myset foo | |
4 | r sadd myset bar | |
5 | list [r scard myset] [r sismember myset foo] \ | |
6 | [r sismember myset bar] [r sismember myset bla] \ | |
7 | [lsort [r smembers myset]] | |
8 | } {2 1 1 0 {bar foo}} | |
9 | ||
10 | test {SADD adding the same element multiple times} { | |
11 | r sadd myset foo | |
12 | r sadd myset foo | |
13 | r sadd myset foo | |
14 | r scard myset | |
15 | } {2} | |
16 | ||
17 | test {SADD against non set} { | |
18 | r lpush mylist foo | |
19 | catch {r sadd mylist bar} err | |
20 | format $err | |
21 | } {ERR*kind*} | |
22 | ||
23 | test {SREM basics} { | |
24 | r sadd myset ciao | |
25 | r srem myset foo | |
26 | lsort [r smembers myset] | |
27 | } {bar ciao} | |
28 | ||
29 | test {Mass SADD and SINTER with two sets} { | |
30 | for {set i 0} {$i < 1000} {incr i} { | |
31 | r sadd set1 $i | |
32 | r sadd set2 [expr $i+995] | |
33 | } | |
34 | lsort [r sinter set1 set2] | |
35 | } {995 996 997 998 999} | |
36 | ||
37 | test {SUNION with two sets} { | |
38 | lsort [r sunion set1 set2] | |
39 | } [lsort -uniq "[r smembers set1] [r smembers set2]"] | |
40 | ||
41 | test {SINTERSTORE with two sets} { | |
42 | r sinterstore setres set1 set2 | |
43 | lsort [r smembers setres] | |
44 | } {995 996 997 998 999} | |
45 | ||
46 | test {SINTERSTORE with two sets, after a DEBUG RELOAD} { | |
47 | r debug reload | |
48 | r sinterstore setres set1 set2 | |
49 | lsort [r smembers setres] | |
50 | } {995 996 997 998 999} | |
51 | ||
52 | test {SUNIONSTORE with two sets} { | |
53 | r sunionstore setres set1 set2 | |
54 | lsort [r smembers setres] | |
55 | } [lsort -uniq "[r smembers set1] [r smembers set2]"] | |
56 | ||
57 | test {SUNIONSTORE against non existing keys} { | |
58 | r set setres xxx | |
59 | list [r sunionstore setres foo111 bar222] [r exists xxx] | |
60 | } {0 0} | |
61 | ||
62 | test {SINTER against three sets} { | |
63 | r sadd set3 999 | |
64 | r sadd set3 995 | |
65 | r sadd set3 1000 | |
66 | r sadd set3 2000 | |
67 | lsort [r sinter set1 set2 set3] | |
68 | } {995 999} | |
69 | ||
70 | test {SINTERSTORE with three sets} { | |
71 | r sinterstore setres set1 set2 set3 | |
72 | lsort [r smembers setres] | |
73 | } {995 999} | |
74 | ||
75 | test {SUNION with non existing keys} { | |
76 | lsort [r sunion nokey1 set1 set2 nokey2] | |
77 | } [lsort -uniq "[r smembers set1] [r smembers set2]"] | |
78 | ||
79 | test {SDIFF with two sets} { | |
80 | for {set i 5} {$i < 1000} {incr i} { | |
81 | r sadd set4 $i | |
82 | } | |
83 | lsort [r sdiff set1 set4] | |
84 | } {0 1 2 3 4} | |
85 | ||
86 | test {SDIFF with three sets} { | |
87 | r sadd set5 0 | |
88 | lsort [r sdiff set1 set4 set5] | |
89 | } {1 2 3 4} | |
90 | ||
91 | test {SDIFFSTORE with three sets} { | |
92 | r sdiffstore sres set1 set4 set5 | |
93 | lsort [r smembers sres] | |
94 | } {1 2 3 4} | |
95 | ||
96 | test {SPOP basics} { | |
97 | r del myset | |
98 | r sadd myset 1 | |
99 | r sadd myset 2 | |
100 | r sadd myset 3 | |
101 | list [lsort [list [r spop myset] [r spop myset] [r spop myset]]] [r scard myset] | |
102 | } {{1 2 3} 0} | |
103 | ||
104 | test {SRANDMEMBER} { | |
105 | r del myset | |
106 | r sadd myset a | |
107 | r sadd myset b | |
108 | r sadd myset c | |
109 | unset -nocomplain myset | |
110 | array set myset {} | |
111 | for {set i 0} {$i < 100} {incr i} { | |
112 | set myset([r srandmember myset]) 1 | |
113 | } | |
114 | lsort [array names myset] | |
115 | } {a b c} | |
116 | ||
117 | test {SMOVE basics} { | |
118 | r sadd myset1 a | |
119 | r sadd myset1 b | |
120 | r sadd myset1 c | |
121 | r sadd myset2 x | |
122 | r sadd myset2 y | |
123 | r sadd myset2 z | |
124 | r smove myset1 myset2 a | |
125 | list [lsort [r smembers myset2]] [lsort [r smembers myset1]] | |
126 | } {{a x y z} {b c}} | |
127 | ||
128 | test {SMOVE non existing key} { | |
129 | list [r smove myset1 myset2 foo] [lsort [r smembers myset2]] [lsort [r smembers myset1]] | |
130 | } {0 {a x y z} {b c}} | |
131 | ||
132 | test {SMOVE non existing src set} { | |
133 | list [r smove noset myset2 foo] [lsort [r smembers myset2]] | |
134 | } {0 {a x y z}} | |
135 | ||
136 | test {SMOVE non existing dst set} { | |
137 | list [r smove myset2 myset3 y] [lsort [r smembers myset2]] [lsort [r smembers myset3]] | |
138 | } {1 {a x z} y} | |
139 | ||
140 | test {SMOVE wrong src key type} { | |
141 | r set x 10 | |
142 | catch {r smove x myset2 foo} err | |
143 | format $err | |
144 | } {ERR*} | |
145 | ||
146 | test {SMOVE wrong dst key type} { | |
147 | r set x 10 | |
148 | catch {r smove myset2 x foo} err | |
149 | format $err | |
150 | } {ERR*} | |
151 | } |