2 test
{DEL all keys to start with a clean DB
} {
3 foreach key
[r keys
*] {r del
$key}
7 test
{SET and GET an item
} {
12 test
{SET and GET an empty item
} {
17 test
{DEL against a single item
} {
26 list [r del foo1 foo2 foo3 foo4
] [r mget foo1 foo2 foo3
]
29 test
{KEYS with pattern
} {
30 foreach key
{key_x key_y key_z foo_a foo_b foo_c
} {
36 test
{KEYS to get all keys
} {
38 } {foo_a foo_b foo_c key_x key_y key_z
}
45 foreach key
[r keys
*] {r del
$key}
49 test
{Very big payload in GET
/SET
} {
50 set buf
[string repeat
"abcd" 1000000]
53 } [string repeat
"abcd" 1000000]
55 test
{Very big payload random access
} {
58 for {set j
0} {$j < 100} {incr j
} {
59 set size
[expr 1+[randomInt
100000]]
60 set buf
[string repeat
"pl-$j" $size]
62 r
set bigpayload_
$j $buf
64 for {set j
0} {$j < 1000} {incr j
} {
65 set index
[randomInt
100]
66 set buf
[r get bigpayload_
$index]
67 if {$buf != $payload($index)} {
68 set err
"Values differ: I set '$payload($index)' but I read back '$buf'"
76 test
{SET
10000 numeric keys and access all them in reverse order
} {
78 for {set x
0} {$x < 10000} {incr x
} {
82 for {set x
9999} {$x >= 0} {incr x
-1} {
85 set err
"Eleemnt at position $x is $val instead of $x"
92 test
{DBSIZE should be
10101 now
} {
96 test
{INCR against non existing key
} {
98 append res
[r
incr novar
]
99 append res
[r get novar
]
102 test
{INCR against key created by
incr itself
} {
106 test
{INCR against key originally
set with SET
} {
111 test
{INCR over
32bit value
} {
112 r
set novar
17179869184
116 test
{INCRBY over
32bit value with over
32bit increment
} {
117 r
set novar
17179869184
118 r incrby novar
17179869184
121 test
{INCR fails against key with spaces
(no integer encoded
)} {
123 catch {r
incr novar
} err
127 test
{INCR fails against a key holding a
list} {
129 catch {r
incr mylist
} err
134 test
{DECRBY over
32bit value with over
32bit increment
, negative res
} {
135 r
set novar
17179869184
136 r decrby novar
17179869185
139 test
{SETNX target key missing
} {
140 r setnx novar2 foobared
144 test
{SETNX target key exists
} {
145 r setnx novar2 blabla
149 test
{SETNX will overwrite EXPIREing key
} {
159 append res
[r exists newkey
]
161 append res
[r exists newkey
]
164 test
{Zero length value in key. SET
/GET
/EXISTS
} {
166 set res
[r get emptykey
]
167 append res
[r exists emptykey
]
169 append res
[r exists emptykey
]
172 test
{Commands pipelining
} {
174 puts -nonewline $fd "SET k1 4\r\nxyzk\r\nGET k1\r\nPING\r\n"
177 append res
[string match OK
* [::redis::redis_read_reply $fd]]
178 append res
[::redis::redis_read_reply $fd]
179 append res
[string match PONG
* [::redis::redis_read_reply $fd]]
183 test
{Non existing command
} {
184 catch {r foobaredcommand
} err
185 string match ERR
* $err
188 test
{RENAME basic usage
} {
190 r
rename mykey mykey1
191 r
rename mykey1 mykey2
195 test
{RENAME
source key should no longer exist
} {
199 test
{RENAME against already existing key
} {
202 r
rename mykey2 mykey
203 set res
[r get mykey
]
204 append res
[r exists mykey2
]
207 test
{RENAMENX basic usage
} {
211 r renamenx mykey mykey2
212 set res
[r get mykey2
]
213 append res
[r exists mykey
]
216 test
{RENAMENX against already existing key
} {
219 r renamenx mykey mykey2
222 test
{RENAMENX against already existing key
(2)} {
223 set res
[r get mykey
]
224 append res
[r get mykey2
]
227 test
{RENAME against non existing
source key
} {
228 catch {r
rename nokey foobar
} err
232 test
{RENAME where
source and dest key is the same
} {
233 catch {r
rename mykey mykey
} err
237 test
{DEL all keys again
(DB
0)} {
238 foreach key
[r keys
*] {
244 test
{DEL all keys again
(DB
1)} {
246 foreach key
[r keys
*] {
254 test
{MOVE basic usage
} {
258 lappend res
[r exists mykey
]
259 lappend res
[r dbsize
]
261 lappend res
[r get mykey
]
262 lappend res
[r dbsize
]
265 } [list 0 0 foobar
1]
267 test
{MOVE against key existing in the target DB
} {
272 test
{SET
/GET keys in different DBs
} {
280 lappend res
[r get a
]
281 lappend res
[r get b
]
283 lappend res
[r get a
]
284 lappend res
[r get b
]
287 } {hello world foo bared
}
296 test
{MGET against non existing key
} {
300 test
{MGET against non-string key
} {
303 r mget foo baazz bar myset
312 for {set i
0} {$i < 100} {incr i
} {
313 set rkey
[r randomkey
]
314 if {$rkey eq
{foo
}} {
317 if {$rkey eq
{bar
}} {
321 list $foo_seen $bar_seen
324 test
{RANDOMKEY against empty DB
} {
329 test
{RANDOMKEY regression
1} {
336 test
{GETSET
(set new value
)} {
337 list [r getset foo xyz
] [r get foo
]
340 test
{GETSET
(replace old value
)} {
342 list [r getset foo xyz
] [r get foo
]
345 test
{MSET base case
} {
346 r mset x
10 y
"foo bar" z
"x x x x x x x\n\n\r\n"
348 } [list 10 {foo bar
} "x x x x x x x\n\n\r\n"]
350 test
{MSET wrong number of args
} {
351 catch {r mset x
10 y
"foo bar" z
} err
355 test
{MSETNX with already existent key
} {
356 list [r msetnx x1 xxx y2 yyy x
20] [r exists x1
] [r exists y2
]
359 test
{MSETNX with not existing keys
} {
360 list [r msetnx x1 xxx y2 yyy
] [r get x1
] [r get y2
]
363 test
{MSETNX should remove all the volatile keys even on
failure} {
367 list [r msetnx x A y B z C
] [r mget x y z
]