]>
Commit | Line | Data |
---|---|---|
7f7499ee | 1 | start_server {tags {"hash"}} { |
98578b57 PN |
2 | test {HSET/HLEN - Small hash creation} { |
3 | array set smallhash {} | |
4 | for {set i 0} {$i < 8} {incr i} { | |
5 | set key [randstring 0 8 alpha] | |
6 | set val [randstring 0 8 alpha] | |
7 | if {[info exists smallhash($key)]} { | |
8 | incr i -1 | |
9 | continue | |
10 | } | |
11 | r hset smallhash $key $val | |
12 | set smallhash($key) $val | |
13 | } | |
14 | list [r hlen smallhash] | |
15 | } {8} | |
16 | ||
17 | test {Is the small hash encoded with a zipmap?} { | |
efc5d4cc PN |
18 | assert_encoding zipmap smallhash |
19 | } | |
98578b57 PN |
20 | |
21 | test {HSET/HLEN - Big hash creation} { | |
22 | array set bighash {} | |
23 | for {set i 0} {$i < 1024} {incr i} { | |
24 | set key [randstring 0 8 alpha] | |
25 | set val [randstring 0 8 alpha] | |
26 | if {[info exists bighash($key)]} { | |
27 | incr i -1 | |
28 | continue | |
29 | } | |
30 | r hset bighash $key $val | |
31 | set bighash($key) $val | |
32 | } | |
33 | list [r hlen bighash] | |
34 | } {1024} | |
35 | ||
36 | test {Is the big hash encoded with a zipmap?} { | |
3c23ee1b PN |
37 | assert_encoding hashtable bighash |
38 | } | |
98578b57 PN |
39 | |
40 | test {HGET against the small hash} { | |
41 | set err {} | |
42 | foreach k [array names smallhash *] { | |
43 | if {$smallhash($k) ne [r hget smallhash $k]} { | |
44 | set err "$smallhash($k) != [r hget smallhash $k]" | |
45 | break | |
46 | } | |
47 | } | |
48 | set _ $err | |
49 | } {} | |
50 | ||
51 | test {HGET against the big hash} { | |
52 | set err {} | |
53 | foreach k [array names bighash *] { | |
54 | if {$bighash($k) ne [r hget bighash $k]} { | |
55 | set err "$bighash($k) != [r hget bighash $k]" | |
56 | break | |
57 | } | |
58 | } | |
59 | set _ $err | |
60 | } {} | |
61 | ||
62 | test {HGET against non existing key} { | |
63 | set rv {} | |
64 | lappend rv [r hget smallhash __123123123__] | |
65 | lappend rv [r hget bighash __123123123__] | |
66 | set _ $rv | |
67 | } {{} {}} | |
68 | ||
69 | test {HSET in update and insert mode} { | |
70 | set rv {} | |
71 | set k [lindex [array names smallhash *] 0] | |
72 | lappend rv [r hset smallhash $k newval1] | |
73 | set smallhash($k) newval1 | |
74 | lappend rv [r hget smallhash $k] | |
75 | lappend rv [r hset smallhash __foobar123__ newval] | |
76 | set k [lindex [array names bighash *] 0] | |
77 | lappend rv [r hset bighash $k newval2] | |
78 | set bighash($k) newval2 | |
79 | lappend rv [r hget bighash $k] | |
80 | lappend rv [r hset bighash __foobar123__ newval] | |
81 | lappend rv [r hdel smallhash __foobar123__] | |
82 | lappend rv [r hdel bighash __foobar123__] | |
83 | set _ $rv | |
84 | } {0 newval1 1 0 newval2 1 1 1} | |
85 | ||
86 | test {HSETNX target key missing - small hash} { | |
87 | r hsetnx smallhash __123123123__ foo | |
88 | r hget smallhash __123123123__ | |
89 | } {foo} | |
90 | ||
91 | test {HSETNX target key exists - small hash} { | |
92 | r hsetnx smallhash __123123123__ bar | |
93 | set result [r hget smallhash __123123123__] | |
94 | r hdel smallhash __123123123__ | |
95 | set _ $result | |
96 | } {foo} | |
97 | ||
98 | test {HSETNX target key missing - big hash} { | |
99 | r hsetnx bighash __123123123__ foo | |
100 | r hget bighash __123123123__ | |
101 | } {foo} | |
102 | ||
103 | test {HSETNX target key exists - big hash} { | |
104 | r hsetnx bighash __123123123__ bar | |
105 | set result [r hget bighash __123123123__] | |
106 | r hdel bighash __123123123__ | |
107 | set _ $result | |
108 | } {foo} | |
109 | ||
110 | test {HMSET wrong number of args} { | |
111 | catch {r hmset smallhash key1 val1 key2} err | |
112 | format $err | |
113 | } {*wrong number*} | |
114 | ||
115 | test {HMSET - small hash} { | |
116 | set args {} | |
117 | foreach {k v} [array get smallhash] { | |
118 | set newval [randstring 0 8 alpha] | |
119 | set smallhash($k) $newval | |
120 | lappend args $k $newval | |
121 | } | |
122 | r hmset smallhash {*}$args | |
123 | } {OK} | |
124 | ||
125 | test {HMSET - big hash} { | |
126 | set args {} | |
127 | foreach {k v} [array get bighash] { | |
128 | set newval [randstring 0 8 alpha] | |
129 | set bighash($k) $newval | |
130 | lappend args $k $newval | |
131 | } | |
132 | r hmset bighash {*}$args | |
133 | } {OK} | |
134 | ||
135 | test {HMGET against non existing key and fields} { | |
136 | set rv {} | |
137 | lappend rv [r hmget doesntexist __123123123__ __456456456__] | |
138 | lappend rv [r hmget smallhash __123123123__ __456456456__] | |
139 | lappend rv [r hmget bighash __123123123__ __456456456__] | |
140 | set _ $rv | |
141 | } {{{} {}} {{} {}} {{} {}}} | |
142 | ||
e584d82f PN |
143 | test {HMGET against wrong type} { |
144 | r set wrongtype somevalue | |
145 | assert_error "*wrong*" {r hmget wrongtype field1 field2} | |
146 | } | |
147 | ||
98578b57 PN |
148 | test {HMGET - small hash} { |
149 | set keys {} | |
150 | set vals {} | |
151 | foreach {k v} [array get smallhash] { | |
152 | lappend keys $k | |
153 | lappend vals $v | |
154 | } | |
155 | set err {} | |
156 | set result [r hmget smallhash {*}$keys] | |
157 | if {$vals ne $result} { | |
158 | set err "$vals != $result" | |
159 | break | |
160 | } | |
161 | set _ $err | |
162 | } {} | |
163 | ||
164 | test {HMGET - big hash} { | |
165 | set keys {} | |
166 | set vals {} | |
167 | foreach {k v} [array get bighash] { | |
168 | lappend keys $k | |
169 | lappend vals $v | |
170 | } | |
171 | set err {} | |
172 | set result [r hmget bighash {*}$keys] | |
173 | if {$vals ne $result} { | |
174 | set err "$vals != $result" | |
175 | break | |
176 | } | |
177 | set _ $err | |
178 | } {} | |
179 | ||
180 | test {HKEYS - small hash} { | |
181 | lsort [r hkeys smallhash] | |
182 | } [lsort [array names smallhash *]] | |
183 | ||
184 | test {HKEYS - big hash} { | |
185 | lsort [r hkeys bighash] | |
186 | } [lsort [array names bighash *]] | |
187 | ||
188 | test {HVALS - small hash} { | |
189 | set vals {} | |
190 | foreach {k v} [array get smallhash] { | |
191 | lappend vals $v | |
192 | } | |
193 | set _ [lsort $vals] | |
194 | } [lsort [r hvals smallhash]] | |
195 | ||
196 | test {HVALS - big hash} { | |
197 | set vals {} | |
198 | foreach {k v} [array get bighash] { | |
199 | lappend vals $v | |
200 | } | |
201 | set _ [lsort $vals] | |
202 | } [lsort [r hvals bighash]] | |
203 | ||
204 | test {HGETALL - small hash} { | |
205 | lsort [r hgetall smallhash] | |
206 | } [lsort [array get smallhash]] | |
207 | ||
208 | test {HGETALL - big hash} { | |
209 | lsort [r hgetall bighash] | |
210 | } [lsort [array get bighash]] | |
211 | ||
212 | test {HDEL and return value} { | |
213 | set rv {} | |
214 | lappend rv [r hdel smallhash nokey] | |
215 | lappend rv [r hdel bighash nokey] | |
216 | set k [lindex [array names smallhash *] 0] | |
217 | lappend rv [r hdel smallhash $k] | |
218 | lappend rv [r hdel smallhash $k] | |
219 | lappend rv [r hget smallhash $k] | |
220 | unset smallhash($k) | |
221 | set k [lindex [array names bighash *] 0] | |
222 | lappend rv [r hdel bighash $k] | |
223 | lappend rv [r hdel bighash $k] | |
224 | lappend rv [r hget bighash $k] | |
225 | unset bighash($k) | |
226 | set _ $rv | |
227 | } {0 0 1 0 {} 1 0 {}} | |
228 | ||
229 | test {HEXISTS} { | |
230 | set rv {} | |
231 | set k [lindex [array names smallhash *] 0] | |
232 | lappend rv [r hexists smallhash $k] | |
233 | lappend rv [r hexists smallhash nokey] | |
234 | set k [lindex [array names bighash *] 0] | |
235 | lappend rv [r hexists bighash $k] | |
236 | lappend rv [r hexists bighash nokey] | |
237 | } {1 0 1 0} | |
238 | ||
239 | test {Is a zipmap encoded Hash promoted on big payload?} { | |
240 | r hset smallhash foo [string repeat a 1024] | |
241 | r debug object smallhash | |
242 | } {*hashtable*} | |
243 | ||
244 | test {HINCRBY against non existing database key} { | |
245 | r del htest | |
246 | list [r hincrby htest foo 2] | |
247 | } {2} | |
248 | ||
249 | test {HINCRBY against non existing hash key} { | |
250 | set rv {} | |
251 | r hdel smallhash tmp | |
252 | r hdel bighash tmp | |
253 | lappend rv [r hincrby smallhash tmp 2] | |
254 | lappend rv [r hget smallhash tmp] | |
255 | lappend rv [r hincrby bighash tmp 2] | |
256 | lappend rv [r hget bighash tmp] | |
257 | } {2 2 2 2} | |
258 | ||
259 | test {HINCRBY against hash key created by hincrby itself} { | |
260 | set rv {} | |
261 | lappend rv [r hincrby smallhash tmp 3] | |
262 | lappend rv [r hget smallhash tmp] | |
263 | lappend rv [r hincrby bighash tmp 3] | |
264 | lappend rv [r hget bighash tmp] | |
265 | } {5 5 5 5} | |
266 | ||
267 | test {HINCRBY against hash key originally set with HSET} { | |
268 | r hset smallhash tmp 100 | |
269 | r hset bighash tmp 100 | |
270 | list [r hincrby smallhash tmp 2] [r hincrby bighash tmp 2] | |
271 | } {102 102} | |
272 | ||
273 | test {HINCRBY over 32bit value} { | |
274 | r hset smallhash tmp 17179869184 | |
275 | r hset bighash tmp 17179869184 | |
276 | list [r hincrby smallhash tmp 1] [r hincrby bighash tmp 1] | |
277 | } {17179869185 17179869185} | |
278 | ||
279 | test {HINCRBY over 32bit value with over 32bit increment} { | |
280 | r hset smallhash tmp 17179869184 | |
281 | r hset bighash tmp 17179869184 | |
282 | list [r hincrby smallhash tmp 17179869184] [r hincrby bighash tmp 17179869184] | |
283 | } {34359738368 34359738368} | |
284 | ||
285 | test {HINCRBY fails against hash value with spaces} { | |
286 | r hset smallhash str " 11 " | |
287 | r hset bighash str " 11 " | |
288 | catch {r hincrby smallhash str 1} smallerr | |
289 | catch {r hincrby smallhash str 1} bigerr | |
290 | set rv {} | |
291 | lappend rv [string match "ERR*not an integer*" $smallerr] | |
292 | lappend rv [string match "ERR*not an integer*" $bigerr] | |
293 | } {1 1} | |
d6d3f92f | 294 | |
295 | test {Hash zipmap regression test for large keys} { | |
296 | r hset hash kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk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