1 start_server
{tags
{"hash"}} {
2 test
{HSET
/HLEN
- Small hash creation
} {
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)]} {
11 r hset smallhash
$key $val
12 set smallhash
($key) $val
14 list [r hlen smallhash
]
17 test
{Is the small hash encoded with a zipmap?
} {
18 assert_encoding zipmap smallhash
21 test
{HSET
/HLEN
- Big hash creation
} {
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)]} {
30 r hset bighash
$key $val
31 set bighash
($key) $val
36 test
{Is the big hash encoded with a zipmap?
} {
37 r debug object bighash
40 test
{HGET against the small hash
} {
42 foreach k
[array names smallhash
*] {
43 if {$smallhash($k) ne
[r hget smallhash
$k]} {
44 set err
"$smallhash($k) != [r hget smallhash $k]"
51 test
{HGET against the big hash
} {
53 foreach k
[array names bighash
*] {
54 if {$bighash($k) ne
[r hget bighash
$k]} {
55 set err
"$bighash($k) != [r hget bighash $k]"
62 test
{HGET against non existing key
} {
64 lappend rv
[r hget smallhash __123123123__
]
65 lappend rv
[r hget bighash __123123123__
]
69 test
{HSET in
update and insert mode
} {
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__
]
84 } {0 newval1
1 0 newval2
1 1 1}
86 test
{HSETNX target key missing
- small hash
} {
87 r hsetnx smallhash __123123123__ foo
88 r hget smallhash __123123123__
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__
98 test
{HSETNX target key missing
- big hash
} {
99 r hsetnx bighash __123123123__ foo
100 r hget bighash __123123123__
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__
110 test
{HMSET wrong number of args
} {
111 catch {r hmset smallhash key1 val1 key2
} err
115 test
{HMSET
- small hash
} {
117 foreach {k v
} [array get smallhash
] {
118 set newval
[randstring
0 8 alpha
]
119 set smallhash
($k) $newval
120 lappend args
$k $newval
122 r hmset smallhash
{*}$args
125 test
{HMSET
- big hash
} {
127 foreach {k v
} [array get bighash
] {
128 set newval
[randstring
0 8 alpha
]
129 set bighash
($k) $newval
130 lappend args
$k $newval
132 r hmset bighash
{*}$args
135 test
{HMGET against non existing key and fields
} {
137 lappend rv
[r hmget doesntexist __123123123__ __456456456__
]
138 lappend rv
[r hmget smallhash __123123123__ __456456456__
]
139 lappend rv
[r hmget bighash __123123123__ __456456456__
]
141 } {{{} {}} {{} {}} {{} {}}}
143 test
{HMGET
- small hash
} {
146 foreach {k v
} [array get smallhash
] {
151 set result
[r hmget smallhash
{*}$keys]
152 if {$vals ne
$result} {
153 set err
"$vals != $result"
159 test
{HMGET
- big hash
} {
162 foreach {k v
} [array get bighash
] {
167 set result
[r hmget bighash
{*}$keys]
168 if {$vals ne
$result} {
169 set err
"$vals != $result"
175 test
{HKEYS
- small hash
} {
176 lsort [r hkeys smallhash
]
177 } [lsort [array names smallhash
*]]
179 test
{HKEYS
- big hash
} {
180 lsort [r hkeys bighash
]
181 } [lsort [array names bighash
*]]
183 test
{HVALS
- small hash
} {
185 foreach {k v
} [array get smallhash
] {
189 } [lsort [r hvals smallhash
]]
191 test
{HVALS
- big hash
} {
193 foreach {k v
} [array get bighash
] {
197 } [lsort [r hvals bighash
]]
199 test
{HGETALL
- small hash
} {
200 lsort [r hgetall smallhash
]
201 } [lsort [array get smallhash
]]
203 test
{HGETALL
- big hash
} {
204 lsort [r hgetall bighash
]
205 } [lsort [array get bighash
]]
207 test
{HDEL and
return value
} {
209 lappend rv
[r hdel smallhash nokey
]
210 lappend rv
[r hdel bighash nokey
]
211 set k
[lindex [array names smallhash
*] 0]
212 lappend rv
[r hdel smallhash
$k]
213 lappend rv
[r hdel smallhash
$k]
214 lappend rv
[r hget smallhash
$k]
216 set k
[lindex [array names bighash
*] 0]
217 lappend rv
[r hdel bighash
$k]
218 lappend rv
[r hdel bighash
$k]
219 lappend rv
[r hget bighash
$k]
222 } {0 0 1 0 {} 1 0 {}}
226 set k
[lindex [array names smallhash
*] 0]
227 lappend rv
[r hexists smallhash
$k]
228 lappend rv
[r hexists smallhash nokey
]
229 set k
[lindex [array names bighash
*] 0]
230 lappend rv
[r hexists bighash
$k]
231 lappend rv
[r hexists bighash nokey
]
234 test
{Is a zipmap encoded Hash promoted on big payload?
} {
235 r hset smallhash foo
[string repeat a
1024]
236 r debug object smallhash
239 test
{HINCRBY against non existing database key
} {
241 list [r hincrby htest foo
2]
244 test
{HINCRBY against non existing hash key
} {
248 lappend rv
[r hincrby smallhash tmp
2]
249 lappend rv
[r hget smallhash tmp
]
250 lappend rv
[r hincrby bighash tmp
2]
251 lappend rv
[r hget bighash tmp
]
254 test
{HINCRBY against hash key created by hincrby itself
} {
256 lappend rv
[r hincrby smallhash tmp
3]
257 lappend rv
[r hget smallhash tmp
]
258 lappend rv
[r hincrby bighash tmp
3]
259 lappend rv
[r hget bighash tmp
]
262 test
{HINCRBY against hash key originally
set with HSET
} {
263 r hset smallhash tmp
100
264 r hset bighash tmp
100
265 list [r hincrby smallhash tmp
2] [r hincrby bighash tmp
2]
268 test
{HINCRBY over
32bit value
} {
269 r hset smallhash tmp
17179869184
270 r hset bighash tmp
17179869184
271 list [r hincrby smallhash tmp
1] [r hincrby bighash tmp
1]
272 } {17179869185 17179869185}
274 test
{HINCRBY over
32bit value with over
32bit increment
} {
275 r hset smallhash tmp
17179869184
276 r hset bighash tmp
17179869184
277 list [r hincrby smallhash tmp
17179869184] [r hincrby bighash tmp
17179869184]
278 } {34359738368 34359738368}
280 test
{HINCRBY fails against hash value with spaces
} {
281 r hset smallhash str
" 11 "
282 r hset bighash str
" 11 "
283 catch {r hincrby smallhash str
1} smallerr
284 catch {r hincrby smallhash str
1} bigerr
286 lappend rv
[string match
"ERR*not an integer*" $smallerr]
287 lappend rv
[string match
"ERR*not an integer*" $bigerr]
290 test
{Hash zipmap regression test
for large keys
} {
291 r hset hash kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk a
292 r hset hash kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk b
293 r hget hash kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk