-start_server default.conf {} {
+start_server {tags {"basic"}} {
test {DEL all keys to start with a clean DB} {
foreach key [r keys *] {r del $key}
r dbsize
r get foo
} [string repeat "abcd" 1000000]
- test {Very big payload random access} {
- set err {}
- array set payload {}
- for {set j 0} {$j < 100} {incr j} {
- set size [expr 1+[randomInt 100000]]
- set buf [string repeat "pl-$j" $size]
- set payload($j) $buf
- r set bigpayload_$j $buf
- }
- for {set j 0} {$j < 1000} {incr j} {
- set index [randomInt 100]
- set buf [r get bigpayload_$index]
- if {$buf != $payload($index)} {
- set err "Values differ: I set '$payload($index)' but I read back '$buf'"
- break
+ tags {"slow"} {
+ test {Very big payload random access} {
+ set err {}
+ array set payload {}
+ for {set j 0} {$j < 100} {incr j} {
+ set size [expr 1+[randomInt 100000]]
+ set buf [string repeat "pl-$j" $size]
+ set payload($j) $buf
+ r set bigpayload_$j $buf
}
- }
- unset payload
- set _ $err
- } {}
-
- test {SET 10000 numeric keys and access all them in reverse order} {
- set err {}
- for {set x 0} {$x < 10000} {incr x} {
- r set $x $x
- }
- set sum 0
- for {set x 9999} {$x >= 0} {incr x -1} {
- set val [r get $x]
- if {$val ne $x} {
- set err "Eleemnt at position $x is $val instead of $x"
- break
+ for {set j 0} {$j < 1000} {incr j} {
+ set index [randomInt 100]
+ set buf [r get bigpayload_$index]
+ if {$buf != $payload($index)} {
+ set err "Values differ: I set '$payload($index)' but I read back '$buf'"
+ break
+ }
}
- }
- set _ $err
- } {}
+ unset payload
+ set _ $err
+ } {}
+
+ test {SET 10000 numeric keys and access all them in reverse order} {
+ set err {}
+ for {set x 0} {$x < 10000} {incr x} {
+ r set $x $x
+ }
+ set sum 0
+ for {set x 9999} {$x >= 0} {incr x -1} {
+ set val [r get $x]
+ if {$val ne $x} {
+ set err "Eleemnt at position $x is $val instead of $x"
+ break
+ }
+ }
+ set _ $err
+ } {}
- test {DBSIZE should be 10101 now} {
- r dbsize
- } {10101}
+ test {DBSIZE should be 10101 now} {
+ r dbsize
+ } {10101}
+ }
test {INCR against non existing key} {
set res {}
r get novar2
} {foobared}
- test {SETNX will overwrite EXPIREing key} {
+ test {SETNX against volatile key} {
r set x 10
r expire x 10000
- r setnx x 20
- r get x
- } {20}
+ list [r setnx x 20] [r get x]
+ } {0 10}
test {EXISTS} {
set res {}
test {Commands pipelining} {
set fd [r channel]
- puts -nonewline $fd "SET k1 4\r\nxyzk\r\nGET k1\r\nPING\r\n"
+ puts -nonewline $fd "SET k1 xyzk\r\nGET k1\r\nPING\r\n"
flush $fd
set res {}
append res [string match OK* [::redis::redis_read_reply $fd]]
list [r msetnx x1 xxx y2 yyy] [r get x1] [r get y2]
} {1 xxx yyy}
- test {MSETNX should remove all the volatile keys even on failure} {
- r mset x 1 y 2 z 3
- r expire y 10000
- r expire z 10000
- list [r msetnx x A y B z C] [r mget x y z]
- } {0 {1 {} {}}}
+ test {STRLEN against non existing key} {
+ r strlen notakey
+ } {0}
+
+ test {STRLEN against integer} {
+ r set myinteger -555
+ r strlen myinteger
+ } {4}
+
+ test {STRLEN against plain string} {
+ r set mystring "foozzz0123456789 baz"
+ r strlen mystring
+ }
+
+ test "SETBIT against non-existing key" {
+ r del mykey
+
+ # Setting 2nd bit to on is integer 64, ascii "@"
+ assert_equal 1 [r setbit mykey 1 1]
+ assert_equal "@" [r get mykey]
+ }
+
+ test "SETBIT against string-encoded key" {
+ # Single byte with 2nd bit set
+ r set mykey "@"
+
+ # 64 + 32 = 96 => ascii "`" (backtick)
+ assert_equal 1 [r setbit mykey 2 1]
+ assert_equal "`" [r get mykey]
+ }
+
+ test "SETBIT against integer-encoded key" {
+ r set mykey 1
+ assert_encoding int mykey
+
+ # Ascii "1" is integer 49 = 00 11 00 01
+ # Setting 7th bit = 51 => ascii "3"
+ assert_equal 1 [r setbit mykey 6 1]
+ assert_equal "3" [r get mykey]
+ }
+
+ test "SETBIT against key with wrong type" {
+ r del mykey
+ r lpush mykey "foo"
+ assert_error "*wrong kind*" {r setbit mykey 0 1}
+ }
+
+ test "SETBIT with out of range bit offset" {
+ r del mykey
+ assert_error "*out of range*" {r setbit mykey [expr 4*1024*1024*1024] 1}
+ assert_error "*out of range*" {r setbit mykey -1 1}
+ }
+
+ test "SETBIT with non-bit argument" {
+ r del mykey
+ assert_error "*0 or 1*" {r setbit mykey 0 -1}
+ assert_error "*0 or 1*" {r setbit mykey 0 2}
+ assert_error "*0 or 1*" {r setbit mykey 0 10}
+ assert_error "*0 or 1*" {r setbit mykey 0 01}
+ }
+
+ test "GETBIT against non-existing key" {
+ r del mykey
+ assert_equal 0 [r getbit mykey 0]
+ }
+
+ test "GETBIT against string-encoded key" {
+ # Single byte with 2nd and 3rd bit set
+ r set mykey "`"
+
+ # In-range
+ assert_equal 0 [r getbit mykey 0]
+ assert_equal 1 [r getbit mykey 1]
+ assert_equal 1 [r getbit mykey 2]
+ assert_equal 0 [r getbit mykey 3]
+
+ # Out-range
+ assert_equal 0 [r getbit mykey 8]
+ assert_equal 0 [r getbit mykey 100]
+ assert_equal 0 [r getbit mykey 10000]
+ }
+
+ test "GETBIT against integer-encoded key" {
+ r set mykey 1
+ assert_encoding int mykey
+
+ # Ascii "1" is integer 49 = 00 11 00 01
+ assert_equal 0 [r getbit mykey 0]
+ assert_equal 0 [r getbit mykey 1]
+ assert_equal 1 [r getbit mykey 2]
+ assert_equal 1 [r getbit mykey 3]
+
+ # Out-range
+ assert_equal 0 [r getbit mykey 8]
+ assert_equal 0 [r getbit mykey 100]
+ assert_equal 0 [r getbit mykey 10000]
+ }
}