1 start_server
{tags
{"basic"}} {
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]
56 test
{Very big payload random access
} {
59 for {set j
0} {$j < 100} {incr j
} {
60 set size
[expr 1+[randomInt
100000]]
61 set buf
[string repeat
"pl-$j" $size]
63 r
set bigpayload_
$j $buf
65 for {set j
0} {$j < 1000} {incr j
} {
66 set index
[randomInt
100]
67 set buf
[r get bigpayload_
$index]
68 if {$buf != $payload($index)} {
69 set err
"Values differ: I set '$payload($index)' but I read back '$buf'"
77 test
{SET
10000 numeric keys and access all them in reverse order
} {
79 for {set x
0} {$x < 10000} {incr x
} {
83 for {set x
9999} {$x >= 0} {incr x
-1} {
86 set err
"Eleemnt at position $x is $val instead of $x"
93 test
{DBSIZE should be
10101 now
} {
98 test
{INCR against non existing key
} {
100 append res
[r
incr novar
]
101 append res
[r get novar
]
104 test
{INCR against key created by
incr itself
} {
108 test
{INCR against key originally
set with SET
} {
113 test
{INCR over
32bit value
} {
114 r
set novar
17179869184
118 test
{INCRBY over
32bit value with over
32bit increment
} {
119 r
set novar
17179869184
120 r incrby novar
17179869184
123 test
{INCR fails against key with spaces
(no integer encoded
)} {
125 catch {r
incr novar
} err
129 test
{INCR fails against a key holding a
list} {
131 catch {r
incr mylist
} err
136 test
{DECRBY over
32bit value with over
32bit increment
, negative res
} {
137 r
set novar
17179869184
138 r decrby novar
17179869185
141 test
{SETNX target key missing
} {
142 r setnx novar2 foobared
146 test
{SETNX target key exists
} {
147 r setnx novar2 blabla
151 test
{SETNX will overwrite EXPIREing key
} {
161 append res
[r exists newkey
]
163 append res
[r exists newkey
]
166 test
{Zero length value in key. SET
/GET
/EXISTS
} {
168 set res
[r get emptykey
]
169 append res
[r exists emptykey
]
171 append res
[r exists emptykey
]
174 test
{Commands pipelining
} {
176 puts -nonewline $fd "SET k1 4\r\nxyzk\r\nGET k1\r\nPING\r\n"
179 append res
[string match OK
* [::redis::redis_read_reply $fd]]
180 append res
[::redis::redis_read_reply $fd]
181 append res
[string match PONG
* [::redis::redis_read_reply $fd]]
185 test
{Non existing command
} {
186 catch {r foobaredcommand
} err
187 string match ERR
* $err
190 test
{RENAME basic usage
} {
192 r
rename mykey mykey1
193 r
rename mykey1 mykey2
197 test
{RENAME
source key should no longer exist
} {
201 test
{RENAME against already existing key
} {
204 r
rename mykey2 mykey
205 set res
[r get mykey
]
206 append res
[r exists mykey2
]
209 test
{RENAMENX basic usage
} {
213 r renamenx mykey mykey2
214 set res
[r get mykey2
]
215 append res
[r exists mykey
]
218 test
{RENAMENX against already existing key
} {
221 r renamenx mykey mykey2
224 test
{RENAMENX against already existing key
(2)} {
225 set res
[r get mykey
]
226 append res
[r get mykey2
]
229 test
{RENAME against non existing
source key
} {
230 catch {r
rename nokey foobar
} err
234 test
{RENAME where
source and dest key is the same
} {
235 catch {r
rename mykey mykey
} err
239 test
{DEL all keys again
(DB
0)} {
240 foreach key
[r keys
*] {
246 test
{DEL all keys again
(DB
1)} {
248 foreach key
[r keys
*] {
256 test
{MOVE basic usage
} {
260 lappend res
[r exists mykey
]
261 lappend res
[r dbsize
]
263 lappend res
[r get mykey
]
264 lappend res
[r dbsize
]
267 } [list 0 0 foobar
1]
269 test
{MOVE against key existing in the target DB
} {
274 test
{SET
/GET keys in different DBs
} {
282 lappend res
[r get a
]
283 lappend res
[r get b
]
285 lappend res
[r get a
]
286 lappend res
[r get b
]
289 } {hello world foo bared
}
298 test
{MGET against non existing key
} {
302 test
{MGET against non-string key
} {
305 r mget foo baazz bar myset
314 for {set i
0} {$i < 100} {incr i
} {
315 set rkey
[r randomkey
]
316 if {$rkey eq
{foo
}} {
319 if {$rkey eq
{bar
}} {
323 list $foo_seen $bar_seen
326 test
{RANDOMKEY against empty DB
} {
331 test
{RANDOMKEY regression
1} {
338 test
{GETSET
(set new value
)} {
339 list [r getset foo xyz
] [r get foo
]
342 test
{GETSET
(replace old value
)} {
344 list [r getset foo xyz
] [r get foo
]
347 test
{MSET base case
} {
348 r mset x
10 y
"foo bar" z
"x x x x x x x\n\n\r\n"
350 } [list 10 {foo bar
} "x x x x x x x\n\n\r\n"]
352 test
{MSET wrong number of args
} {
353 catch {r mset x
10 y
"foo bar" z
} err
357 test
{MSETNX with already existent key
} {
358 list [r msetnx x1 xxx y2 yyy x
20] [r exists x1
] [r exists y2
]
361 test
{MSETNX with not existing keys
} {
362 list [r msetnx x1 xxx y2 yyy
] [r get x1
] [r get y2
]
365 test
{MSETNX should remove all the volatile keys even on
failure} {
369 list [r msetnx x A y B z C
] [r mget x y z
]