mirror of
https://github.com/Snapchat/KeyDB.git
synced 2026-11-25 15:49:40 -05:00
commit
fe8efa916b
298 files changed
+30298
-10182
No files matched your search
@@ -81,6 +81,110 @@ start_server {tags {"acl"}} {
|
||||
set e
|
||||
} {*NOPERM*key*}
|
||||
|
||||
test {By default users are able to publish to any channel} {
|
||||
r ACL setuser psuser on >pspass +acl +client +@pubsub
|
||||
r AUTH psuser pspass
|
||||
r PUBLISH foo bar
|
||||
} {0}
|
||||
|
||||
test {By default users are able to subscribe to any channel} {
|
||||
set rd [redis_deferring_client]
|
||||
$rd AUTH psuser pspass
|
||||
$rd read
|
||||
$rd SUBSCRIBE foo
|
||||
assert_match {subscribe foo 1} [$rd read]
|
||||
$rd close
|
||||
} {0}
|
||||
|
||||
test {By default users are able to subscribe to any pattern} {
|
||||
set rd [redis_deferring_client]
|
||||
$rd AUTH psuser pspass
|
||||
$rd read
|
||||
$rd PSUBSCRIBE bar*
|
||||
assert_match {psubscribe bar\* 1} [$rd read]
|
||||
$rd close
|
||||
} {0}
|
||||
|
||||
test {It's possible to allow publishing to a subset of channels} {
|
||||
r ACL setuser psuser resetchannels &foo:1 &bar:*
|
||||
assert_equal {0} [r PUBLISH foo:1 somemessage]
|
||||
assert_equal {0} [r PUBLISH bar:2 anothermessage]
|
||||
catch {r PUBLISH zap:3 nosuchmessage} e
|
||||
set e
|
||||
} {*NOPERM*channel*}
|
||||
|
||||
test {It's possible to allow subscribing to a subset of channels} {
|
||||
set rd [redis_deferring_client]
|
||||
$rd AUTH psuser pspass
|
||||
$rd read
|
||||
$rd SUBSCRIBE foo:1
|
||||
assert_match {subscribe foo:1 1} [$rd read]
|
||||
$rd SUBSCRIBE bar:2
|
||||
assert_match {subscribe bar:2 2} [$rd read]
|
||||
$rd SUBSCRIBE zap:3
|
||||
catch {$rd read} e
|
||||
set e
|
||||
} {*NOPERM*channel*}
|
||||
|
||||
test {It's possible to allow subscribing to a subset of channel patterns} {
|
||||
set rd [redis_deferring_client]
|
||||
$rd AUTH psuser pspass
|
||||
$rd read
|
||||
$rd PSUBSCRIBE foo:1
|
||||
assert_match {psubscribe foo:1 1} [$rd read]
|
||||
$rd PSUBSCRIBE bar:*
|
||||
assert_match {psubscribe bar:\* 2} [$rd read]
|
||||
$rd PSUBSCRIBE bar:baz
|
||||
catch {$rd read} e
|
||||
set e
|
||||
} {*NOPERM*channel*}
|
||||
|
||||
test {Subscribers are killed when revoked of channel permission} {
|
||||
set rd [redis_deferring_client]
|
||||
r ACL setuser psuser resetchannels &foo:1
|
||||
$rd AUTH psuser pspass
|
||||
$rd read
|
||||
$rd CLIENT SETNAME deathrow
|
||||
$rd read
|
||||
$rd SUBSCRIBE foo:1
|
||||
$rd read
|
||||
r ACL setuser psuser resetchannels
|
||||
assert_no_match {*deathrow*} [r CLIENT LIST]
|
||||
$rd close
|
||||
} {0}
|
||||
|
||||
test {Subscribers are killed when revoked of pattern permission} {
|
||||
set rd [redis_deferring_client]
|
||||
r ACL setuser psuser resetchannels &bar:*
|
||||
$rd AUTH psuser pspass
|
||||
$rd read
|
||||
$rd CLIENT SETNAME deathrow
|
||||
$rd read
|
||||
$rd PSUBSCRIBE bar:*
|
||||
$rd read
|
||||
r ACL setuser psuser resetchannels
|
||||
assert_no_match {*deathrow*} [r CLIENT LIST]
|
||||
$rd close
|
||||
} {0}
|
||||
|
||||
test {Subscribers are pardoned if literal permissions are retained and/or gaining allchannels} {
|
||||
set rd [redis_deferring_client]
|
||||
r ACL setuser psuser resetchannels &foo:1 &bar:*
|
||||
$rd AUTH psuser pspass
|
||||
$rd read
|
||||
$rd CLIENT SETNAME pardoned
|
||||
$rd read
|
||||
$rd SUBSCRIBE foo:1
|
||||
$rd read
|
||||
$rd PSUBSCRIBE bar:*
|
||||
$rd read
|
||||
r ACL setuser psuser resetchannels &foo:1 &bar:* &baz:qaz &zoo:*
|
||||
assert_match {*pardoned*} [r CLIENT LIST]
|
||||
r ACL setuser psuser allchannels
|
||||
assert_match {*pardoned*} [r CLIENT LIST]
|
||||
$rd close
|
||||
} {0}
|
||||
|
||||
test {Users can be configured to authenticate with any password} {
|
||||
r ACL setuser newuser nopass
|
||||
r AUTH newuser zipzapblabla
|
||||
@@ -113,6 +217,25 @@ start_server {tags {"acl"}} {
|
||||
set e
|
||||
} {*NOPERM*}
|
||||
|
||||
test {ACLs set can include subcommands, if already full command exists} {
|
||||
r ACL setuser bob +memory|doctor
|
||||
set cmdstr [dict get [r ACL getuser bob] commands]
|
||||
assert_equal {-@all +memory|doctor} $cmdstr
|
||||
|
||||
# Validate the commands have got engulfed to +memory.
|
||||
r ACL setuser bob +memory
|
||||
set cmdstr [dict get [r ACL getuser bob] commands]
|
||||
assert_equal {-@all +memory} $cmdstr
|
||||
|
||||
# Appending to the existing access string of bob.
|
||||
r ACL setuser bob +@all +client|id
|
||||
# Validate the new commands has got engulfed to +@all.
|
||||
set cmdstr [dict get [r ACL getuser bob] commands]
|
||||
assert_equal {+@all} $cmdstr
|
||||
r CLIENT ID; # Should not fail
|
||||
r MEMORY DOCTOR; # Should not fail
|
||||
}
|
||||
|
||||
# Note that the order of the generated ACL rules is not stable in Redis
|
||||
# so we need to match the different parts and not as a whole string.
|
||||
test {ACL GETUSER is able to translate back command permissions} {
|
||||
@@ -166,6 +289,7 @@ start_server {tags {"acl"}} {
|
||||
r ACL LOG RESET
|
||||
r ACL setuser antirez >foo on +set ~object:1234
|
||||
r ACL setuser antirez +eval +multi +exec
|
||||
r ACL setuser antirez resetchannels +publish
|
||||
r AUTH antirez foo
|
||||
catch {r GET foo}
|
||||
r AUTH default ""
|
||||
@@ -195,6 +319,15 @@ start_server {tags {"acl"}} {
|
||||
assert {[dict get $entry object] eq {somekeynotallowed}}
|
||||
}
|
||||
|
||||
test {ACL LOG is able to log channel access violations and channel name} {
|
||||
r AUTH antirez foo
|
||||
catch {r PUBLISH somechannelnotallowed nullmsg}
|
||||
r AUTH default ""
|
||||
set entry [lindex [r ACL LOG] 0]
|
||||
assert {[dict get $entry reason] eq {channel}}
|
||||
assert {[dict get $entry object] eq {somechannelnotallowed}}
|
||||
}
|
||||
|
||||
test {ACL LOG RESET is able to flush the entries in the log} {
|
||||
r ACL LOG RESET
|
||||
assert {[llength [r ACL LOG]] == 0}
|
||||
|
||||
@@ -25,3 +25,44 @@ start_server {tags {"auth"} overrides {requirepass foobar}} {
|
||||
r incr foo
|
||||
} {101}
|
||||
}
|
||||
|
||||
start_server {tags {"auth_binary_password"}} {
|
||||
test {AUTH fails when binary password is wrong} {
|
||||
r config set requirepass "abc\x00def"
|
||||
catch {r auth abc} err
|
||||
set _ $err
|
||||
} {WRONGPASS*}
|
||||
|
||||
test {AUTH succeeds when binary password is correct} {
|
||||
r config set requirepass "abc\x00def"
|
||||
r auth "abc\x00def"
|
||||
} {OK}
|
||||
|
||||
start_server {tags {"masterauth"}} {
|
||||
set master [srv -1 client]
|
||||
set master_host [srv -1 host]
|
||||
set master_port [srv -1 port]
|
||||
set slave [srv 0 client]
|
||||
|
||||
test {MASTERAUTH test with binary password} {
|
||||
$master config set requirepass "abc\x00def"
|
||||
|
||||
# Configure the replica with masterauth
|
||||
set loglines [count_log_lines 0]
|
||||
$slave slaveof $master_host $master_port
|
||||
$slave config set masterauth "abc"
|
||||
|
||||
# Verify replica is not able to sync with master
|
||||
wait_for_log_messages 0 {"*Unable to AUTH to MASTER*"} $loglines 1000 10
|
||||
assert_equal {down} [s 0 master_link_status]
|
||||
|
||||
# Test replica with the correct masterauth
|
||||
$slave config set masterauth "abc\x00def"
|
||||
wait_for_condition 50 100 {
|
||||
[s 0 master_link_status] eq {up}
|
||||
} else {
|
||||
fail "Can't turn the instance into a replica"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -12,7 +12,7 @@ start_server {tags {"dump"}} {
|
||||
r del foo
|
||||
r restore foo 5000 $encoded
|
||||
set ttl [r pttl foo]
|
||||
assert {$ttl >= 3000 && $ttl <= 5000}
|
||||
assert_range $ttl 3000 5000
|
||||
r get foo
|
||||
} {bar}
|
||||
|
||||
@@ -22,7 +22,7 @@ start_server {tags {"dump"}} {
|
||||
r del foo
|
||||
r restore foo 2569591501 $encoded
|
||||
set ttl [r pttl foo]
|
||||
assert {$ttl >= (2569591501-3000) && $ttl <= 2569591501}
|
||||
assert_range $ttl (2569591501-3000) 2569591501
|
||||
r get foo
|
||||
} {bar}
|
||||
|
||||
@@ -33,7 +33,7 @@ start_server {tags {"dump"}} {
|
||||
set now [clock milliseconds]
|
||||
r restore foo [expr $now+3000] $encoded absttl
|
||||
set ttl [r pttl foo]
|
||||
assert {$ttl >= 2900 && $ttl <= 3100}
|
||||
assert_range $ttl 2000 3100
|
||||
r get foo
|
||||
} {bar}
|
||||
|
||||
@@ -170,7 +170,7 @@ start_server {tags {"dump"}} {
|
||||
$second set list somevalue
|
||||
catch {r -1 migrate $second_host $second_port list 9 5000 copy} e
|
||||
assert_match {ERR*} $e
|
||||
set res [r -1 migrate $second_host $second_port list 9 5000 copy replace]
|
||||
set ret [r -1 migrate $second_host $second_port list 9 5000 copy replace]
|
||||
assert {$ret eq {OK}}
|
||||
assert {[$first exists list] == 1}
|
||||
assert {[$second exists list] == 1}
|
||||
|
||||
+173
-10
@@ -209,19 +209,153 @@ start_server {tags {"expire"}} {
|
||||
set e
|
||||
} {*not an integer*}
|
||||
|
||||
test {SET - use EX/PX option, TTL should not be reseted after loadaof} {
|
||||
r config set appendonly yes
|
||||
r set foo bar EX 100
|
||||
after 2000
|
||||
r debug loadaof
|
||||
set ttl [r ttl foo]
|
||||
assert {$ttl <= 98 && $ttl > 90}
|
||||
test {SET with EX with big integer should report an error} {
|
||||
catch {r set foo bar EX 10000000000000000} e
|
||||
set e
|
||||
} {ERR invalid expire time in set}
|
||||
|
||||
test {SET with EX with smallest integer should report an error} {
|
||||
catch {r SET foo bar EX -9999999999999999} e
|
||||
set e
|
||||
} {ERR invalid expire time in set}
|
||||
|
||||
test {GETEX with big integer should report an error} {
|
||||
r set foo bar
|
||||
catch {r GETEX foo EX 10000000000000000} e
|
||||
set e
|
||||
} {ERR invalid expire time in getex}
|
||||
|
||||
test {GETEX with smallest integer should report an error} {
|
||||
r set foo bar
|
||||
catch {r GETEX foo EX -9999999999999999} e
|
||||
set e
|
||||
} {ERR invalid expire time in getex}
|
||||
|
||||
test {EXPIRE with big integer overflows when converted to milliseconds} {
|
||||
r set foo bar
|
||||
catch {r EXPIRE foo 10000000000000000} e
|
||||
set e
|
||||
} {ERR invalid expire time in expire}
|
||||
|
||||
test {PEXPIRE with big integer overflow when basetime is added} {
|
||||
r set foo bar
|
||||
catch {r PEXPIRE foo 9223372036854770000} e
|
||||
set e
|
||||
} {ERR invalid expire time in pexpire}
|
||||
|
||||
test {EXPIRE with big negative integer} {
|
||||
r set foo bar
|
||||
catch {r EXPIRE foo -9999999999999999} e
|
||||
assert_match {ERR invalid expire time in expire} $e
|
||||
r ttl foo
|
||||
} {-1}
|
||||
|
||||
test {PEXPIREAT with big integer works} {
|
||||
r set foo bar
|
||||
r PEXPIREAT foo 9223372036854770000
|
||||
} {1}
|
||||
|
||||
test {PEXPIREAT with big negative integer works} {
|
||||
r set foo bar
|
||||
r PEXPIREAT foo -9223372036854770000
|
||||
r ttl foo
|
||||
} {-2}
|
||||
|
||||
test {EXPIRE and SET/GETEX EX/PX/EXAT/PXAT option, TTL should not be reset after loadaof} {
|
||||
# This test makes sure that expire times are propagated as absolute
|
||||
# times to the AOF file and not as relative time, so that when the AOF
|
||||
# is reloaded the TTLs are not being shifted forward to the future.
|
||||
# We want the time to logically pass when the server is restarted!
|
||||
|
||||
r config set appendonly yes
|
||||
r set foo1 bar EX 100
|
||||
r set foo2 bar PX 100000
|
||||
r set foo3 bar
|
||||
r set foo4 bar
|
||||
r expire foo3 100
|
||||
r pexpire foo4 100000
|
||||
r setex foo5 100 bar
|
||||
r psetex foo6 100000 bar
|
||||
r set foo7 bar EXAT [expr [clock seconds] + 100]
|
||||
r set foo8 bar PXAT [expr [clock milliseconds] + 100000]
|
||||
r set foo9 bar
|
||||
r getex foo9 EX 100
|
||||
r set foo10 bar
|
||||
r getex foo10 PX 100000
|
||||
r set foo11 bar
|
||||
r getex foo11 EXAT [expr [clock seconds] + 100]
|
||||
r set foo12 bar
|
||||
r getex foo12 PXAT [expr [clock milliseconds] + 100000]
|
||||
|
||||
r set foo bar PX 100000
|
||||
after 2000
|
||||
r debug loadaof
|
||||
set ttl [r ttl foo]
|
||||
assert {$ttl <= 98 && $ttl > 90}
|
||||
assert_range [r ttl foo1] 90 98
|
||||
assert_range [r ttl foo2] 90 98
|
||||
assert_range [r ttl foo3] 90 98
|
||||
assert_range [r ttl foo4] 90 98
|
||||
assert_range [r ttl foo5] 90 98
|
||||
assert_range [r ttl foo6] 90 98
|
||||
assert_range [r ttl foo7] 90 98
|
||||
assert_range [r ttl foo8] 90 98
|
||||
assert_range [r ttl foo9] 90 98
|
||||
assert_range [r ttl foo10] 90 98
|
||||
assert_range [r ttl foo11] 90 98
|
||||
assert_range [r ttl foo12] 90 98
|
||||
}
|
||||
|
||||
test {EXPIRE relative and absolute propagation to replicas} {
|
||||
# Make sure that relative and absolute expire commands are propagated
|
||||
# "as is" to replicas.
|
||||
# We want replicas to honor the same high level contract of expires that
|
||||
# the master has, that is, we want the time to be counted logically
|
||||
# starting from the moment the write was received. This usually provides
|
||||
# the most coherent behavior from the point of view of the external
|
||||
# users, with TTLs that are similar from the POV of the external observer.
|
||||
#
|
||||
# This test is here to stop some innocent / eager optimization or cleanup
|
||||
# from doing the wrong thing without proper discussion, see:
|
||||
# https://github.com/redis/redis/pull/5171#issuecomment-409553266
|
||||
|
||||
set repl [attach_to_replication_stream]
|
||||
r set foo1 bar ex 200
|
||||
r set foo1 bar px 100000
|
||||
r set foo1 bar exat [expr [clock seconds]+100]
|
||||
r set foo1 bar pxat [expr [clock milliseconds]+10000]
|
||||
r setex foo1 100 bar
|
||||
r psetex foo1 100000 bar
|
||||
r set foo2 bar
|
||||
r expire foo2 100
|
||||
r pexpire foo2 100000
|
||||
r set foo3 bar
|
||||
r expireat foo3 [expr [clock seconds]+100]
|
||||
r pexpireat foo3 [expr [clock seconds]*1000+100000]
|
||||
r expireat foo3 [expr [clock seconds]-100]
|
||||
r set foo4 bar
|
||||
r getex foo4 ex 200
|
||||
r getex foo4 px 200000
|
||||
r getex foo4 exat [expr [clock seconds]+100]
|
||||
r getex foo4 pxat [expr [clock milliseconds]+10000]
|
||||
assert_replication_stream $repl {
|
||||
{select *}
|
||||
{set foo1 bar PX 200000}
|
||||
{set foo1 bar PX 100000}
|
||||
{set foo1 bar PXAT *}
|
||||
{set foo1 bar PXAT *}
|
||||
{set foo1 bar PX 100000}
|
||||
{set foo1 bar PX 100000}
|
||||
{set foo2 bar}
|
||||
{expire foo2 100}
|
||||
{pexpire foo2 100000}
|
||||
{set foo3 bar}
|
||||
{expireat foo3 *}
|
||||
{pexpireat foo3 *}
|
||||
{del foo3}
|
||||
{set foo4 bar}
|
||||
{pexpire foo4 200000}
|
||||
{pexpire foo4 200000}
|
||||
{pexpireat foo4 *}
|
||||
{pexpireat foo4 *}
|
||||
}
|
||||
}
|
||||
|
||||
test {EXPIREMEMBER works (set)} {
|
||||
@@ -318,6 +452,7 @@ start_server {tags {"expire"}} {
|
||||
assert_equal [r dbsize] 0
|
||||
}
|
||||
|
||||
|
||||
test {SET - use KEEPTTL option, TTL should not be removed after loadaof} {
|
||||
r config set appendonly yes
|
||||
r set foo bar EX 100
|
||||
@@ -327,4 +462,32 @@ start_server {tags {"expire"}} {
|
||||
set ttl [r ttl foo]
|
||||
assert {$ttl <= 98 && $ttl > 90}
|
||||
}
|
||||
|
||||
test {GETEX use of PERSIST option should remove TTL} {
|
||||
r set foo bar EX 100
|
||||
r getex foo PERSIST
|
||||
r ttl foo
|
||||
} {-1}
|
||||
|
||||
test {GETEX use of PERSIST option should remove TTL after loadaof} {
|
||||
r set foo bar EX 100
|
||||
r getex foo PERSIST
|
||||
after 2000
|
||||
r debug loadaof
|
||||
r ttl foo
|
||||
} {-1}
|
||||
|
||||
test {GETEX propagate as to replica as PERSIST, DEL, or nothing} {
|
||||
set repl [attach_to_replication_stream]
|
||||
r set foo bar EX 100
|
||||
r getex foo PERSIST
|
||||
r getex foo
|
||||
r getex foo exat [expr [clock seconds]-100]
|
||||
assert_replication_stream $repl {
|
||||
{select *}
|
||||
{set foo bar PX 100000}
|
||||
{persist foo}
|
||||
{del foo}
|
||||
}
|
||||
}
|
||||
}
|
||||
+323
-24
@@ -1,6 +1,7 @@
|
||||
# Helper functions to simulate search-in-radius in the Tcl side in order to
|
||||
# verify the Redis implementation with a fuzzy test.
|
||||
proc geo_degrad deg {expr {$deg*atan(1)*8/360}}
|
||||
proc geo_degrad deg {expr {$deg*(atan(1)*8/360)}}
|
||||
proc geo_raddeg rad {expr {$rad/(atan(1)*8/360)}}
|
||||
|
||||
proc geo_distance {lon1d lat1d lon2d lat2d} {
|
||||
set lon1r [geo_degrad $lon1d]
|
||||
@@ -42,6 +43,34 @@ proc compare_lists {List1 List2} {
|
||||
return $DiffList
|
||||
}
|
||||
|
||||
# return true If a point in circle.
|
||||
# search_lon and search_lat define the center of the circle,
|
||||
# and lon, lat define the point being searched.
|
||||
proc pointInCircle {radius_km lon lat search_lon search_lat} {
|
||||
set radius_m [expr {$radius_km*1000}]
|
||||
set distance [geo_distance $lon $lat $search_lon $search_lat]
|
||||
if {$distance < $radius_m} {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
# return true If a point in rectangle.
|
||||
# search_lon and search_lat define the center of the rectangle,
|
||||
# and lon, lat define the point being searched.
|
||||
# error: can adjust the width and height of the rectangle according to the error
|
||||
proc pointInRectangle {width_km height_km lon lat search_lon search_lat error} {
|
||||
set width_m [expr {$width_km*1000*$error/2}]
|
||||
set height_m [expr {$height_km*1000*$error/2}]
|
||||
set lon_distance [geo_distance $lon $lat $search_lon $lat]
|
||||
set lat_distance [geo_distance $lon $lat $lon $search_lat]
|
||||
|
||||
if {$lon_distance > $width_m || $lat_distance > $height_m} {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
# The following list represents sets of random seed, search position
|
||||
# and radius that caused bugs in the past. It is used by the randomized
|
||||
# test later as a starting point. When the regression vectors are scanned
|
||||
@@ -74,6 +103,49 @@ start_server {tags {"geo"}} {
|
||||
r geoadd nyc -73.9454966 40.747533 "lic market"
|
||||
} {0}
|
||||
|
||||
test {GEOADD update with CH option} {
|
||||
assert_equal 1 [r geoadd nyc CH 40.747533 -73.9454966 "lic market"]
|
||||
lassign [lindex [r geopos nyc "lic market"] 0] x1 y1
|
||||
assert {abs($x1) - 40.747 < 0.001}
|
||||
assert {abs($y1) - 73.945 < 0.001}
|
||||
} {}
|
||||
|
||||
test {GEOADD update with NX option} {
|
||||
assert_equal 0 [r geoadd nyc NX -73.9454966 40.747533 "lic market"]
|
||||
lassign [lindex [r geopos nyc "lic market"] 0] x1 y1
|
||||
assert {abs($x1) - 40.747 < 0.001}
|
||||
assert {abs($y1) - 73.945 < 0.001}
|
||||
} {}
|
||||
|
||||
test {GEOADD update with XX option} {
|
||||
assert_equal 0 [r geoadd nyc XX -83.9454966 40.747533 "lic market"]
|
||||
lassign [lindex [r geopos nyc "lic market"] 0] x1 y1
|
||||
assert {abs($x1) - 83.945 < 0.001}
|
||||
assert {abs($y1) - 40.747 < 0.001}
|
||||
} {}
|
||||
|
||||
test {GEOADD update with CH NX option} {
|
||||
r geoadd nyc CH NX -73.9454966 40.747533 "lic market"
|
||||
} {0}
|
||||
|
||||
test {GEOADD update with CH XX option} {
|
||||
r geoadd nyc CH XX -73.9454966 40.747533 "lic market"
|
||||
} {1}
|
||||
|
||||
test {GEOADD update with XX NX option will return syntax error} {
|
||||
catch {
|
||||
r geoadd nyc xx nx -73.9454966 40.747533 "lic market"
|
||||
} err
|
||||
set err
|
||||
} {ERR*syntax*}
|
||||
|
||||
test {GEOADD update with invalid option} {
|
||||
catch {
|
||||
r geoadd nyc ch xx foo -73.9454966 40.747533 "lic market"
|
||||
} err
|
||||
set err
|
||||
} {ERR*syntax*}
|
||||
|
||||
test {GEOADD invalid coordinates} {
|
||||
catch {
|
||||
r geoadd nyc -73.9454966 40.747533 "lic market" \
|
||||
@@ -94,14 +166,60 @@ start_server {tags {"geo"}} {
|
||||
r georadius nyc -73.9798091 40.7598464 3 km asc
|
||||
} {{central park n/q/r} 4545 {union square}}
|
||||
|
||||
test {GEOSEARCH simple (sorted)} {
|
||||
r geosearch nyc fromlonlat -73.9798091 40.7598464 bybox 6 6 km asc
|
||||
} {{central park n/q/r} 4545 {union square} {lic market}}
|
||||
|
||||
test {GEOSEARCH FROMLONLAT and FROMMEMBER cannot exist at the same time} {
|
||||
catch {r geosearch nyc fromlonlat -73.9798091 40.7598464 frommember xxx bybox 6 6 km asc} e
|
||||
set e
|
||||
} {ERR*syntax*}
|
||||
|
||||
test {GEOSEARCH FROMLONLAT and FROMMEMBER one must exist} {
|
||||
catch {r geosearch nyc bybox 3 3 km asc desc withhash withdist withcoord} e
|
||||
set e
|
||||
} {ERR*exactly one of FROMMEMBER or FROMLONLAT*}
|
||||
|
||||
test {GEOSEARCH BYRADIUS and BYBOX cannot exist at the same time} {
|
||||
catch {r geosearch nyc fromlonlat -73.9798091 40.7598464 byradius 3 km bybox 3 3 km asc} e
|
||||
set e
|
||||
} {ERR*syntax*}
|
||||
|
||||
test {GEOSEARCH BYRADIUS and BYBOX one must exist} {
|
||||
catch {r geosearch nyc fromlonlat -73.9798091 40.7598464 asc desc withhash withdist withcoord} e
|
||||
set e
|
||||
} {ERR*exactly one of BYRADIUS and BYBOX*}
|
||||
|
||||
test {GEOSEARCH with STOREDIST option} {
|
||||
catch {r geosearch nyc fromlonlat -73.9798091 40.7598464 bybox 6 6 km asc storedist} e
|
||||
set e
|
||||
} {ERR*syntax*}
|
||||
|
||||
test {GEORADIUS withdist (sorted)} {
|
||||
r georadius nyc -73.9798091 40.7598464 3 km withdist asc
|
||||
} {{{central park n/q/r} 0.7750} {4545 2.3651} {{union square} 2.7697}}
|
||||
|
||||
test {GEOSEARCH withdist (sorted)} {
|
||||
r geosearch nyc fromlonlat -73.9798091 40.7598464 bybox 6 6 km withdist asc
|
||||
} {{{central park n/q/r} 0.7750} {4545 2.3651} {{union square} 2.7697} {{lic market} 3.1991}}
|
||||
|
||||
test {GEORADIUS with COUNT} {
|
||||
r georadius nyc -73.9798091 40.7598464 10 km COUNT 3
|
||||
} {{central park n/q/r} 4545 {union square}}
|
||||
|
||||
test {GEORADIUS with ANY not sorted by default} {
|
||||
r georadius nyc -73.9798091 40.7598464 10 km COUNT 3 ANY
|
||||
} {{wtc one} {union square} {central park n/q/r}}
|
||||
|
||||
test {GEORADIUS with ANY sorted by ASC} {
|
||||
r georadius nyc -73.9798091 40.7598464 10 km COUNT 3 ANY ASC
|
||||
} {{central park n/q/r} {union square} {wtc one}}
|
||||
|
||||
test {GEORADIUS with ANY but no COUNT} {
|
||||
catch {r georadius nyc -73.9798091 40.7598464 10 km ANY ASC} e
|
||||
set e
|
||||
} {ERR*ANY*requires*COUNT*}
|
||||
|
||||
test {GEORADIUS with COUNT but missing integer argument} {
|
||||
catch {r georadius nyc -73.9798091 40.7598464 10 km COUNT} e
|
||||
set e
|
||||
@@ -120,6 +238,42 @@ start_server {tags {"geo"}} {
|
||||
r georadiusbymember nyc "wtc one" 7 km
|
||||
} {{wtc one} {union square} {central park n/q/r} 4545 {lic market}}
|
||||
|
||||
test {GEOSEARCH FROMMEMBER simple (sorted)} {
|
||||
r geosearch nyc frommember "wtc one" bybox 14 14 km
|
||||
} {{wtc one} {union square} {central park n/q/r} 4545 {lic market} q4}
|
||||
|
||||
test {GEOSEARCH vs GEORADIUS} {
|
||||
r del Sicily
|
||||
r geoadd Sicily 13.361389 38.115556 "Palermo" 15.087269 37.502669 "Catania"
|
||||
r geoadd Sicily 12.758489 38.788135 "edge1" 17.241510 38.788135 "eage2"
|
||||
set ret1 [r georadius Sicily 15 37 200 km asc]
|
||||
assert_equal $ret1 {Catania Palermo}
|
||||
set ret2 [r geosearch Sicily fromlonlat 15 37 bybox 400 400 km asc]
|
||||
assert_equal $ret2 {Catania Palermo eage2 edge1}
|
||||
}
|
||||
|
||||
test {GEOSEARCH non square, long and narrow} {
|
||||
r del Sicily
|
||||
r geoadd Sicily 12.75 36.995 "test1"
|
||||
r geoadd Sicily 12.75 36.50 "test2"
|
||||
r geoadd Sicily 13.00 36.50 "test3"
|
||||
# box height=2km width=400km
|
||||
set ret1 [r geosearch Sicily fromlonlat 15 37 bybox 400 2 km]
|
||||
assert_equal $ret1 {test1}
|
||||
|
||||
# Add a western Hemisphere point
|
||||
r geoadd Sicily -1 37.00 "test3"
|
||||
set ret2 [r geosearch Sicily fromlonlat 15 37 bybox 3000 2 km asc]
|
||||
assert_equal $ret2 {test1 test3}
|
||||
}
|
||||
|
||||
test {GEOSEARCH corner point test} {
|
||||
r del Sicily
|
||||
r geoadd Sicily 12.758489 38.788135 edge1 17.241510 38.788135 edge2 17.250000 35.202000 edge3 12.750000 35.202000 edge4 12.748489955781654 37 edge5 15 38.798135872540925 edge6 17.251510044218346 37 edge7 15 35.201864127459075 edge8 12.692799634687903 38.798135872540925 corner1 12.692799634687903 38.798135872540925 corner2 17.200560937451133 35.201864127459075 corner3 12.799439062548865 35.201864127459075 corner4
|
||||
set ret [lsort [r geosearch Sicily fromlonlat 15 37 bybox 400 400 km asc]]
|
||||
assert_equal $ret {edge1 edge2 edge5 edge7}
|
||||
}
|
||||
|
||||
test {GEORADIUSBYMEMBER withdist (sorted)} {
|
||||
r georadiusbymember nyc "wtc one" 7 km withdist
|
||||
} {{{wtc one} 0.0000} {{union square} 3.2544} {{central park n/q/r} 6.7000} {4545 6.1975} {{lic market} 6.8969}}
|
||||
@@ -178,6 +332,11 @@ start_server {tags {"geo"}} {
|
||||
set e
|
||||
} {*ERR*syntax*}
|
||||
|
||||
test {GEOSEARCHSTORE STORE option: syntax error} {
|
||||
catch {r geosearchstore abc points fromlonlat 13.361389 38.115556 byradius 50 km store abc} e
|
||||
set e
|
||||
} {*ERR*syntax*}
|
||||
|
||||
test {GEORANGE STORE option: incompatible options} {
|
||||
r del points
|
||||
r geoadd points 13.361389 38.115556 "Palermo" \
|
||||
@@ -198,6 +357,11 @@ start_server {tags {"geo"}} {
|
||||
assert_equal [r zrange points 0 -1] [r zrange points2 0 -1]
|
||||
}
|
||||
|
||||
test {GEOSEARCHSTORE STORE option: plain usage} {
|
||||
r geosearchstore points2 points fromlonlat 13.361389 38.115556 byradius 500 km
|
||||
assert_equal [r zrange points 0 -1] [r zrange points2 0 -1]
|
||||
}
|
||||
|
||||
test {GEORANGE STOREDIST option: plain usage} {
|
||||
r del points
|
||||
r geoadd points 13.361389 38.115556 "Palermo" \
|
||||
@@ -209,6 +373,14 @@ start_server {tags {"geo"}} {
|
||||
assert {[lindex $res 3] < 167}
|
||||
}
|
||||
|
||||
test {GEOSEARCHSTORE STOREDIST option: plain usage} {
|
||||
r geosearchstore points2 points fromlonlat 13.361389 38.115556 byradius 500 km storedist
|
||||
set res [r zrange points2 0 -1 withscores]
|
||||
assert {[lindex $res 1] < 1}
|
||||
assert {[lindex $res 3] > 166}
|
||||
assert {[lindex $res 3] < 167}
|
||||
}
|
||||
|
||||
test {GEORANGE STOREDIST option: COUNT ASC and DESC} {
|
||||
r del points
|
||||
r geoadd points 13.361389 38.115556 "Palermo" \
|
||||
@@ -224,12 +396,22 @@ start_server {tags {"geo"}} {
|
||||
assert {[lindex $res 0] eq "Catania"}
|
||||
}
|
||||
|
||||
test {GEOADD + GEORANGE randomized test} {
|
||||
set attempt 30
|
||||
test {GEOSEARCH the box spans -180° or 180°} {
|
||||
r del points
|
||||
r geoadd points 179.5 36 point1
|
||||
r geoadd points -179.5 36 point2
|
||||
assert_equal {point1 point2} [r geosearch points fromlonlat 179 37 bybox 400 400 km asc]
|
||||
assert_equal {point2 point1} [r geosearch points fromlonlat -179 37 bybox 400 400 km asc]
|
||||
}
|
||||
|
||||
foreach {type} {byradius bybox} {
|
||||
test "GEOSEARCH fuzzy test - $type" {
|
||||
if {$::accurate} { set attempt 300 } else { set attempt 30 }
|
||||
while {[incr attempt -1]} {
|
||||
set rv [lindex $regression_vectors $rv_idx]
|
||||
incr rv_idx
|
||||
|
||||
set radius_km 0; set width_km 0; set height_km 0
|
||||
unset -nocomplain debuginfo
|
||||
set srand_seed [clock milliseconds]
|
||||
if {$rv ne {}} {set srand_seed [lindex $rv 0]}
|
||||
@@ -239,33 +421,55 @@ start_server {tags {"geo"}} {
|
||||
|
||||
if {[randomInt 10] == 0} {
|
||||
# From time to time use very big radiuses
|
||||
set radius_km [expr {[randomInt 50000]+10}]
|
||||
if {$type == "byradius"} {
|
||||
set radius_km [expr {[randomInt 5000]+10}]
|
||||
} elseif {$type == "bybox"} {
|
||||
set width_km [expr {[randomInt 5000]+10}]
|
||||
set height_km [expr {[randomInt 5000]+10}]
|
||||
}
|
||||
} else {
|
||||
# Normally use a few - ~200km radiuses to stress
|
||||
# test the code the most in edge cases.
|
||||
set radius_km [expr {[randomInt 200]+10}]
|
||||
if {$type == "byradius"} {
|
||||
set radius_km [expr {[randomInt 200]+10}]
|
||||
} elseif {$type == "bybox"} {
|
||||
set width_km [expr {[randomInt 200]+10}]
|
||||
set height_km [expr {[randomInt 200]+10}]
|
||||
}
|
||||
}
|
||||
if {$rv ne {}} {
|
||||
set radius_km [lindex $rv 1]
|
||||
set width_km [lindex $rv 1]
|
||||
set height_km [lindex $rv 1]
|
||||
}
|
||||
if {$rv ne {}} {set radius_km [lindex $rv 1]}
|
||||
set radius_m [expr {$radius_km*1000}]
|
||||
geo_random_point search_lon search_lat
|
||||
if {$rv ne {}} {
|
||||
set search_lon [lindex $rv 2]
|
||||
set search_lat [lindex $rv 3]
|
||||
}
|
||||
lappend debuginfo "Search area: $search_lon,$search_lat $radius_km km"
|
||||
lappend debuginfo "Search area: $search_lon,$search_lat $radius_km $width_km $height_km km"
|
||||
set tcl_result {}
|
||||
set argv {}
|
||||
for {set j 0} {$j < 20000} {incr j} {
|
||||
geo_random_point lon lat
|
||||
lappend argv $lon $lat "place:$j"
|
||||
set distance [geo_distance $lon $lat $search_lon $search_lat]
|
||||
if {$distance < $radius_m} {
|
||||
lappend tcl_result "place:$j"
|
||||
if {$type == "byradius"} {
|
||||
if {[pointInCircle $radius_km $lon $lat $search_lon $search_lat]} {
|
||||
lappend tcl_result "place:$j"
|
||||
}
|
||||
} elseif {$type == "bybox"} {
|
||||
if {[pointInRectangle $width_km $height_km $lon $lat $search_lon $search_lat 1]} {
|
||||
lappend tcl_result "place:$j"
|
||||
}
|
||||
}
|
||||
lappend debuginfo "place:$j $lon $lat [expr {$distance/1000}] km"
|
||||
lappend debuginfo "place:$j $lon $lat"
|
||||
}
|
||||
r geoadd mypoints {*}$argv
|
||||
set res [lsort [r georadius mypoints $search_lon $search_lat $radius_km km]]
|
||||
if {$type == "byradius"} {
|
||||
set res [lsort [r geosearch mypoints fromlonlat $search_lon $search_lat byradius $radius_km km]]
|
||||
} elseif {$type == "bybox"} {
|
||||
set res [lsort [r geosearch mypoints fromlonlat $search_lon $search_lat bybox $width_km $height_km km]]
|
||||
}
|
||||
set res2 [lsort $tcl_result]
|
||||
set test_result OK
|
||||
|
||||
@@ -273,18 +477,27 @@ start_server {tags {"geo"}} {
|
||||
set rounding_errors 0
|
||||
set diff [compare_lists $res $res2]
|
||||
foreach place $diff {
|
||||
lassign [lindex [r geopos mypoints $place] 0] lon lat
|
||||
set mydist [geo_distance $lon $lat $search_lon $search_lat]
|
||||
set mydist [expr $mydist/1000]
|
||||
if {($mydist / $radius_km) > 0.999} {
|
||||
incr rounding_errors
|
||||
continue
|
||||
}
|
||||
if {$mydist < $radius_m} {
|
||||
# This is a false positive for redis since given the
|
||||
# same points the higher precision calculation provided
|
||||
# by TCL shows the point within range
|
||||
incr rounding_errors
|
||||
continue
|
||||
if {$type == "byradius"} {
|
||||
if {($mydist / $radius_km) > 0.999} {
|
||||
incr rounding_errors
|
||||
continue
|
||||
}
|
||||
if {$mydist < [expr {$radius_km*1000}]} {
|
||||
# This is a false positive for redis since given the
|
||||
# same points the higher precision calculation provided
|
||||
# by TCL shows the point within range
|
||||
incr rounding_errors
|
||||
continue
|
||||
}
|
||||
} elseif {$type == "bybox"} {
|
||||
# we add 0.1% error for floating point calculation error
|
||||
if {[pointInRectangle $width_km $height_km $lon $lat $search_lon $search_lat 1.001]} {
|
||||
incr rounding_errors
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -311,7 +524,6 @@ start_server {tags {"geo"}} {
|
||||
set mydist [geo_distance $lon $lat $search_lon $search_lat]
|
||||
set mydist [expr $mydist/1000]
|
||||
puts "$place -> [r geopos mypoints $place] $mydist $where"
|
||||
if {($mydist / $radius_km) > 0.999} {incr rounding_errors}
|
||||
}
|
||||
set test_result FAIL
|
||||
}
|
||||
@@ -320,4 +532,91 @@ start_server {tags {"geo"}} {
|
||||
}
|
||||
set test_result
|
||||
} {OK}
|
||||
}
|
||||
|
||||
test {GEOSEARCH box edges fuzzy test} {
|
||||
if {$::accurate} { set attempt 300 } else { set attempt 30 }
|
||||
while {[incr attempt -1]} {
|
||||
unset -nocomplain debuginfo
|
||||
set srand_seed [clock milliseconds]
|
||||
lappend debuginfo "srand_seed is $srand_seed"
|
||||
expr {srand($srand_seed)} ; # If you need a reproducible run
|
||||
r del mypoints
|
||||
|
||||
geo_random_point search_lon search_lat
|
||||
set width_m [expr {[randomInt 10000]+10}]
|
||||
set height_m [expr {[randomInt 10000]+10}]
|
||||
set lat_delta [geo_raddeg [expr {$height_m/2/6372797.560856}]]
|
||||
set long_delta_top [geo_raddeg [expr {$width_m/2/6372797.560856/cos([geo_degrad [expr {$search_lat+$lat_delta}]])}]]
|
||||
set long_delta_middle [geo_raddeg [expr {$width_m/2/6372797.560856/cos([geo_degrad $search_lat])}]]
|
||||
set long_delta_bottom [geo_raddeg [expr {$width_m/2/6372797.560856/cos([geo_degrad [expr {$search_lat-$lat_delta}]])}]]
|
||||
|
||||
# Total of 8 points are generated, which are located at each vertex and the center of each side
|
||||
set points(north) [list $search_lon [expr {$search_lat+$lat_delta}]]
|
||||
set points(south) [list $search_lon [expr {$search_lat-$lat_delta}]]
|
||||
set points(east) [list [expr {$search_lon+$long_delta_middle}] $search_lat]
|
||||
set points(west) [list [expr {$search_lon-$long_delta_middle}] $search_lat]
|
||||
set points(north_east) [list [expr {$search_lon+$long_delta_top}] [expr {$search_lat+$lat_delta}]]
|
||||
set points(north_west) [list [expr {$search_lon-$long_delta_top}] [expr {$search_lat+$lat_delta}]]
|
||||
set points(south_east) [list [expr {$search_lon+$long_delta_bottom}] [expr {$search_lat-$lat_delta}]]
|
||||
set points(south_west) [list [expr {$search_lon-$long_delta_bottom}] [expr {$search_lat-$lat_delta}]]
|
||||
|
||||
lappend debuginfo "Search area: geosearch mypoints fromlonlat $search_lon $search_lat bybox $width_m $height_m m"
|
||||
set tcl_result {}
|
||||
foreach name [array names points] {
|
||||
set x [lindex $points($name) 0]
|
||||
set y [lindex $points($name) 1]
|
||||
# If longitude crosses -180° or 180°, we need to convert it.
|
||||
# latitude doesn't have this problem, because it's scope is -70~70, see geo_random_point
|
||||
if {$x > 180} {
|
||||
set x [expr {$x-360}]
|
||||
} elseif {$x < -180} {
|
||||
set x [expr {$x+360}]
|
||||
}
|
||||
r geoadd mypoints $x $y place:$name
|
||||
lappend tcl_result "place:$name"
|
||||
lappend debuginfo "geoadd mypoints $x $y place:$name"
|
||||
}
|
||||
|
||||
set res2 [lsort $tcl_result]
|
||||
|
||||
# make the box larger by two meter in each direction to put the coordinate slightly inside the box.
|
||||
set height_new [expr {$height_m+4}]
|
||||
set width_new [expr {$width_m+4}]
|
||||
set res [lsort [r geosearch mypoints fromlonlat $search_lon $search_lat bybox $width_new $height_new m]]
|
||||
if {$res != $res2} {
|
||||
set diff [compare_lists $res $res2]
|
||||
lappend debuginfo "res: $res, res2: $res2, diff: $diff"
|
||||
fail "place should be found, debuginfo: $debuginfo, height_new: $height_new width_new: $width_new"
|
||||
}
|
||||
|
||||
# The width decreases and the height increases. Only north and south are found
|
||||
set width_new [expr {$width_m-4}]
|
||||
set height_new [expr {$height_m+4}]
|
||||
set res [lsort [r geosearch mypoints fromlonlat $search_lon $search_lat bybox $width_new $height_new m]]
|
||||
if {$res != {place:north place:south}} {
|
||||
lappend debuginfo "res: $res"
|
||||
fail "place should not be found, debuginfo: $debuginfo, height_new: $height_new width_new: $width_new"
|
||||
}
|
||||
|
||||
# The width increases and the height decreases. Only ease and west are found
|
||||
set width_new [expr {$width_m+4}]
|
||||
set height_new [expr {$height_m-4}]
|
||||
set res [lsort [r geosearch mypoints fromlonlat $search_lon $search_lat bybox $width_new $height_new m]]
|
||||
if {$res != {place:east place:west}} {
|
||||
lappend debuginfo "res: $res"
|
||||
fail "place should not be found, debuginfo: $debuginfo, height_new: $height_new width_new: $width_new"
|
||||
}
|
||||
|
||||
# make the box smaller by two meter in each direction to put the coordinate slightly outside the box.
|
||||
set height_new [expr {$height_m-4}]
|
||||
set width_new [expr {$width_m-4}]
|
||||
set res [r geosearch mypoints fromlonlat $search_lon $search_lat bybox $width_new $height_new m]
|
||||
if {$res != ""} {
|
||||
lappend debuginfo "res: $res"
|
||||
fail "place should not be found, debuginfo: $debuginfo, height_new: $height_new width_new: $width_new"
|
||||
}
|
||||
unset -nocomplain debuginfo
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
proc cmdstat {cmd} {
|
||||
return [cmdrstat $cmd r]
|
||||
}
|
||||
|
||||
proc errorstat {cmd} {
|
||||
return [errorrstat $cmd r]
|
||||
}
|
||||
|
||||
start_server {tags {"info"}} {
|
||||
start_server {} {
|
||||
|
||||
test {errorstats: failed call authentication error} {
|
||||
r config resetstat
|
||||
assert_match {} [errorstat ERR]
|
||||
assert_equal [s total_error_replies] 0
|
||||
catch {r auth k} e
|
||||
assert_match {ERR AUTH*} $e
|
||||
assert_match {*count=1*} [errorstat ERR]
|
||||
assert_match {*calls=1,*,rejected_calls=0,failed_calls=1} [cmdstat auth]
|
||||
assert_equal [s total_error_replies] 1
|
||||
r config resetstat
|
||||
assert_match {} [errorstat ERR]
|
||||
}
|
||||
|
||||
test {errorstats: failed call within MULTI/EXEC} {
|
||||
r config resetstat
|
||||
assert_match {} [errorstat ERR]
|
||||
assert_equal [s total_error_replies] 0
|
||||
r multi
|
||||
r set a b
|
||||
r auth a
|
||||
catch {r exec} e
|
||||
assert_match {ERR AUTH*} $e
|
||||
assert_match {*count=1*} [errorstat ERR]
|
||||
assert_match {*calls=1,*,rejected_calls=0,failed_calls=0} [cmdstat set]
|
||||
assert_match {*calls=1,*,rejected_calls=0,failed_calls=1} [cmdstat auth]
|
||||
assert_match {*calls=1,*,rejected_calls=0,failed_calls=0} [cmdstat exec]
|
||||
assert_equal [s total_error_replies] 1
|
||||
|
||||
# MULTI/EXEC command errors should still be pinpointed to him
|
||||
catch {r exec} e
|
||||
assert_match {ERR EXEC without MULTI} $e
|
||||
assert_match {*calls=2,*,rejected_calls=0,failed_calls=1} [cmdstat exec]
|
||||
assert_match {*count=2*} [errorstat ERR]
|
||||
assert_equal [s total_error_replies] 2
|
||||
}
|
||||
|
||||
test {errorstats: failed call within LUA} {
|
||||
r config resetstat
|
||||
assert_match {} [errorstat ERR]
|
||||
assert_equal [s total_error_replies] 0
|
||||
catch {r eval {redis.pcall('XGROUP', 'CREATECONSUMER', 's1', 'mygroup', 'consumer') return } 0} e
|
||||
assert_match {*count=1*} [errorstat ERR]
|
||||
assert_match {*calls=1,*,rejected_calls=0,failed_calls=1} [cmdstat xgroup]
|
||||
assert_match {*calls=1,*,rejected_calls=0,failed_calls=0} [cmdstat eval]
|
||||
|
||||
# EVAL command errors should still be pinpointed to him
|
||||
catch {r eval a} e
|
||||
assert_match {ERR wrong*} $e
|
||||
assert_match {*calls=1,*,rejected_calls=1,failed_calls=0} [cmdstat eval]
|
||||
assert_match {*count=2*} [errorstat ERR]
|
||||
assert_equal [s total_error_replies] 2
|
||||
}
|
||||
|
||||
test {errorstats: failed call NOSCRIPT error} {
|
||||
r config resetstat
|
||||
assert_equal [s total_error_replies] 0
|
||||
assert_match {} [errorstat NOSCRIPT]
|
||||
catch {r evalsha NotValidShaSUM 0} e
|
||||
assert_match {NOSCRIPT*} $e
|
||||
assert_match {*count=1*} [errorstat NOSCRIPT]
|
||||
assert_match {*calls=1,*,rejected_calls=0,failed_calls=1} [cmdstat evalsha]
|
||||
assert_equal [s total_error_replies] 1
|
||||
r config resetstat
|
||||
assert_match {} [errorstat NOSCRIPT]
|
||||
}
|
||||
|
||||
test {errorstats: failed call NOGROUP error} {
|
||||
r config resetstat
|
||||
assert_match {} [errorstat NOGROUP]
|
||||
r del mystream
|
||||
r XADD mystream * f v
|
||||
catch {r XGROUP CREATECONSUMER mystream mygroup consumer} e
|
||||
assert_match {NOGROUP*} $e
|
||||
assert_match {*count=1*} [errorstat NOGROUP]
|
||||
assert_match {*calls=1,*,rejected_calls=0,failed_calls=1} [cmdstat xgroup]
|
||||
r config resetstat
|
||||
assert_match {} [errorstat NOGROUP]
|
||||
}
|
||||
|
||||
test {errorstats: rejected call unknown command} {
|
||||
r config resetstat
|
||||
assert_equal [s total_error_replies] 0
|
||||
assert_match {} [errorstat ERR]
|
||||
catch {r asdf} e
|
||||
assert_match {ERR unknown*} $e
|
||||
assert_match {*count=1*} [errorstat ERR]
|
||||
assert_equal [s total_error_replies] 1
|
||||
r config resetstat
|
||||
assert_match {} [errorstat ERR]
|
||||
}
|
||||
|
||||
test {errorstats: rejected call within MULTI/EXEC} {
|
||||
r config resetstat
|
||||
assert_equal [s total_error_replies] 0
|
||||
assert_match {} [errorstat ERR]
|
||||
r multi
|
||||
catch {r set} e
|
||||
assert_match {ERR wrong number of arguments*} $e
|
||||
catch {r exec} e
|
||||
assert_match {EXECABORT*} $e
|
||||
assert_match {*count=1*} [errorstat ERR]
|
||||
assert_equal [s total_error_replies] 1
|
||||
assert_match {*calls=0,*,rejected_calls=1,failed_calls=0} [cmdstat set]
|
||||
assert_match {*calls=1,*,rejected_calls=0,failed_calls=0} [cmdstat multi]
|
||||
assert_match {*calls=1,*,rejected_calls=0,failed_calls=0} [cmdstat exec]
|
||||
assert_equal [s total_error_replies] 1
|
||||
r config resetstat
|
||||
assert_match {} [errorstat ERR]
|
||||
}
|
||||
|
||||
test {errorstats: rejected call due to wrong arity} {
|
||||
r config resetstat
|
||||
assert_equal [s total_error_replies] 0
|
||||
assert_match {} [errorstat ERR]
|
||||
catch {r set k} e
|
||||
assert_match {ERR wrong number of arguments*} $e
|
||||
assert_match {*count=1*} [errorstat ERR]
|
||||
assert_match {*calls=0,*,rejected_calls=1,failed_calls=0} [cmdstat set]
|
||||
# ensure that after a rejected command, valid ones are counted properly
|
||||
r set k1 v1
|
||||
r set k2 v2
|
||||
assert_match {calls=2,*,rejected_calls=1,failed_calls=0} [cmdstat set]
|
||||
assert_equal [s total_error_replies] 1
|
||||
}
|
||||
|
||||
test {errorstats: rejected call by OOM error} {
|
||||
r config resetstat
|
||||
assert_equal [s total_error_replies] 0
|
||||
assert_match {} [errorstat OOM]
|
||||
r config set maxmemory 1
|
||||
catch {r set a b} e
|
||||
assert_match {OOM*} $e
|
||||
assert_match {*count=1*} [errorstat OOM]
|
||||
assert_match {*calls=0,*,rejected_calls=1,failed_calls=0} [cmdstat set]
|
||||
assert_equal [s total_error_replies] 1
|
||||
r config resetstat
|
||||
assert_match {} [errorstat OOM]
|
||||
}
|
||||
|
||||
test {errorstats: rejected call by authorization error} {
|
||||
r config resetstat
|
||||
assert_equal [s total_error_replies] 0
|
||||
assert_match {} [errorstat NOPERM]
|
||||
r ACL SETUSER alice on >p1pp0 ~cached:* +get +info +config
|
||||
r auth alice p1pp0
|
||||
catch {r set a b} e
|
||||
assert_match {NOPERM*} $e
|
||||
assert_match {*count=1*} [errorstat NOPERM]
|
||||
assert_match {*calls=0,*,rejected_calls=1,failed_calls=0} [cmdstat set]
|
||||
assert_equal [s total_error_replies] 1
|
||||
r config resetstat
|
||||
assert_match {} [errorstat NOPERM]
|
||||
}
|
||||
}
|
||||
|
||||
start_server {} {
|
||||
test {Unsafe command names are sanitized in INFO output} {
|
||||
catch {r host:} e
|
||||
set info [r info commandstats]
|
||||
assert_match {*cmdstat_host_:calls=1*} $info
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
proc cmdstat {cmd} {
|
||||
if {[regexp "\r\ncmdstat_$cmd:(.*?)\r\n" [r info commandstats] _ value]} {
|
||||
set _ $value
|
||||
}
|
||||
return [cmdrstat $cmd r]
|
||||
}
|
||||
|
||||
start_server {tags {"introspection"}} {
|
||||
|
||||
@@ -3,6 +3,16 @@ start_server {tags {"introspection"}} {
|
||||
r client list
|
||||
} {*addr=*:* fd=* age=* idle=* flags=N db=9 sub=0 psub=0 multi=-1 qbuf=26 qbuf-free=* argv-mem=* obl=0 oll=0 omem=0 tot-mem=* events=r cmd=client*}
|
||||
|
||||
test {CLIENT LIST with IDs} {
|
||||
set myid [r client id]
|
||||
set cl [split [r client list id $myid] "\r\n"]
|
||||
assert_match "id=$myid*" [lindex $cl 0]
|
||||
}
|
||||
|
||||
test {CLIENT INFO} {
|
||||
r client info
|
||||
} {*addr=*:* fd=* age=* idle=* flags=N db=9 sub=0 psub=0 multi=-1 qbuf=26 qbuf-free=* argv-mem=* obl=0 oll=0 omem=0 tot-mem=* events=r cmd=client*}
|
||||
|
||||
test {MONITOR can log executed commands} {
|
||||
set rd [redis_deferring_client]
|
||||
$rd monitor
|
||||
@@ -58,6 +68,19 @@ start_server {tags {"introspection"}} {
|
||||
}
|
||||
}
|
||||
|
||||
test {CONFIG save params special case handled properly} {
|
||||
# No "save" keyword - defaults should apply
|
||||
start_server {config "minimal.conf"} {
|
||||
assert_match [r config get save] {save {3600 1 300 100 60 10000}}
|
||||
}
|
||||
|
||||
# First "save" keyword overrides defaults
|
||||
start_server {config "minimal.conf" overrides {save {100 100}}} {
|
||||
# Defaults
|
||||
assert_match [r config get save] {save {100 100}}
|
||||
}
|
||||
}
|
||||
|
||||
test {CONFIG sanity} {
|
||||
# Do CONFIG GET, CONFIG SET and then CONFIG GET again
|
||||
# Skip immutable configs, one with no get, and other complicated configs
|
||||
@@ -78,20 +101,19 @@ start_server {tags {"introspection"}} {
|
||||
supervised
|
||||
syslog-facility
|
||||
databases
|
||||
port
|
||||
tls-port
|
||||
io-threads
|
||||
logfile
|
||||
unixsocketperm
|
||||
slaveof
|
||||
bind
|
||||
requirepass
|
||||
multi-master
|
||||
server_cpulist
|
||||
bio_cpulist
|
||||
aof_rewrite_cpulist
|
||||
bgsave_cpulist
|
||||
multi-master
|
||||
active-replica
|
||||
bind
|
||||
set-proc-title
|
||||
}
|
||||
|
||||
if {!$::tls} {
|
||||
@@ -102,12 +124,15 @@ start_server {tags {"introspection"}} {
|
||||
tls-session-caching
|
||||
tls-cert-file
|
||||
tls-key-file
|
||||
tls-client-cert-file
|
||||
tls-client-key-file
|
||||
tls-dh-params-file
|
||||
tls-ca-cert-file
|
||||
tls-ca-cert-dir
|
||||
tls-protocols
|
||||
tls-ciphers
|
||||
tls-ciphersuites
|
||||
tls-port
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,12 +175,12 @@ start_server {tags {"introspection"}} {
|
||||
# Rewrite entire configuration, restart and confirm the
|
||||
# server is able to parse it and start.
|
||||
assert_equal [r debug config-rewrite-force-all] "OK"
|
||||
restart_server 0 0
|
||||
restart_server 0 true false
|
||||
assert_equal [r ping] "PONG"
|
||||
|
||||
# Verify no changes were introduced
|
||||
dict for {k v} $configs {
|
||||
assert_equal $v [lindex [r config get $k] 1] $k
|
||||
assert_equal $v [lindex [r config get $k] 1]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+208
-1
@@ -169,6 +169,213 @@ start_server {tags {"keyspace"}} {
|
||||
format $res
|
||||
} {0}
|
||||
|
||||
test {COPY basic usage for string} {
|
||||
r set mykey foobar
|
||||
set res {}
|
||||
r copy mykey mynewkey
|
||||
lappend res [r get mynewkey]
|
||||
lappend res [r dbsize]
|
||||
r copy mykey mynewkey DB 10
|
||||
r select 10
|
||||
lappend res [r get mynewkey]
|
||||
lappend res [r dbsize]
|
||||
r select 9
|
||||
format $res
|
||||
} [list foobar 2 foobar 1]
|
||||
|
||||
test {COPY for string does not replace an existing key without REPLACE option} {
|
||||
r set mykey2 hello
|
||||
catch {r copy mykey2 mynewkey DB 10} e
|
||||
set e
|
||||
} {0}
|
||||
|
||||
test {COPY for string can replace an existing key with REPLACE option} {
|
||||
r copy mykey2 mynewkey DB 10 REPLACE
|
||||
r select 10
|
||||
r get mynewkey
|
||||
} {hello}
|
||||
|
||||
test {COPY for string ensures that copied data is independent of copying data} {
|
||||
r flushdb
|
||||
r select 9
|
||||
r set mykey foobar
|
||||
set res {}
|
||||
r copy mykey mynewkey DB 10
|
||||
r select 10
|
||||
lappend res [r get mynewkey]
|
||||
r set mynewkey hoge
|
||||
lappend res [r get mynewkey]
|
||||
r select 9
|
||||
lappend res [r get mykey]
|
||||
r select 10
|
||||
r flushdb
|
||||
r select 9
|
||||
format $res
|
||||
} [list foobar hoge foobar]
|
||||
|
||||
test {COPY for string does not copy data to no-integer DB} {
|
||||
r set mykey foobar
|
||||
catch {r copy mykey mynewkey DB notanumber} e
|
||||
set e
|
||||
} {ERR value is not an integer or out of range}
|
||||
|
||||
test {COPY can copy key expire metadata as well} {
|
||||
r set mykey foobar ex 100
|
||||
r copy mykey mynewkey REPLACE
|
||||
assert {[r ttl mynewkey] > 0 && [r ttl mynewkey] <= 100}
|
||||
assert {[r get mynewkey] eq "foobar"}
|
||||
}
|
||||
|
||||
test {COPY does not create an expire if it does not exist} {
|
||||
r set mykey foobar
|
||||
assert {[r ttl mykey] == -1}
|
||||
r copy mykey mynewkey REPLACE
|
||||
assert {[r ttl mynewkey] == -1}
|
||||
assert {[r get mynewkey] eq "foobar"}
|
||||
}
|
||||
|
||||
test {COPY basic usage for list} {
|
||||
r del mylist mynewlist
|
||||
r lpush mylist a b c d
|
||||
r copy mylist mynewlist
|
||||
set digest [r debug digest-value mylist]
|
||||
assert_equal $digest [r debug digest-value mynewlist]
|
||||
assert_equal 1 [r object refcount mylist]
|
||||
assert_equal 1 [r object refcount mynewlist]
|
||||
r del mylist
|
||||
assert_equal $digest [r debug digest-value mynewlist]
|
||||
}
|
||||
|
||||
test {COPY basic usage for intset set} {
|
||||
r del set1 newset1
|
||||
r sadd set1 1 2 3
|
||||
assert_encoding intset set1
|
||||
r copy set1 newset1
|
||||
set digest [r debug digest-value set1]
|
||||
assert_equal $digest [r debug digest-value newset1]
|
||||
assert_equal 1 [r object refcount set1]
|
||||
assert_equal 1 [r object refcount newset1]
|
||||
r del set1
|
||||
assert_equal $digest [r debug digest-value newset1]
|
||||
}
|
||||
|
||||
test {COPY basic usage for hashtable set} {
|
||||
r del set2 newset2
|
||||
r sadd set2 1 2 3 a
|
||||
assert_encoding hashtable set2
|
||||
r copy set2 newset2
|
||||
set digest [r debug digest-value set2]
|
||||
assert_equal $digest [r debug digest-value newset2]
|
||||
assert_equal 1 [r object refcount set2]
|
||||
assert_equal 1 [r object refcount newset2]
|
||||
r del set2
|
||||
assert_equal $digest [r debug digest-value newset2]
|
||||
}
|
||||
|
||||
test {COPY basic usage for ziplist sorted set} {
|
||||
r del zset1 newzset1
|
||||
r zadd zset1 123 foobar
|
||||
assert_encoding ziplist zset1
|
||||
r copy zset1 newzset1
|
||||
set digest [r debug digest-value zset1]
|
||||
assert_equal $digest [r debug digest-value newzset1]
|
||||
assert_equal 1 [r object refcount zset1]
|
||||
assert_equal 1 [r object refcount newzset1]
|
||||
r del zset1
|
||||
assert_equal $digest [r debug digest-value newzset1]
|
||||
}
|
||||
|
||||
test {COPY basic usage for skiplist sorted set} {
|
||||
r del zset2 newzset2
|
||||
set original_max [lindex [r config get zset-max-ziplist-entries] 1]
|
||||
r config set zset-max-ziplist-entries 0
|
||||
for {set j 0} {$j < 130} {incr j} {
|
||||
r zadd zset2 [randomInt 50] ele-[randomInt 10]
|
||||
}
|
||||
assert_encoding skiplist zset2
|
||||
r copy zset2 newzset2
|
||||
set digest [r debug digest-value zset2]
|
||||
assert_equal $digest [r debug digest-value newzset2]
|
||||
assert_equal 1 [r object refcount zset2]
|
||||
assert_equal 1 [r object refcount newzset2]
|
||||
r del zset2
|
||||
assert_equal $digest [r debug digest-value newzset2]
|
||||
r config set zset-max-ziplist-entries $original_max
|
||||
}
|
||||
|
||||
test {COPY basic usage for ziplist hash} {
|
||||
r del hash1 newhash1
|
||||
r hset hash1 tmp 17179869184
|
||||
assert_encoding ziplist hash1
|
||||
r copy hash1 newhash1
|
||||
set digest [r debug digest-value hash1]
|
||||
assert_equal $digest [r debug digest-value newhash1]
|
||||
assert_equal 1 [r object refcount hash1]
|
||||
assert_equal 1 [r object refcount newhash1]
|
||||
r del hash1
|
||||
assert_equal $digest [r debug digest-value newhash1]
|
||||
}
|
||||
|
||||
test {COPY basic usage for hashtable hash} {
|
||||
r del hash2 newhash2
|
||||
set original_max [lindex [r config get hash-max-ziplist-entries] 1]
|
||||
r config set hash-max-ziplist-entries 0
|
||||
for {set i 0} {$i < 64} {incr i} {
|
||||
r hset hash2 [randomValue] [randomValue]
|
||||
}
|
||||
assert_encoding hashtable hash2
|
||||
r copy hash2 newhash2
|
||||
set digest [r debug digest-value hash2]
|
||||
assert_equal $digest [r debug digest-value newhash2]
|
||||
assert_equal 1 [r object refcount hash2]
|
||||
assert_equal 1 [r object refcount newhash2]
|
||||
r del hash2
|
||||
assert_equal $digest [r debug digest-value newhash2]
|
||||
r config set hash-max-ziplist-entries $original_max
|
||||
}
|
||||
|
||||
test {COPY basic usage for stream} {
|
||||
r del mystream mynewstream
|
||||
for {set i 0} {$i < 1000} {incr i} {
|
||||
r XADD mystream * item 2 value b
|
||||
}
|
||||
r copy mystream mynewstream
|
||||
set digest [r debug digest-value mystream]
|
||||
assert_equal $digest [r debug digest-value mynewstream]
|
||||
assert_equal 1 [r object refcount mystream]
|
||||
assert_equal 1 [r object refcount mynewstream]
|
||||
r del mystream
|
||||
assert_equal $digest [r debug digest-value mynewstream]
|
||||
}
|
||||
|
||||
test {COPY basic usage for stream-cgroups} {
|
||||
r del x
|
||||
r XADD x 100 a 1
|
||||
set id [r XADD x 101 b 1]
|
||||
r XADD x 102 c 1
|
||||
r XADD x 103 e 1
|
||||
r XADD x 104 f 1
|
||||
r XADD x 105 g 1
|
||||
r XGROUP CREATE x g1 0
|
||||
r XGROUP CREATE x g2 0
|
||||
r XREADGROUP GROUP g1 Alice COUNT 1 STREAMS x >
|
||||
r XREADGROUP GROUP g1 Bob COUNT 1 STREAMS x >
|
||||
r XREADGROUP GROUP g1 Bob NOACK COUNT 1 STREAMS x >
|
||||
r XREADGROUP GROUP g2 Charlie COUNT 4 STREAMS x >
|
||||
r XGROUP SETID x g1 $id
|
||||
r XREADGROUP GROUP g1 Dave COUNT 3 STREAMS x >
|
||||
r XDEL x 103
|
||||
|
||||
r copy x newx
|
||||
set info [r xinfo stream x full]
|
||||
assert_equal $info [r xinfo stream newx full]
|
||||
assert_equal 1 [r object refcount x]
|
||||
assert_equal 1 [r object refcount newx]
|
||||
r del x
|
||||
assert_equal $info [r xinfo stream newx full]
|
||||
r flushdb
|
||||
}
|
||||
|
||||
test {MOVE basic usage} {
|
||||
r set mykey foobar
|
||||
r move mykey 10
|
||||
@@ -191,7 +398,7 @@ start_server {tags {"keyspace"}} {
|
||||
r set mykey hello
|
||||
catch {r move mykey notanumber} e
|
||||
set e
|
||||
} {*ERR*index out of range}
|
||||
} {ERR value is not an integer or out of range}
|
||||
|
||||
test {MOVE can move key expire metadata as well} {
|
||||
r select 10
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
start_server {tags {"limits"} overrides {maxclients 10}} {
|
||||
start_server {tags {"limits network"} overrides {maxclients 10}} {
|
||||
if {$::tls} {
|
||||
set expected_code "*I/O error*"
|
||||
} else {
|
||||
|
||||
@@ -246,10 +246,31 @@ test_slave_buffers {slave buffer are counted correctly} 1000000 10 0 1
|
||||
# test again with fewer (and bigger) commands without pipeline, but with eviction
|
||||
test_slave_buffers "replica buffer don't induce eviction" 100000 100 1 0
|
||||
|
||||
start_server {tags {"maxmemory"} overrides {server-threads 1}} {
|
||||
test {Don't rehash if used memory exceeds maxmemory after rehash} {
|
||||
r config set maxmemory 0
|
||||
r config set maxmemory-policy allkeys-random
|
||||
|
||||
# Next rehash size is 8192, that will eat 64k memory
|
||||
populate 4096 "" 1
|
||||
|
||||
set used [s used_memory]
|
||||
set limit [expr {$used + 10*1024}]
|
||||
r config set maxmemory $limit
|
||||
r set k1 v1
|
||||
# Next writing command will trigger evicting some keys if last
|
||||
# command trigger DB dict rehash
|
||||
r set k2 v2
|
||||
# There must be 4098 keys because redis doesn't evict keys.
|
||||
r dbsize
|
||||
} {4098}
|
||||
}
|
||||
|
||||
start_server {tags {"maxmemory"} overrides {server-threads 1}} {
|
||||
test {client tracking don't cause eviction feedback loop} {
|
||||
r config set maxmemory 0
|
||||
r config set maxmemory-policy allkeys-lru
|
||||
r config set maxmemory-eviction-tenacity 100
|
||||
|
||||
# 10 clients listening on tracking messages
|
||||
set clients {}
|
||||
@@ -308,4 +329,4 @@ start_server {tags {"maxmemory"} overrides {server-threads 1}} {
|
||||
if {$::verbose} { puts "evicted: $evicted" }
|
||||
}
|
||||
}
|
||||
}; #run_solo
|
||||
}
|
||||
+55
-105
@@ -37,10 +37,9 @@ start_server {tags {"memefficiency"}} {
|
||||
}
|
||||
|
||||
run_solo {defrag} {
|
||||
start_server {tags {"defrag"} overrides {server-threads 1} } {
|
||||
if {[string match {*jemalloc*} [s mem_allocator]]} {
|
||||
start_server {tags {"defrag"} overrides {appendonly yes auto-aof-rewrite-percentage 0 save "" server-threads 1}} {
|
||||
if {[string match {*jemalloc*} [s mem_allocator]] && [r debug mallctl arenas.page] <= 8192} {
|
||||
test "Active defrag" {
|
||||
r config set save "" ;# prevent bgsave from interfereing with save below
|
||||
r config set hz 100
|
||||
r config set activedefrag no
|
||||
r config set active-defrag-threshold-lower 5
|
||||
@@ -49,9 +48,9 @@ start_server {tags {"defrag"} overrides {server-threads 1} } {
|
||||
r config set active-defrag-ignore-bytes 2mb
|
||||
r config set maxmemory 100mb
|
||||
r config set maxmemory-policy allkeys-lru
|
||||
r debug populate 700000 asdf1 150
|
||||
r debug populate 170000 asdf2 300
|
||||
r ping ;# trigger eviction following the previous population
|
||||
|
||||
populate 700000 asdf1 150
|
||||
populate 170000 asdf2 300
|
||||
after 120 ;# serverCron only updates the info once in 100ms
|
||||
set frag [s allocator_frag_ratio]
|
||||
if {$::verbose} {
|
||||
@@ -64,7 +63,7 @@ start_server {tags {"defrag"} overrides {server-threads 1} } {
|
||||
r config set maxmemory 110mb ;# prevent further eviction (not to fail the digest test)
|
||||
set digest [r debug digest]
|
||||
catch {r config set activedefrag yes} e
|
||||
if {![string match {DISABLED*} $e]} {
|
||||
if {[r config get activedefrag] eq "activedefrag yes"} {
|
||||
# Wait for the active defrag to start working (decision once a
|
||||
# second).
|
||||
wait_for_condition 50 100 {
|
||||
@@ -109,19 +108,59 @@ start_server {tags {"defrag"} overrides {server-threads 1} } {
|
||||
if {!$::no_latency} {
|
||||
assert {$max_latency <= 30}
|
||||
}
|
||||
} else {
|
||||
set _ ""
|
||||
}
|
||||
# verify the data isn't corrupted or changed
|
||||
set newdigest [r debug digest]
|
||||
assert {$digest eq $newdigest}
|
||||
r save ;# saving an rdb iterates over all the data / pointers
|
||||
} {OK}
|
||||
|
||||
# if defrag is supported, test AOF loading too
|
||||
if {[r config get activedefrag] eq "activedefrag yes"} {
|
||||
# reset stats and load the AOF file
|
||||
r config resetstat
|
||||
r config set key-load-delay -50 ;# sleep on average 1/50 usec
|
||||
r debug loadaof
|
||||
r config set activedefrag no
|
||||
# measure hits and misses right after aof loading
|
||||
set misses [s active_defrag_misses]
|
||||
set hits [s active_defrag_hits]
|
||||
|
||||
after 120 ;# serverCron only updates the info once in 100ms
|
||||
set frag [s allocator_frag_ratio]
|
||||
set max_latency 0
|
||||
foreach event [r latency latest] {
|
||||
lassign $event eventname time latency max
|
||||
if {$eventname == "loading-cron"} {
|
||||
set max_latency $max
|
||||
}
|
||||
}
|
||||
if {$::verbose} {
|
||||
puts "AOF loading:"
|
||||
puts "frag $frag"
|
||||
puts "hits: $hits"
|
||||
puts "misses: $misses"
|
||||
puts "max latency $max_latency"
|
||||
puts [r latency latest]
|
||||
puts [r latency history loading-cron]
|
||||
}
|
||||
# make sure we had defrag hits during AOF loading
|
||||
assert {$hits > 100000}
|
||||
# make sure the defragger did enough work to keep the fragmentation low during loading.
|
||||
# we cannot check that it went all the way down, since we don't wait for full defrag cycle to complete.
|
||||
assert {$frag < 1.4}
|
||||
# since the AOF contains simple (fast) SET commands (and the cron during loading runs every 1000 commands),
|
||||
# it'll still not block the loading for long periods of time.
|
||||
if {!$::no_latency} {
|
||||
assert {$max_latency <= 30}
|
||||
}
|
||||
}
|
||||
}
|
||||
r config set appendonly no
|
||||
r config set key-load-delay 0
|
||||
|
||||
test "Active defrag big keys" {
|
||||
r flushdb
|
||||
r config resetstat
|
||||
r config set save "" ;# prevent bgsave from interfereing with save below
|
||||
r config set hz 100
|
||||
r config set activedefrag no
|
||||
r config set active-defrag-max-scan-fields 1000
|
||||
@@ -197,7 +236,7 @@ start_server {tags {"defrag"} overrides {server-threads 1} } {
|
||||
|
||||
set digest [r debug digest]
|
||||
catch {r config set activedefrag yes} e
|
||||
if {![string match {DISABLED*} $e]} {
|
||||
if {[r config get activedefrag] eq "activedefrag yes"} {
|
||||
# wait for the active defrag to start working (decision once a second)
|
||||
wait_for_condition 50 100 {
|
||||
[s active_defrag_running] ne 0
|
||||
@@ -251,7 +290,6 @@ start_server {tags {"defrag"} overrides {server-threads 1} } {
|
||||
test "Active defrag big list" {
|
||||
r flushdb
|
||||
r config resetstat
|
||||
r config set save "" ;# prevent bgsave from interfereing with save below
|
||||
r config set hz 100
|
||||
r config set activedefrag no
|
||||
r config set active-defrag-max-scan-fields 1000
|
||||
@@ -294,7 +332,7 @@ start_server {tags {"defrag"} overrides {server-threads 1} } {
|
||||
|
||||
set digest [r debug digest]
|
||||
catch {r config set activedefrag yes} e
|
||||
if {![string match {DISABLED*} $e]} {
|
||||
if {[r config get activedefrag] eq "activedefrag yes"} {
|
||||
# wait for the active defrag to start working (decision once a second)
|
||||
wait_for_condition 50 100 {
|
||||
[s active_defrag_running] ne 0
|
||||
@@ -357,10 +395,9 @@ start_server {tags {"defrag"} overrides {server-threads 1} } {
|
||||
# if the current slab is lower in utilization the defragger would have ended up in stagnation,
|
||||
# keept running and not move any allocation.
|
||||
# this test is more consistent on a fresh server with no history
|
||||
start_server {tags {"defrag"} overrides {server-threads 1}} {
|
||||
start_server {tags {"defrag"} overrides {save ""}} {
|
||||
r flushdb
|
||||
r config resetstat
|
||||
r config set save "" ;# prevent bgsave from interfereing with save below
|
||||
r config set hz 100
|
||||
r config set activedefrag no
|
||||
r config set active-defrag-max-scan-fields 1000
|
||||
@@ -415,7 +452,7 @@ start_server {tags {"defrag"} overrides {server-threads 1} } {
|
||||
|
||||
set digest [r debug digest]
|
||||
catch {r config set activedefrag yes} e
|
||||
if {![string match {DISABLED*} $e]} {
|
||||
if {[r config get activedefrag] eq "activedefrag yes"} {
|
||||
# wait for the active defrag to start working (decision once a second)
|
||||
wait_for_condition 50 100 {
|
||||
[s active_defrag_running] ne 0
|
||||
@@ -456,91 +493,4 @@ start_server {tags {"defrag"} overrides {server-threads 1} } {
|
||||
}
|
||||
}
|
||||
}
|
||||
start_server {tags {"defrag"} overrides {server-threads 1 active-replica yes} } { ;#test defrag with active-replica enabled
|
||||
if {[string match {*jemalloc*} [s mem_allocator]]} {
|
||||
|
||||
test "Active defrag with active replica" {
|
||||
r config set save "" ;# prevent bgsave from interfereing with save below
|
||||
r config set hz 100
|
||||
r config set activedefrag no
|
||||
r config set active-defrag-threshold-lower 5
|
||||
r config set active-defrag-cycle-min 65
|
||||
r config set active-defrag-cycle-max 75
|
||||
r config set active-defrag-ignore-bytes 2mb
|
||||
r config set maxmemory 100mb
|
||||
r config set maxmemory-policy allkeys-lru
|
||||
r debug populate 700000 asdf1 150
|
||||
r debug populate 170000 asdf2 300
|
||||
r ping ;# trigger eviction following the previous population
|
||||
after 120 ;# serverCron only updates the info once in 100ms
|
||||
set frag [s allocator_frag_ratio]
|
||||
if {$::verbose} {
|
||||
puts "frag $frag"
|
||||
}
|
||||
assert {$frag >= 1.4}
|
||||
|
||||
r config set latency-monitor-threshold 5
|
||||
r latency reset
|
||||
r config set maxmemory 110mb ;# prevent further eviction (not to fail the digest test)
|
||||
set digest [r debug digest]
|
||||
catch {r config set activedefrag yes} e
|
||||
if {![string match {DISABLED*} $e]} {
|
||||
# Wait for the active defrag to start working (decision once a
|
||||
# second).
|
||||
wait_for_condition 50 100 {
|
||||
[s active_defrag_running] ne 0
|
||||
} else {
|
||||
fail "defrag not started."
|
||||
}
|
||||
|
||||
# Wait for the active defrag to stop working.
|
||||
catch {
|
||||
wait_for_condition 150 100 {
|
||||
[s active_defrag_running] eq 0
|
||||
} else {
|
||||
after 120 ;# serverCron only updates the info once in 100ms
|
||||
puts [r info memory]
|
||||
puts [r memory malloc-stats]
|
||||
fail "defrag didn't stop."
|
||||
}
|
||||
} e
|
||||
if {[string match *error* $e]} {
|
||||
after 120
|
||||
fail "defrag accessed invalid address."
|
||||
}
|
||||
|
||||
# Test the the fragmentation is lower.
|
||||
after 120 ;# serverCron only updates the info once in 100ms
|
||||
set frag [s allocator_frag_ratio]
|
||||
set max_latency 0
|
||||
foreach event [r latency latest] {
|
||||
lassign $event eventname time latency max
|
||||
if {$eventname == "active-defrag-cycle"} {
|
||||
set max_latency $max
|
||||
}
|
||||
}
|
||||
if {$::verbose} {
|
||||
puts "frag $frag"
|
||||
set misses [s active_defrag_misses]
|
||||
set hits [s active_defrag_hits]
|
||||
puts "hits: $hits"
|
||||
puts "misses: $misses"
|
||||
puts "max latency $max_latency"
|
||||
puts [r latency latest]
|
||||
puts [r latency history active-defrag-cycle]
|
||||
}
|
||||
assert {$frag < 1.1}
|
||||
# due to high fragmentation, 100hz, and active-defrag-cycle-max set to 75,
|
||||
# we expect max latency to be not much higher than 7.5ms but due to rare slowness threshold is set higher
|
||||
assert {$max_latency <= 30}
|
||||
} else {
|
||||
set _ ""
|
||||
}
|
||||
# verify the data isn't corrupted or changed
|
||||
set newdigest [r debug digest]
|
||||
assert {$digest eq $newdigest}
|
||||
r save ;# saving an rdb iterates over all the data / pointers
|
||||
} {OK}
|
||||
}
|
||||
}
|
||||
} ;# run solo
|
||||
} ;# run_solo
|
||||
@@ -15,6 +15,69 @@ start_server {tags {"modules"}} {
|
||||
assert_equal {{Blocked client is not supported inside multi}} [r exec]
|
||||
}
|
||||
|
||||
test {Locked GIL acquisition from RM_Call} {
|
||||
assert_equal {Blocked client is not allowed} [r do_rm_call acquire_gil]
|
||||
}
|
||||
|
||||
test {Blocking command are not block the client on RM_Call} {
|
||||
r lpush l test
|
||||
assert_equal [r do_rm_call blpop l 0] {l test}
|
||||
|
||||
r lpush l test
|
||||
assert_equal [r do_rm_call brpop l 0] {l test}
|
||||
|
||||
r lpush l1 test
|
||||
assert_equal [r do_rm_call brpoplpush l1 l2 0] {test}
|
||||
assert_equal [r do_rm_call brpop l2 0] {l2 test}
|
||||
|
||||
r lpush l1 test
|
||||
assert_equal [r do_rm_call blmove l1 l2 LEFT LEFT 0] {test}
|
||||
assert_equal [r do_rm_call brpop l2 0] {l2 test}
|
||||
|
||||
r ZADD zset1 0 a 1 b 2 c
|
||||
assert_equal [r do_rm_call bzpopmin zset1 0] {zset1 a 0}
|
||||
assert_equal [r do_rm_call bzpopmax zset1 0] {zset1 c 2}
|
||||
|
||||
r xgroup create s g $ MKSTREAM
|
||||
r xadd s * foo bar
|
||||
assert {[r do_rm_call xread BLOCK 0 STREAMS s 0-0] ne {}}
|
||||
assert {[r do_rm_call xreadgroup group g c BLOCK 0 STREAMS s >] ne {}}
|
||||
|
||||
assert {[r do_rm_call blpop empty_list 0] eq {}}
|
||||
assert {[r do_rm_call brpop empty_list 0] eq {}}
|
||||
assert {[r do_rm_call brpoplpush empty_list1 empty_list2 0] eq {}}
|
||||
assert {[r do_rm_call blmove empty_list1 empty_list2 LEFT LEFT 0] eq {}}
|
||||
|
||||
assert {[r do_rm_call bzpopmin empty_zset 0] eq {}}
|
||||
assert {[r do_rm_call bzpopmax empty_zset 0] eq {}}
|
||||
|
||||
r xgroup create empty_stream g $ MKSTREAM
|
||||
assert {[r do_rm_call xread BLOCK 0 STREAMS empty_stream $] eq {}}
|
||||
assert {[r do_rm_call xreadgroup group g c BLOCK 0 STREAMS empty_stream >] eq {}}
|
||||
|
||||
}
|
||||
|
||||
test {Monitor disallow inside RM_Call} {
|
||||
set e {}
|
||||
catch {
|
||||
r do_rm_call monitor
|
||||
} e
|
||||
set e
|
||||
} {*ERR*DENY BLOCKING*}
|
||||
|
||||
test {subscribe disallow inside RM_Call} {
|
||||
set e {}
|
||||
catch {
|
||||
r do_rm_call subscribe x
|
||||
} e
|
||||
set e
|
||||
} {*ERR*DENY BLOCKING*}
|
||||
|
||||
test {RM_Call from blocked client} {
|
||||
r hset hash foo bar
|
||||
r do_bg_rm_call hgetall hash
|
||||
} {foo bar}
|
||||
|
||||
test {blocked client reaches client output buffer limit} {
|
||||
r hset hash big [string repeat x 50000]
|
||||
r hset hash bada [string repeat x 50000]
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
set testmodule [file normalize tests/modules/blockonbackground.so]
|
||||
|
||||
source tests/support/util.tcl
|
||||
|
||||
start_server {tags {"modules"}} {
|
||||
r module load $testmodule
|
||||
|
||||
test { blocked clients time tracking - check blocked command that uses RedisModule_BlockedClientMeasureTimeStart() is tracking background time} {
|
||||
r slowlog reset
|
||||
r config set slowlog-log-slower-than 200000
|
||||
if {!$::no_latency} {
|
||||
assert_equal [r slowlog len] 0
|
||||
}
|
||||
r block.debug 0 10000
|
||||
if {!$::no_latency} {
|
||||
assert_equal [r slowlog len] 0
|
||||
}
|
||||
r config resetstat
|
||||
r block.debug 200 10000
|
||||
if {!$::no_latency} {
|
||||
assert_equal [r slowlog len] 1
|
||||
}
|
||||
|
||||
set cmdstatline [cmdrstat block.debug r]
|
||||
|
||||
regexp "calls=1,usec=(.*?),usec_per_call=(.*?),rejected_calls=0,failed_calls=0" $cmdstatline usec usec_per_call
|
||||
assert {$usec >= 100000}
|
||||
assert {$usec_per_call >= 100000}
|
||||
}
|
||||
|
||||
test { blocked clients time tracking - check blocked command that uses RedisModule_BlockedClientMeasureTimeStart() is tracking background time even in timeout } {
|
||||
r slowlog reset
|
||||
r config set slowlog-log-slower-than 200000
|
||||
if {!$::no_latency} {
|
||||
assert_equal [r slowlog len] 0
|
||||
}
|
||||
r block.debug 0 20000
|
||||
if {!$::no_latency} {
|
||||
assert_equal [r slowlog len] 0
|
||||
}
|
||||
r config resetstat
|
||||
r block.debug 20000 500
|
||||
if {!$::no_latency} {
|
||||
assert_equal [r slowlog len] 1
|
||||
}
|
||||
|
||||
set cmdstatline [cmdrstat block.debug r]
|
||||
|
||||
regexp "calls=1,usec=(.*?),usec_per_call=(.*?),rejected_calls=0,failed_calls=0" $cmdstatline usec usec_per_call
|
||||
assert {$usec >= 250000}
|
||||
assert {$usec_per_call >= 250000}
|
||||
}
|
||||
|
||||
test { blocked clients time tracking - check blocked command with multiple calls RedisModule_BlockedClientMeasureTimeStart() is tracking the total background time } {
|
||||
r slowlog reset
|
||||
r config set slowlog-log-slower-than 200000
|
||||
if {!$::no_latency} {
|
||||
assert_equal [r slowlog len] 0
|
||||
}
|
||||
r block.double_debug 0
|
||||
if {!$::no_latency} {
|
||||
assert_equal [r slowlog len] 0
|
||||
}
|
||||
r config resetstat
|
||||
r block.double_debug 100
|
||||
if {!$::no_latency} {
|
||||
assert_equal [r slowlog len] 1
|
||||
}
|
||||
set cmdstatline [cmdrstat block.double_debug r]
|
||||
|
||||
regexp "calls=1,usec=(.*?),usec_per_call=(.*?),rejected_calls=0,failed_calls=0" $cmdstatline usec usec_per_call
|
||||
assert {$usec >= 60000}
|
||||
assert {$usec_per_call >= 60000}
|
||||
}
|
||||
|
||||
test { blocked clients time tracking - check blocked command without calling RedisModule_BlockedClientMeasureTimeStart() is not reporting background time } {
|
||||
r slowlog reset
|
||||
r config set slowlog-log-slower-than 200000
|
||||
if {!$::no_latency} {
|
||||
assert_equal [r slowlog len] 0
|
||||
}
|
||||
r block.debug_no_track 200 1000
|
||||
# ensure slowlog is still empty
|
||||
if {!$::no_latency} {
|
||||
assert_equal [r slowlog len] 0
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -168,7 +168,7 @@ start_server {tags {"modules"}} {
|
||||
assert_error "*unblocked*" {$rd read}
|
||||
}
|
||||
|
||||
test {Module client blocked on keys does not wake up on wrong type} {
|
||||
test {Module client re-blocked on keys after woke up on wrong type} {
|
||||
r del k
|
||||
set rd [redis_deferring_client]
|
||||
$rd fsl.bpop k 0
|
||||
@@ -184,5 +184,56 @@ start_server {tags {"modules"}} {
|
||||
r del k
|
||||
r fsl.push k 34
|
||||
assert_equal {34} [$rd read]
|
||||
assert_equal {1} [r get fsl_wrong_type] ;# first lpush caused one wrong-type wake-up
|
||||
}
|
||||
|
||||
test {Module client blocked on keys woken up by LPUSH} {
|
||||
r del k
|
||||
set rd [redis_deferring_client]
|
||||
$rd blockonkeys.popall k
|
||||
# wait until client is actually blocked
|
||||
wait_for_condition 50 100 {
|
||||
[s 0 blocked_clients] eq {1}
|
||||
} else {
|
||||
fail "Client is not blocked"
|
||||
}
|
||||
r lpush k 42 squirrel banana
|
||||
assert_equal {banana squirrel 42} [$rd read]
|
||||
$rd close
|
||||
}
|
||||
|
||||
test {Module client unblocks BLPOP} {
|
||||
r del k
|
||||
set rd [redis_deferring_client]
|
||||
$rd blpop k 3
|
||||
# wait until client is actually blocked
|
||||
wait_for_condition 50 100 {
|
||||
[s 0 blocked_clients] eq {1}
|
||||
} else {
|
||||
fail "Client is not blocked"
|
||||
}
|
||||
r blockonkeys.lpush k 42
|
||||
assert_equal {k 42} [$rd read]
|
||||
$rd close
|
||||
}
|
||||
|
||||
test {Module unblocks module blocked on non-empty list} {
|
||||
r del k
|
||||
r lpush k aa
|
||||
# Module client blocks to pop 5 elements from list
|
||||
set rd [redis_deferring_client]
|
||||
$rd blockonkeys.blpopn k 5
|
||||
# Wait until client is actually blocked
|
||||
wait_for_condition 50 100 {
|
||||
[s 0 blocked_clients] eq {1}
|
||||
} else {
|
||||
fail "Client is not blocked"
|
||||
}
|
||||
# Check that RM_SignalKeyAsReady() can wake up BLPOPN
|
||||
r blockonkeys.lpush_unblock k bb cc ;# Not enough elements for BLPOPN
|
||||
r lpush k dd ee ff ;# Doesn't unblock module
|
||||
r blockonkeys.lpush_unblock k gg ;# Unblocks module
|
||||
assert_equal {gg ff ee dd cc} [$rd read]
|
||||
$rd close
|
||||
}
|
||||
}
|
||||
@@ -41,4 +41,18 @@ start_server {tags {"modules"}} {
|
||||
catch {r datatype.swap key-a key-b} e
|
||||
set e
|
||||
} {*ERR*}
|
||||
|
||||
test {DataType: Copy command works for modules} {
|
||||
# Test failed copies
|
||||
r datatype.set answer-to-universe 42 AAA
|
||||
catch {r copy answer-to-universe answer2} e
|
||||
assert_match {*module key failed to copy*} $e
|
||||
|
||||
# Our module's data type copy function copies the int value as-is
|
||||
# but appends /<from-key>/<to-key> to the string value so we can
|
||||
# track passed arguments.
|
||||
r datatype.set sourcekey 1234 AAA
|
||||
r copy sourcekey targetkey
|
||||
r datatype.get targetkey
|
||||
} {1234 AAA/sourcekey/targetkey}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
set testmodule [file normalize tests/modules/defragtest.so]
|
||||
|
||||
start_server {tags {"modules"} overrides {{save ""}}} {
|
||||
r module load $testmodule 10000
|
||||
r config set hz 100
|
||||
r config set active-defrag-ignore-bytes 1
|
||||
r config set active-defrag-threshold-lower 0
|
||||
r config set active-defrag-cycle-min 99
|
||||
|
||||
# try to enable active defrag, it will fail if redis was compiled without it
|
||||
catch {r config set activedefrag yes} e
|
||||
if {[r config get activedefrag] eq "activedefrag yes"} {
|
||||
|
||||
test {Module defrag: simple key defrag works} {
|
||||
r frag.create key1 1 1000 0
|
||||
|
||||
after 2000
|
||||
set info [r info defragtest_stats]
|
||||
assert {[getInfoProperty $info defragtest_datatype_attempts] > 0}
|
||||
assert_equal 0 [getInfoProperty $info defragtest_datatype_resumes]
|
||||
}
|
||||
|
||||
test {Module defrag: late defrag with cursor works} {
|
||||
r flushdb
|
||||
r frag.resetstats
|
||||
|
||||
# key can only be defragged in no less than 10 iterations
|
||||
# due to maxstep
|
||||
r frag.create key2 10000 100 1000
|
||||
|
||||
after 2000
|
||||
set info [r info defragtest_stats]
|
||||
assert {[getInfoProperty $info defragtest_datatype_resumes] > 10}
|
||||
assert_equal 0 [getInfoProperty $info defragtest_datatype_wrong_cursor]
|
||||
}
|
||||
|
||||
test {Module defrag: global defrag works} {
|
||||
r flushdb
|
||||
r frag.resetstats
|
||||
|
||||
after 2000
|
||||
set info [r info defragtest_stats]
|
||||
assert {[getInfoProperty $info defragtest_global_attempts] > 0}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
set testmodule [file normalize tests/modules/hash.so]
|
||||
|
||||
start_server {tags {"modules"}} {
|
||||
r module load $testmodule
|
||||
|
||||
test {Module hash set} {
|
||||
r set k mystring
|
||||
assert_error "WRONGTYPE*" {r hash.set k "" hello world}
|
||||
r del k
|
||||
# "" = count updates and deletes of existing fields only
|
||||
assert_equal 0 [r hash.set k "" squirrel yes]
|
||||
# "a" = COUNT_ALL = count inserted, modified and deleted fields
|
||||
assert_equal 2 [r hash.set k "a" banana no sushi whynot]
|
||||
# "n" = NX = only add fields not already existing in the hash
|
||||
# "x" = XX = only replace the value for existing fields
|
||||
assert_equal 0 [r hash.set k "n" squirrel hoho what nothing]
|
||||
assert_equal 1 [r hash.set k "na" squirrel hoho something nice]
|
||||
assert_equal 0 [r hash.set k "xa" new stuff not inserted]
|
||||
assert_equal 1 [r hash.set k "x" squirrel ofcourse]
|
||||
assert_equal 1 [r hash.set k "" sushi :delete: none :delete:]
|
||||
r hgetall k
|
||||
} {squirrel ofcourse banana no what nothing something nice}
|
||||
}
|
||||
@@ -85,5 +85,10 @@ start_server {tags {"modules"}} {
|
||||
set keys [scan [regexp -inline {keys\=([\d]*)} $keyspace] keys=%d]
|
||||
} {3}
|
||||
|
||||
test {module info unsafe fields} {
|
||||
set info [r info infotest_unsafe]
|
||||
assert_match {*infotest_unsafe_field:value=1*} $info
|
||||
}
|
||||
|
||||
# TODO: test crash report.
|
||||
}
|
||||
@@ -18,5 +18,54 @@ tags "modules" {
|
||||
assert_equal {1 t} [r keyspace.is_key_loaded t]
|
||||
assert_equal {1 s} [r keyspace.is_key_loaded s]
|
||||
}
|
||||
|
||||
test {Nested multi due to RM_Call} {
|
||||
r del multi
|
||||
r del lua
|
||||
|
||||
r set x 1
|
||||
r set x_copy 1
|
||||
r keyspace.del_key_copy x
|
||||
r keyspace.incr_case1 x
|
||||
r keyspace.incr_case2 x
|
||||
r keyspace.incr_case3 x
|
||||
assert_equal {} [r get multi]
|
||||
assert_equal {} [r get lua]
|
||||
r get x
|
||||
} {3}
|
||||
|
||||
test {Nested multi due to RM_Call, with client MULTI} {
|
||||
r del multi
|
||||
r del lua
|
||||
|
||||
r set x 1
|
||||
r set x_copy 1
|
||||
r multi
|
||||
r keyspace.del_key_copy x
|
||||
r keyspace.incr_case1 x
|
||||
r keyspace.incr_case2 x
|
||||
r keyspace.incr_case3 x
|
||||
r exec
|
||||
assert_equal {1} [r get multi]
|
||||
assert_equal {} [r get lua]
|
||||
r get x
|
||||
} {3}
|
||||
|
||||
test {Nested multi due to RM_Call, with EVAL} {
|
||||
r del multi
|
||||
r del lua
|
||||
|
||||
r set x 1
|
||||
r set x_copy 1
|
||||
r eval {
|
||||
redis.pcall('keyspace.del_key_copy', KEYS[1])
|
||||
redis.pcall('keyspace.incr_case1', KEYS[1])
|
||||
redis.pcall('keyspace.incr_case2', KEYS[1])
|
||||
redis.pcall('keyspace.incr_case3', KEYS[1])
|
||||
} 1 x
|
||||
assert_equal {} [r get multi]
|
||||
assert_equal {1} [r get lua]
|
||||
r get x
|
||||
} {3}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,11 @@ start_server {tags {"modules"}} {
|
||||
assert { [string match "*cmdstat_module*" $info] }
|
||||
}
|
||||
|
||||
test {test RM_Call recursive} {
|
||||
set info [r test.call_generic test.call_generic info commandstats]
|
||||
assert { [string match "*cmdstat_module*" $info] }
|
||||
}
|
||||
|
||||
test {test redis version} {
|
||||
set version [s redis_version]
|
||||
assert_equal $version [r test.redisversion]
|
||||
@@ -106,4 +111,8 @@ start_server {tags {"modules"}} {
|
||||
r test.log_tsctx "info" "Test message"
|
||||
verify_log_message 0 "*<misc> Test message*" 0
|
||||
}
|
||||
|
||||
test {test RM_Call CLIENT INFO} {
|
||||
assert_match "*fd=-1*" [r test.call_generic client info]
|
||||
}
|
||||
}
|
||||
@@ -14,25 +14,103 @@ tags "modules" {
|
||||
# Start the replication process...
|
||||
$replica replicaof $master_host $master_port
|
||||
wait_for_sync $replica
|
||||
|
||||
after 1000
|
||||
$master propagate-test
|
||||
|
||||
wait_for_condition 5000 10 {
|
||||
([$replica get timer] eq "10") && \
|
||||
([$replica get a-from-thread] eq "10")
|
||||
} else {
|
||||
fail "The two counters don't match the expected value."
|
||||
test {module propagates from timer} {
|
||||
set repl [attach_to_replication_stream]
|
||||
|
||||
$master propagate-test.timer
|
||||
|
||||
wait_for_condition 5000 10 {
|
||||
[$replica get timer] eq "3"
|
||||
} else {
|
||||
fail "The two counters don't match the expected value."
|
||||
}
|
||||
|
||||
assert_replication_stream $repl {
|
||||
{select *}
|
||||
{multi}
|
||||
{incr timer}
|
||||
{exec}
|
||||
{multi}
|
||||
{incr timer}
|
||||
{exec}
|
||||
{multi}
|
||||
{incr timer}
|
||||
{exec}
|
||||
}
|
||||
close_replication_stream $repl
|
||||
}
|
||||
|
||||
$master propagate-test-2
|
||||
$master propagate-test-3
|
||||
$master multi
|
||||
$master propagate-test-2
|
||||
$master propagate-test-3
|
||||
$master exec
|
||||
wait_for_ofs_sync $master $replica
|
||||
test {module propagates from thread} {
|
||||
set repl [attach_to_replication_stream]
|
||||
|
||||
$master propagate-test.thread
|
||||
|
||||
wait_for_condition 5000 10 {
|
||||
[$replica get a-from-thread] eq "3"
|
||||
} else {
|
||||
fail "The two counters don't match the expected value."
|
||||
}
|
||||
|
||||
assert_replication_stream $repl {
|
||||
{select *}
|
||||
{incr a-from-thread}
|
||||
{incr b-from-thread}
|
||||
{incr a-from-thread}
|
||||
{incr b-from-thread}
|
||||
{incr a-from-thread}
|
||||
{incr b-from-thread}
|
||||
}
|
||||
close_replication_stream $repl
|
||||
}
|
||||
|
||||
test {module propagates from from command} {
|
||||
set repl [attach_to_replication_stream]
|
||||
|
||||
$master propagate-test.simple
|
||||
$master propagate-test.mixed
|
||||
|
||||
# Note the 'after-call' propagation below is out of order (known limitation)
|
||||
assert_replication_stream $repl {
|
||||
{select *}
|
||||
{multi}
|
||||
{incr counter-1}
|
||||
{incr counter-2}
|
||||
{exec}
|
||||
{multi}
|
||||
{incr using-call}
|
||||
{incr after-call}
|
||||
{incr counter-1}
|
||||
{incr counter-2}
|
||||
{exec}
|
||||
}
|
||||
close_replication_stream $repl
|
||||
}
|
||||
|
||||
test {module propagates from from multi-exec} {
|
||||
set repl [attach_to_replication_stream]
|
||||
|
||||
$master multi
|
||||
$master propagate-test.simple
|
||||
$master propagate-test.mixed
|
||||
$master exec
|
||||
wait_for_ofs_sync $master $replica
|
||||
|
||||
# Note the 'after-call' propagation below is out of order (known limitation)
|
||||
assert_replication_stream $repl {
|
||||
{select *}
|
||||
{multi}
|
||||
{incr counter-1}
|
||||
{incr counter-2}
|
||||
{incr using-call}
|
||||
{incr after-call}
|
||||
{incr counter-1}
|
||||
{incr counter-2}
|
||||
{exec}
|
||||
}
|
||||
close_replication_stream $repl
|
||||
}
|
||||
assert_equal [s -1 unexpected_error_replies] 0
|
||||
}
|
||||
}
|
||||
@@ -47,11 +125,11 @@ tags "modules aof" {
|
||||
r config set auto-aof-rewrite-percentage 0 ; # Disable auto-rewrite.
|
||||
waitForBgrewriteaof r
|
||||
|
||||
r propagate-test-2
|
||||
r propagate-test-3
|
||||
r propagate-test.simple
|
||||
r propagate-test.mixed
|
||||
r multi
|
||||
r propagate-test-2
|
||||
r propagate-test-3
|
||||
r propagate-test.simple
|
||||
r propagate-test.mixed
|
||||
r exec
|
||||
|
||||
# Load the AOF
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
set testmodule [file normalize tests/modules/stream.so]
|
||||
|
||||
start_server {tags {"modules"}} {
|
||||
r module load $testmodule
|
||||
|
||||
test {Module stream add and delete} {
|
||||
r del mystream
|
||||
# add to empty key
|
||||
set streamid1 [r stream.add mystream item 1 value a]
|
||||
# add to existing stream
|
||||
set streamid2 [r stream.add mystream item 2 value b]
|
||||
# check result
|
||||
assert { [string match "*-*" $streamid1] }
|
||||
set items [r XRANGE mystream - +]
|
||||
assert_equal $items \
|
||||
"{$streamid1 {item 1 value a}} {$streamid2 {item 2 value b}}"
|
||||
# delete one of them and try deleting non-existing ID
|
||||
assert_equal OK [r stream.delete mystream $streamid1]
|
||||
assert_error "ERR StreamDelete*" {r stream.delete mystream 123-456}
|
||||
assert_error "Invalid stream ID*" {r stream.delete mystream foo}
|
||||
assert_equal "{$streamid2 {item 2 value b}}" [r XRANGE mystream - +]
|
||||
# check error condition: wrong type
|
||||
r del mystream
|
||||
r set mystream mystring
|
||||
assert_error "ERR StreamAdd*" {r stream.add mystream item 1 value a}
|
||||
assert_error "ERR StreamDelete*" {r stream.delete mystream 123-456}
|
||||
}
|
||||
|
||||
test {Module stream add unblocks blocking xread} {
|
||||
r del mystream
|
||||
|
||||
# Blocking XREAD on an empty key
|
||||
set rd1 [redis_deferring_client]
|
||||
$rd1 XREAD BLOCK 3000 STREAMS mystream $
|
||||
# wait until client is actually blocked
|
||||
wait_for_condition 50 100 {
|
||||
[s 0 blocked_clients] eq {1}
|
||||
} else {
|
||||
fail "Client is not blocked"
|
||||
}
|
||||
set id [r stream.add mystream field 1 value a]
|
||||
assert_equal "{mystream {{$id {field 1 value a}}}}" [$rd1 read]
|
||||
|
||||
# Blocking XREAD on an existing stream
|
||||
set rd2 [redis_deferring_client]
|
||||
$rd2 XREAD BLOCK 3000 STREAMS mystream $
|
||||
# wait until client is actually blocked
|
||||
wait_for_condition 50 100 {
|
||||
[s 0 blocked_clients] eq {1}
|
||||
} else {
|
||||
fail "Client is not blocked"
|
||||
}
|
||||
set id [r stream.add mystream field 2 value b]
|
||||
assert_equal "{mystream {{$id {field 2 value b}}}}" [$rd2 read]
|
||||
}
|
||||
|
||||
test {Module stream add benchmark (1M stream add)} {
|
||||
set n 1000000
|
||||
r del mystream
|
||||
set result [r stream.addn mystream $n field value]
|
||||
assert_equal $result $n
|
||||
}
|
||||
|
||||
test {Module stream iterator} {
|
||||
r del mystream
|
||||
set streamid1 [r xadd mystream * item 1 value a]
|
||||
set streamid2 [r xadd mystream * item 2 value b]
|
||||
# range result
|
||||
set result1 [r stream.range mystream "-" "+"]
|
||||
set expect1 [r xrange mystream "-" "+"]
|
||||
assert_equal $result1 $expect1
|
||||
# reverse range
|
||||
set result_rev [r stream.range mystream "+" "-"]
|
||||
set expect_rev [r xrevrange mystream "+" "-"]
|
||||
assert_equal $result_rev $expect_rev
|
||||
|
||||
# only one item: range with startid = endid
|
||||
set result2 [r stream.range mystream "-" $streamid1]
|
||||
assert_equal $result2 "{$streamid1 {item 1 value a}}"
|
||||
assert_equal $result2 [list [list $streamid1 {item 1 value a}]]
|
||||
# only one item: range with startid = endid
|
||||
set result3 [r stream.range mystream $streamid2 $streamid2]
|
||||
assert_equal $result3 "{$streamid2 {item 2 value b}}"
|
||||
assert_equal $result3 [list [list $streamid2 {item 2 value b}]]
|
||||
}
|
||||
|
||||
test {Module stream iterator delete} {
|
||||
r del mystream
|
||||
set id1 [r xadd mystream * normal item]
|
||||
set id2 [r xadd mystream * selfdestruct yes]
|
||||
set id3 [r xadd mystream * another item]
|
||||
# stream.range deletes the "selfdestruct" item after returning it
|
||||
assert_equal \
|
||||
"{$id1 {normal item}} {$id2 {selfdestruct yes}} {$id3 {another item}}" \
|
||||
[r stream.range mystream - +]
|
||||
# now, the "selfdestruct" item is gone
|
||||
assert_equal \
|
||||
"{$id1 {normal item}} {$id3 {another item}}" \
|
||||
[r stream.range mystream - +]
|
||||
}
|
||||
|
||||
test {Module stream trim by length} {
|
||||
r del mystream
|
||||
# exact maxlen
|
||||
r xadd mystream * item 1 value a
|
||||
r xadd mystream * item 2 value b
|
||||
r xadd mystream * item 3 value c
|
||||
assert_equal 3 [r xlen mystream]
|
||||
assert_equal 0 [r stream.trim mystream maxlen = 5]
|
||||
assert_equal 3 [r xlen mystream]
|
||||
assert_equal 2 [r stream.trim mystream maxlen = 1]
|
||||
assert_equal 1 [r xlen mystream]
|
||||
assert_equal 1 [r stream.trim mystream maxlen = 0]
|
||||
# check that there is no limit for exact maxlen
|
||||
r stream.addn mystream 20000 item x value y
|
||||
assert_equal 20000 [r stream.trim mystream maxlen = 0]
|
||||
# approx maxlen (100 items per node implies default limit 10K items)
|
||||
r stream.addn mystream 20000 item x value y
|
||||
assert_equal 20000 [r xlen mystream]
|
||||
assert_equal 10000 [r stream.trim mystream maxlen ~ 2]
|
||||
assert_equal 9900 [r stream.trim mystream maxlen ~ 2]
|
||||
assert_equal 0 [r stream.trim mystream maxlen ~ 2]
|
||||
assert_equal 100 [r xlen mystream]
|
||||
assert_equal 100 [r stream.trim mystream maxlen ~ 0]
|
||||
assert_equal 0 [r xlen mystream]
|
||||
}
|
||||
|
||||
test {Module stream trim by ID} {
|
||||
r del mystream
|
||||
# exact minid
|
||||
r xadd mystream * item 1 value a
|
||||
r xadd mystream * item 2 value b
|
||||
set minid [r xadd mystream * item 3 value c]
|
||||
assert_equal 3 [r xlen mystream]
|
||||
assert_equal 0 [r stream.trim mystream minid = -]
|
||||
assert_equal 3 [r xlen mystream]
|
||||
assert_equal 2 [r stream.trim mystream minid = $minid]
|
||||
assert_equal 1 [r xlen mystream]
|
||||
assert_equal 1 [r stream.trim mystream minid = +]
|
||||
# check that there is no limit for exact minid
|
||||
r stream.addn mystream 20000 item x value y
|
||||
assert_equal 20000 [r stream.trim mystream minid = +]
|
||||
# approx minid (100 items per node implies default limit 10K items)
|
||||
r stream.addn mystream 19980 item x value y
|
||||
set minid [r xadd mystream * item x value y]
|
||||
r stream.addn mystream 19 item x value y
|
||||
assert_equal 20000 [r xlen mystream]
|
||||
assert_equal 10000 [r stream.trim mystream minid ~ $minid]
|
||||
assert_equal 9900 [r stream.trim mystream minid ~ $minid]
|
||||
assert_equal 0 [r stream.trim mystream minid ~ $minid]
|
||||
assert_equal 100 [r xlen mystream]
|
||||
assert_equal 100 [r stream.trim mystream minid ~ +]
|
||||
assert_equal 0 [r xlen mystream]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
set testmodule [file normalize tests/modules/test_lazyfree.so]
|
||||
|
||||
start_server {tags {"modules"}} {
|
||||
r module load $testmodule
|
||||
|
||||
test "modules allocated memory can be reclaimed in the background" {
|
||||
set orig_mem [s used_memory]
|
||||
set rd [redis_deferring_client]
|
||||
|
||||
# LAZYFREE_THRESHOLD is 64
|
||||
for {set i 0} {$i < 10000} {incr i} {
|
||||
$rd lazyfreelink.insert lazykey $i
|
||||
}
|
||||
|
||||
for {set j 0} {$j < 10000} {incr j} {
|
||||
$rd read
|
||||
}
|
||||
|
||||
assert {[r lazyfreelink.len lazykey] == 10000}
|
||||
|
||||
set peak_mem [s used_memory]
|
||||
assert {[r unlink lazykey] == 1}
|
||||
assert {$peak_mem > $orig_mem+10000}
|
||||
wait_for_condition 50 100 {
|
||||
[s used_memory] < $peak_mem &&
|
||||
[s used_memory] < $orig_mem*2 &&
|
||||
[string match {*lazyfreed_objects:1*} [r info Memory]]
|
||||
} else {
|
||||
fail "Module memory is not reclaimed by UNLINK"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -62,18 +62,30 @@ tags "modules" {
|
||||
$master config set repl-diskless-sync yes
|
||||
$master config set rdbcompression no
|
||||
$replica config set repl-diskless-load swapdb
|
||||
$master config set hz 500
|
||||
$replica config set hz 500
|
||||
$master config set dynamic-hz no
|
||||
$replica config set dynamic-hz no
|
||||
set start [clock clicks -milliseconds]
|
||||
for {set k 0} {$k < 30} {incr k} {
|
||||
r testrdb.set.key key$k [string repeat A [expr {int(rand()*1000000)}]]
|
||||
}
|
||||
|
||||
if {$::verbose} {
|
||||
set end [clock clicks -milliseconds]
|
||||
set duration [expr $end - $start]
|
||||
puts "filling took $duration ms (TODO: use pipeline)"
|
||||
set start [clock clicks -milliseconds]
|
||||
}
|
||||
|
||||
# Start the replication process...
|
||||
set loglines [count_log_lines -1]
|
||||
$master config set repl-diskless-sync-delay 0
|
||||
$replica replicaof $master_host $master_port
|
||||
|
||||
# kill the replication at various points
|
||||
set attempts 3
|
||||
if {$::accurate} { set attempts 10 }
|
||||
set attempts 100
|
||||
if {$::accurate} { set attempts 500 }
|
||||
for {set i 0} {$i < $attempts} {incr i} {
|
||||
# wait for the replica to start reading the rdb
|
||||
# using the log file since the replica only responds to INFO once in 2mb
|
||||
@@ -106,6 +118,11 @@ tags "modules" {
|
||||
fail "Replica didn't disconnect"
|
||||
}
|
||||
}
|
||||
if {$::verbose} {
|
||||
set end [clock clicks -milliseconds]
|
||||
set duration [expr $end - $start]
|
||||
puts "test took $duration ms"
|
||||
}
|
||||
# enable fast shutdown
|
||||
$master config set rdb-key-save-delay 0
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
set testmodule [file normalize tests/modules/timer.so]
|
||||
|
||||
start_server {tags {"modules"}} {
|
||||
r module load $testmodule
|
||||
|
||||
test {RM_CreateTimer: a sequence of timers work} {
|
||||
# We can't guarantee same-ms but we try using MULTI/EXEC
|
||||
r multi
|
||||
for {set i 0} {$i < 20} {incr i} {
|
||||
r test.createtimer 10 timer-incr-key
|
||||
}
|
||||
r exec
|
||||
|
||||
after 500
|
||||
assert_equal 20 [r get timer-incr-key]
|
||||
}
|
||||
|
||||
test {RM_GetTimer: basic sanity} {
|
||||
# Getting non-existing timer
|
||||
assert_equal {} [r test.gettimer 0]
|
||||
|
||||
# Getting a real timer
|
||||
set id [r test.createtimer 10000 timer-incr-key]
|
||||
set info [r test.gettimer $id]
|
||||
|
||||
assert_equal "timer-incr-key" [lindex $info 0]
|
||||
set remaining [lindex $info 1]
|
||||
assert {$remaining < 10000 && $remaining > 1}
|
||||
}
|
||||
|
||||
test {RM_StopTimer: basic sanity} {
|
||||
r set "timer-incr-key" 0
|
||||
set id [r test.createtimer 1000 timer-incr-key]
|
||||
|
||||
assert_equal 1 [r test.stoptimer $id]
|
||||
|
||||
# Wait to be sure timer doesn't execute
|
||||
after 2000
|
||||
assert_equal 0 [r get timer-incr-key]
|
||||
|
||||
# Stop non-existing timer
|
||||
assert_equal 0 [r test.stoptimer $id]
|
||||
}
|
||||
|
||||
test {Timer appears non-existing after it fires} {
|
||||
r set "timer-incr-key" 0
|
||||
set id [r test.createtimer 10 timer-incr-key]
|
||||
|
||||
# verify timer fired
|
||||
after 500
|
||||
assert_equal 1 [r get timer-incr-key]
|
||||
|
||||
# verify id does not exist
|
||||
assert_equal {} [r test.gettimer $id]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
set testmodule [file normalize tests/modules/zset.so]
|
||||
|
||||
start_server {tags {"modules"}} {
|
||||
r module load $testmodule
|
||||
|
||||
test {Module zset rem} {
|
||||
r del k
|
||||
r zadd k 100 hello 200 world
|
||||
assert_equal 1 [r zset.rem k hello]
|
||||
assert_equal 0 [r zset.rem k hello]
|
||||
assert_equal 1 [r exists k]
|
||||
# Check that removing the last element deletes the key
|
||||
assert_equal 1 [r zset.rem k world]
|
||||
assert_equal 0 [r exists k]
|
||||
}
|
||||
}
|
||||
+102
-2
@@ -322,10 +322,14 @@ start_server {tags {"multi"}} {
|
||||
r multi
|
||||
r del foo
|
||||
r exec
|
||||
|
||||
# add another command so that when we see it we know multi-exec wasn't
|
||||
# propagated
|
||||
r incr foo
|
||||
|
||||
assert_replication_stream $repl {
|
||||
{select *}
|
||||
{multi}
|
||||
{exec}
|
||||
{incr foo}
|
||||
}
|
||||
close_replication_stream $repl
|
||||
}
|
||||
@@ -527,4 +531,100 @@ start_server {tags {"multi"}} {
|
||||
$r2 config set maxmemory 0
|
||||
$r2 close
|
||||
}
|
||||
|
||||
test {Blocking commands ignores the timeout} {
|
||||
r xgroup create s g $ MKSTREAM
|
||||
|
||||
set m [r multi]
|
||||
r blpop empty_list 0
|
||||
r brpop empty_list 0
|
||||
r brpoplpush empty_list1 empty_list2 0
|
||||
r blmove empty_list1 empty_list2 LEFT LEFT 0
|
||||
r bzpopmin empty_zset 0
|
||||
r bzpopmax empty_zset 0
|
||||
r xread BLOCK 0 STREAMS s $
|
||||
r xreadgroup group g c BLOCK 0 STREAMS s >
|
||||
set res [r exec]
|
||||
|
||||
list $m $res
|
||||
} {OK {{} {} {} {} {} {} {} {}}}
|
||||
|
||||
test {MULTI propagation of PUBLISH} {
|
||||
set repl [attach_to_replication_stream]
|
||||
|
||||
# make sure that PUBLISH inside MULTI is propagated in a transaction
|
||||
r multi
|
||||
r publish bla bla
|
||||
r exec
|
||||
|
||||
assert_replication_stream $repl {
|
||||
{select *}
|
||||
{multi}
|
||||
{publish bla bla}
|
||||
{exec}
|
||||
}
|
||||
close_replication_stream $repl
|
||||
}
|
||||
|
||||
test {MULTI propagation of SCRIPT LOAD} {
|
||||
set repl [attach_to_replication_stream]
|
||||
|
||||
# make sure that SCRIPT LOAD inside MULTI is propagated in a transaction
|
||||
r multi
|
||||
r script load {redis.call('set', KEYS[1], 'foo')}
|
||||
set res [r exec]
|
||||
set sha [lindex $res 0]
|
||||
|
||||
assert_replication_stream $repl {
|
||||
{select *}
|
||||
{multi}
|
||||
{script load *}
|
||||
{exec}
|
||||
}
|
||||
close_replication_stream $repl
|
||||
}
|
||||
|
||||
test {MULTI propagation of SCRIPT LOAD} {
|
||||
set repl [attach_to_replication_stream]
|
||||
|
||||
# make sure that EVAL inside MULTI is propagated in a transaction
|
||||
r config set lua-replicate-commands no
|
||||
r multi
|
||||
r eval {redis.call('set', KEYS[1], 'bar')} 1 bar
|
||||
r exec
|
||||
|
||||
assert_replication_stream $repl {
|
||||
{select *}
|
||||
{multi}
|
||||
{eval *}
|
||||
{exec}
|
||||
}
|
||||
close_replication_stream $repl
|
||||
}
|
||||
|
||||
tags {"stream"} {
|
||||
test {MULTI propagation of XREADGROUP} {
|
||||
# stream is a special case because it calls propagate() directly for XREADGROUP
|
||||
set repl [attach_to_replication_stream]
|
||||
|
||||
r XADD mystream * foo bar
|
||||
r XGROUP CREATE mystream mygroup 0
|
||||
|
||||
# make sure the XCALIM (propagated by XREADGROUP) is indeed inside MULTI/EXEC
|
||||
r multi
|
||||
r XREADGROUP GROUP mygroup consumer1 STREAMS mystream ">"
|
||||
r exec
|
||||
|
||||
assert_replication_stream $repl {
|
||||
{select *}
|
||||
{xadd *}
|
||||
{xgroup CREATE *}
|
||||
{multi}
|
||||
{xclaim *}
|
||||
{exec}
|
||||
}
|
||||
close_replication_stream $repl
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
test {CONFIG SET port number} {
|
||||
start_server {} {
|
||||
if {$::tls} { set port_cfg tls-port} else { set port_cfg port }
|
||||
|
||||
# available port
|
||||
set avail_port [find_available_port $::baseport $::portcount]
|
||||
set rd [redis [srv 0 host] [srv 0 port] 0 $::tls]
|
||||
$rd CONFIG SET $port_cfg $avail_port
|
||||
$rd close
|
||||
set rd [redis [srv 0 host] $avail_port 0 $::tls]
|
||||
$rd PING
|
||||
|
||||
# already inuse port
|
||||
catch {$rd CONFIG SET $port_cfg $::test_server_port} e
|
||||
assert_match {*Unable to listen on this port*} $e
|
||||
$rd close
|
||||
|
||||
# make sure server still listening on the previous port
|
||||
set rd [redis [srv 0 host] $avail_port 0 $::tls]
|
||||
$rd PING
|
||||
$rd close
|
||||
}
|
||||
}
|
||||
|
||||
test {CONFIG SET bind address} {
|
||||
start_server {} {
|
||||
# non-valid address
|
||||
catch {r CONFIG SET bind "some.wrong.bind.address"} e
|
||||
assert_match {*Failed to bind to specified addresses*} $e
|
||||
|
||||
# make sure server still bound to the previous address
|
||||
set rd [redis [srv 0 host] [srv 0 port] 0 $::tls]
|
||||
$rd PING
|
||||
$rd close
|
||||
}
|
||||
}
|
||||
@@ -21,17 +21,17 @@ if {$system_name eq {linux}} {
|
||||
r config set oom-score-adj-values "10 20 30"
|
||||
r config set oom-score-adj yes
|
||||
|
||||
assert_equal [get_oom_score_adj] [expr $base + 10] case1
|
||||
assert {[get_oom_score_adj] == [expr $base + 10]}
|
||||
|
||||
# Modify current class
|
||||
r config set oom-score-adj-values "15 20 30"
|
||||
assert_equal [get_oom_score_adj] [expr $base + 15] case2
|
||||
assert {[get_oom_score_adj] == [expr $base + 15]}
|
||||
|
||||
# Check replica class
|
||||
r replicaof localhost 1
|
||||
assert_equal [get_oom_score_adj] [expr $base + 20] case3
|
||||
assert {[get_oom_score_adj] == [expr $base + 20]}
|
||||
r replicaof no one
|
||||
assert_equal [get_oom_score_adj] [expr $base + 15] case4
|
||||
assert {[get_oom_score_adj] == [expr $base + 15]}
|
||||
|
||||
# Check child process
|
||||
r set key-a value-a
|
||||
@@ -39,7 +39,12 @@ if {$system_name eq {linux}} {
|
||||
r bgsave
|
||||
|
||||
set child_pid [get_child_pid 0]
|
||||
assert {[get_oom_score_adj $child_pid] == [expr $base + 30]}
|
||||
# Wait until background child process to setOOMScoreAdj success.
|
||||
wait_for_condition 100 10 {
|
||||
[get_oom_score_adj $child_pid] == [expr $base + 30]
|
||||
} else {
|
||||
fail "Set oom-score-adj of background child process is not ok"
|
||||
}
|
||||
}
|
||||
|
||||
# Failed oom-score-adj tests can only run unprivileged
|
||||
|
||||
+97
-3
@@ -62,7 +62,7 @@ start_server {tags {"other"}} {
|
||||
} {*index is out of range*}
|
||||
|
||||
tags {consistency} {
|
||||
if {![catch {package require sha1}]} {
|
||||
if {true} {
|
||||
if {$::accurate} {set numops 10000} else {set numops 1000}
|
||||
test {Check consistency of different data types after a reload} {
|
||||
r flushdb
|
||||
@@ -256,6 +256,57 @@ start_server {tags {"other"}} {
|
||||
waitForBgsave r
|
||||
r save
|
||||
} {OK}
|
||||
|
||||
test {RESET clears client state} {
|
||||
r client setname test-client
|
||||
r client tracking on
|
||||
|
||||
assert_equal [r reset] "RESET"
|
||||
set client [r client list]
|
||||
assert_match {*name= *} $client
|
||||
assert_match {*flags=N *} $client
|
||||
}
|
||||
|
||||
test {RESET clears MONITOR state} {
|
||||
set rd [redis_deferring_client]
|
||||
$rd monitor
|
||||
assert_equal [$rd read] "OK"
|
||||
|
||||
$rd reset
|
||||
|
||||
# skip reset ouptut
|
||||
$rd read
|
||||
assert_equal [$rd read] "RESET"
|
||||
|
||||
assert_no_match {*flags=O*} [r client list]
|
||||
}
|
||||
|
||||
test {RESET clears and discards MULTI state} {
|
||||
r multi
|
||||
r set key-a a
|
||||
|
||||
r reset
|
||||
catch {r exec} err
|
||||
assert_match {*EXEC without MULTI*} $err
|
||||
}
|
||||
|
||||
test {RESET clears Pub/Sub state} {
|
||||
r subscribe channel-1
|
||||
r reset
|
||||
|
||||
# confirm we're not subscribed by executing another command
|
||||
r set key val
|
||||
}
|
||||
|
||||
test {RESET clears authenticated state} {
|
||||
r acl setuser user1 on >secret +@all
|
||||
r auth user1 secret
|
||||
assert_equal [r acl whoami] user1
|
||||
|
||||
r reset
|
||||
|
||||
assert_equal [r acl whoami] default
|
||||
}
|
||||
}
|
||||
|
||||
start_server {tags {"other"}} {
|
||||
@@ -272,8 +323,51 @@ start_server {tags {"other"}} {
|
||||
after 200
|
||||
|
||||
# Hash table should rehash since there is no child process,
|
||||
# size is power of two and over 4098, so it is 16384
|
||||
# size is power of two and over 4098, so it is 8192
|
||||
r set k3 v3
|
||||
assert_match "*table size: 16384*" [r debug HTSTATS 9]
|
||||
assert_match "*table size: 8192*" [r debug HTSTATS 9]
|
||||
}
|
||||
}
|
||||
|
||||
proc read_proc_title {pid} {
|
||||
set fd [open "/proc/$pid/cmdline" "r"]
|
||||
set cmdline [read $fd 1024]
|
||||
close $fd
|
||||
|
||||
return $cmdline
|
||||
}
|
||||
|
||||
start_server {tags {"other"}} {
|
||||
test {Process title set as expected} {
|
||||
# Test only on Linux where it's easy to get cmdline without relying on tools.
|
||||
# Skip valgrind as it messes up the arguments.
|
||||
set os [exec uname]
|
||||
if {$os == "Linux" && !$::valgrind} {
|
||||
# Set a custom template
|
||||
r config set "proc-title-template" "TEST {title} {listen-addr} {port} {tls-port} {unixsocket} {config-file}"
|
||||
set cmdline [read_proc_title [srv 0 pid]]
|
||||
|
||||
assert_equal "TEST" [lindex $cmdline 0]
|
||||
assert_match "*/keydb-server" [lindex $cmdline 1]
|
||||
|
||||
if {$::tls} {
|
||||
set expect_port 0
|
||||
set expect_tls_port [srv 0 port]
|
||||
} else {
|
||||
set expect_port [srv 0 port]
|
||||
set expect_tls_port 0
|
||||
}
|
||||
set port [srv 0 port]
|
||||
|
||||
assert_equal "$::host:$port" [lindex $cmdline 2]
|
||||
assert_equal $expect_port [lindex $cmdline 3]
|
||||
assert_equal $expect_tls_port [lindex $cmdline 4]
|
||||
assert_match "*/tests/tmp/server.*/socket" [lindex $cmdline 5]
|
||||
assert_match "*/tests/tmp/redis.conf.*" [lindex $cmdline 6]
|
||||
|
||||
# Try setting a bad template
|
||||
catch {r config set "proc-title-template" "{invalid-var}"} err
|
||||
assert_match {*template format is invalid*} $err
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
start_server {tags {"pause network"}} {
|
||||
test "Test read commands are not blocked by client pause" {
|
||||
r client PAUSE 100000000 WRITE
|
||||
set rd [redis_deferring_client]
|
||||
$rd GET FOO
|
||||
$rd PING
|
||||
$rd INFO
|
||||
assert_equal [s 0 blocked_clients] 0
|
||||
r client unpause
|
||||
$rd close
|
||||
}
|
||||
|
||||
test "Test write commands are paused by RO" {
|
||||
r client PAUSE 100000000 WRITE
|
||||
|
||||
set rd [redis_deferring_client]
|
||||
$rd SET FOO BAR
|
||||
wait_for_condition 50 100 {
|
||||
[s 0 blocked_clients] eq {1}
|
||||
} else {
|
||||
fail "Clients are not blocked"
|
||||
}
|
||||
|
||||
r client unpause
|
||||
assert_match "OK" [$rd read]
|
||||
$rd close
|
||||
}
|
||||
|
||||
test "Test special commands are paused by RO" {
|
||||
r PFADD pause-hll test
|
||||
r client PAUSE 100000000 WRITE
|
||||
|
||||
# Test that pfcount, which can replicate, is also blocked
|
||||
set rd [redis_deferring_client]
|
||||
$rd PFCOUNT pause-hll
|
||||
wait_for_condition 50 100 {
|
||||
[s 0 blocked_clients] eq {1}
|
||||
} else {
|
||||
fail "Clients are not blocked"
|
||||
}
|
||||
|
||||
# Test that publish, which adds the message to the replication
|
||||
# stream is blocked.
|
||||
set rd2 [redis_deferring_client]
|
||||
$rd2 publish foo bar
|
||||
wait_for_condition 50 100 {
|
||||
[s 0 blocked_clients] eq {2}
|
||||
} else {
|
||||
fail "Clients are not blocked"
|
||||
}
|
||||
|
||||
# Test that SCRIPT LOAD, which is replicated.
|
||||
set rd3 [redis_deferring_client]
|
||||
$rd3 script load "return 1"
|
||||
wait_for_condition 50 100 {
|
||||
[s 0 blocked_clients] eq {3}
|
||||
} else {
|
||||
fail "Clients are not blocked"
|
||||
}
|
||||
|
||||
r client unpause
|
||||
assert_match "1" [$rd read]
|
||||
assert_match "0" [$rd2 read]
|
||||
assert_match "*" [$rd3 read]
|
||||
$rd close
|
||||
$rd2 close
|
||||
$rd3 close
|
||||
}
|
||||
|
||||
test "Test read/admin mutli-execs are not blocked by pause RO" {
|
||||
r SET FOO BAR
|
||||
r client PAUSE 100000000 WRITE
|
||||
set rd [redis_deferring_client]
|
||||
$rd MULTI
|
||||
assert_equal [$rd read] "OK"
|
||||
$rd PING
|
||||
assert_equal [$rd read] "QUEUED"
|
||||
$rd GET FOO
|
||||
assert_equal [$rd read] "QUEUED"
|
||||
$rd EXEC
|
||||
assert_equal [s 0 blocked_clients] 0
|
||||
r client unpause
|
||||
assert_match "PONG BAR" [$rd read]
|
||||
$rd close
|
||||
}
|
||||
|
||||
test "Test write mutli-execs are blocked by pause RO" {
|
||||
set rd [redis_deferring_client]
|
||||
$rd MULTI
|
||||
assert_equal [$rd read] "OK"
|
||||
$rd SET FOO BAR
|
||||
r client PAUSE 100000000 WRITE
|
||||
assert_equal [$rd read] "QUEUED"
|
||||
$rd EXEC
|
||||
wait_for_condition 50 100 {
|
||||
[s 0 blocked_clients] eq {1}
|
||||
} else {
|
||||
fail "Clients are not blocked"
|
||||
}
|
||||
r client unpause
|
||||
assert_match "OK" [$rd read]
|
||||
$rd close
|
||||
}
|
||||
|
||||
test "Test scripts are blocked by pause RO" {
|
||||
r client PAUSE 100000000 WRITE
|
||||
set rd [redis_deferring_client]
|
||||
$rd EVAL "return 1" 0
|
||||
|
||||
wait_for_condition 50 100 {
|
||||
[s 0 blocked_clients] eq {1}
|
||||
} else {
|
||||
fail "Clients are not blocked"
|
||||
}
|
||||
r client unpause
|
||||
assert_match "1" [$rd read]
|
||||
$rd close
|
||||
}
|
||||
|
||||
test "Test multiple clients can be queued up and unblocked" {
|
||||
r client PAUSE 100000000 WRITE
|
||||
set clients [list [redis_deferring_client] [redis_deferring_client] [redis_deferring_client]]
|
||||
foreach client $clients {
|
||||
$client SET FOO BAR
|
||||
}
|
||||
|
||||
wait_for_condition 50 100 {
|
||||
[s 0 blocked_clients] eq {3}
|
||||
} else {
|
||||
fail "Clients are not blocked"
|
||||
}
|
||||
r client unpause
|
||||
foreach client $clients {
|
||||
assert_match "OK" [$client read]
|
||||
$client close
|
||||
}
|
||||
}
|
||||
|
||||
test "Test clients with syntax errors will get responses immediately" {
|
||||
r client PAUSE 100000000 WRITE
|
||||
catch {r set FOO} err
|
||||
assert_match "ERR wrong number of arguments for *" $err
|
||||
r client unpause
|
||||
}
|
||||
|
||||
test "Test both active and passive expiries are skipped during client pause" {
|
||||
set expired_keys [s 0 expired_keys]
|
||||
r multi
|
||||
r set foo bar PX 10
|
||||
r set bar foo PX 10
|
||||
r client PAUSE 100000000 WRITE
|
||||
r exec
|
||||
|
||||
wait_for_condition 10 100 {
|
||||
[r get foo] == {} && [r get bar] == {}
|
||||
} else {
|
||||
fail "Keys were never logically expired"
|
||||
}
|
||||
|
||||
# No keys should actually have been expired
|
||||
assert_match $expired_keys [s 0 expired_keys]
|
||||
|
||||
r client unpause
|
||||
|
||||
# Force the keys to expire
|
||||
r get foo
|
||||
r get bar
|
||||
|
||||
# Now that clients have been unpaused, expires should go through
|
||||
assert_match [expr $expired_keys + 2] [s 0 expired_keys]
|
||||
}
|
||||
|
||||
test "Test that client pause starts at the end of a transaction" {
|
||||
r MULTI
|
||||
r SET FOO1 BAR
|
||||
r client PAUSE 100000000 WRITE
|
||||
r SET FOO2 BAR
|
||||
r exec
|
||||
|
||||
set rd [redis_deferring_client]
|
||||
$rd SET FOO3 BAR
|
||||
|
||||
wait_for_condition 50 100 {
|
||||
[s 0 blocked_clients] eq {1}
|
||||
} else {
|
||||
fail "Clients are not blocked"
|
||||
}
|
||||
|
||||
assert_match "BAR" [r GET FOO1]
|
||||
assert_match "BAR" [r GET FOO2]
|
||||
assert_match "" [r GET FOO3]
|
||||
|
||||
r client unpause
|
||||
assert_match "OK" [$rd read]
|
||||
$rd close
|
||||
}
|
||||
|
||||
# Make sure we unpause at the end
|
||||
r client unpause
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
start_server {tags {"protocol"}} {
|
||||
start_server {tags {"protocol network"}} {
|
||||
test "Handle an empty query" {
|
||||
reconnect
|
||||
r write "\r\n"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
start_server {tags {"pubsub"}} {
|
||||
start_server {tags {"pubsub network"}} {
|
||||
proc __consume_subscribe_messages {client type channels} {
|
||||
set numsub -1
|
||||
set counts {}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
start_server {tags {"scan"}} {
|
||||
start_server {tags {"scan network"}} {
|
||||
test "SCAN basic" {
|
||||
r flushdb
|
||||
r debug populate 1000
|
||||
|
||||
@@ -140,12 +140,42 @@ start_server {tags {"scripting"}} {
|
||||
} {*execution time*}
|
||||
}
|
||||
|
||||
test {EVAL - Scripts can't run certain commands} {
|
||||
test {EVAL - Scripts can't run blpop command} {
|
||||
set e {}
|
||||
catch {r eval {return redis.pcall('blpop','x',0)} 0} e
|
||||
set e
|
||||
} {*not allowed*}
|
||||
|
||||
test {EVAL - Scripts can't run brpop command} {
|
||||
set e {}
|
||||
catch {r eval {return redis.pcall('brpop','empty_list',0)} 0} e
|
||||
set e
|
||||
} {*not allowed*}
|
||||
|
||||
test {EVAL - Scripts can't run brpoplpush command} {
|
||||
set e {}
|
||||
catch {r eval {return redis.pcall('brpoplpush','empty_list1', 'empty_list2',0)} 0} e
|
||||
set e
|
||||
} {*not allowed*}
|
||||
|
||||
test {EVAL - Scripts can't run blmove command} {
|
||||
set e {}
|
||||
catch {r eval {return redis.pcall('blmove','empty_list1', 'empty_list2', 'LEFT', 'LEFT', 0)} 0} e
|
||||
set e
|
||||
} {*not allowed*}
|
||||
|
||||
test {EVAL - Scripts can't run bzpopmin command} {
|
||||
set e {}
|
||||
catch {r eval {return redis.pcall('bzpopmin','empty_zset', 0)} 0} e
|
||||
set e
|
||||
} {*not allowed*}
|
||||
|
||||
test {EVAL - Scripts can't run bzpopmax command} {
|
||||
set e {}
|
||||
catch {r eval {return redis.pcall('bzpopmax','empty_zset', 0)} 0} e
|
||||
set e
|
||||
} {*not allowed*}
|
||||
|
||||
test {EVAL - Scripts can't run XREAD and XREADGROUP with BLOCK option} {
|
||||
r del s
|
||||
r xgroup create s g $ MKSTREAM
|
||||
@@ -300,6 +330,15 @@ start_server {tags {"scripting"}} {
|
||||
set e
|
||||
} {NOSCRIPT*}
|
||||
|
||||
test {SCRIPTING FLUSH ASYNC} {
|
||||
for {set j 0} {$j < 100} {incr j} {
|
||||
r script load "return $j"
|
||||
}
|
||||
assert { [string match "*number_of_cached_scripts:100*" [r info Memory]] }
|
||||
r script flush async
|
||||
assert { [string match "*number_of_cached_scripts:0*" [r info Memory]] }
|
||||
}
|
||||
|
||||
test {SCRIPT EXISTS - can detect already defined scripts?} {
|
||||
r eval "return 1+1" 0
|
||||
r script exists a27e7e8a43702b7046d4f6a7ccf5b60cef6b9bd9 a27e7e8a43702b7046d4f6a7ccf5b60cef6b9bda
|
||||
@@ -429,6 +468,7 @@ start_server {tags {"scripting"}} {
|
||||
r slaveof no one
|
||||
set res
|
||||
} {102}
|
||||
r config set aof-use-rdb-preamble yes
|
||||
|
||||
test {EVAL with pipelined command (No crash)} {
|
||||
r flushall
|
||||
|
||||
+36
-1
@@ -41,6 +41,41 @@ start_server {tags {"slowlog"} overrides {slowlog-log-slower-than 1000000}} {
|
||||
assert_equal {foobar} [lindex $e 5]
|
||||
}
|
||||
|
||||
test {SLOWLOG - Rewritten commands are logged as their original command} {
|
||||
r config set slowlog-log-slower-than 0
|
||||
|
||||
# Test rewriting client arguments
|
||||
r sadd set a b c d e
|
||||
r slowlog reset
|
||||
|
||||
# SPOP is rewritten as DEL when all keys are removed
|
||||
r spop set 10
|
||||
assert_equal {spop set 10} [lindex [lindex [r slowlog get] 0] 3]
|
||||
|
||||
# Test replacing client arguments
|
||||
r slowlog reset
|
||||
|
||||
# GEOADD is replicated as ZADD
|
||||
r geoadd cool-cities -122.33207 47.60621 Seattle
|
||||
assert_equal {geoadd cool-cities -122.33207 47.60621 Seattle} [lindex [lindex [r slowlog get] 0] 3]
|
||||
|
||||
# Test replacing a single command argument
|
||||
r set A 5
|
||||
r slowlog reset
|
||||
|
||||
# GETSET is replicated as SET
|
||||
r getset a 5
|
||||
assert_equal {getset a 5} [lindex [lindex [r slowlog get] 0] 3]
|
||||
|
||||
# INCRBYFLOAT calls rewrite multiple times, so it's a special case
|
||||
r set A 0
|
||||
r slowlog reset
|
||||
|
||||
# INCRBYFLOAT is replicated as SET
|
||||
r INCRBYFLOAT A 1.0
|
||||
assert_equal {INCRBYFLOAT A 1.0} [lindex [lindex [r slowlog get] 0] 3]
|
||||
}
|
||||
|
||||
test {SLOWLOG - commands with too many arguments are trimmed} {
|
||||
r config set slowlog-log-slower-than 0
|
||||
r slowlog reset
|
||||
@@ -70,7 +105,7 @@ start_server {tags {"slowlog"} overrides {slowlog-log-slower-than 1000000}} {
|
||||
assert_equal [lindex $e 3] {debug sleep 0.2}
|
||||
}
|
||||
|
||||
test {SLOWLOG - can clean older entires} {
|
||||
test {SLOWLOG - can clean older entries} {
|
||||
r client setname lastentry_client
|
||||
r config set slowlog-max-len 1
|
||||
r debug sleep 0.2
|
||||
|
||||
@@ -93,5 +93,51 @@ start_server {tags {"tls"}} {
|
||||
r CONFIG SET tls-protocols ""
|
||||
r CONFIG SET tls-ciphers "DEFAULT"
|
||||
}
|
||||
|
||||
test {TLS: Verify tls-cert-file is also used as a client cert if none specified} {
|
||||
set master [srv 0 client]
|
||||
set master_host [srv 0 host]
|
||||
set master_port [srv 0 port]
|
||||
|
||||
# Use a non-restricted client/server cert for the replica
|
||||
set redis_crt [format "%s/tests/tls/redis.crt" [pwd]]
|
||||
set redis_key [format "%s/tests/tls/redis.key" [pwd]]
|
||||
|
||||
start_server [list overrides [list tls-cert-file $redis_crt tls-key-file $redis_key] \
|
||||
omit [list tls-client-cert-file tls-client-key-file]] {
|
||||
set replica [srv 0 client]
|
||||
$replica replicaof $master_host $master_port
|
||||
wait_for_condition 30 100 {
|
||||
[string match {*master_link_status:up*} [$replica info replication]]
|
||||
} else {
|
||||
fail "Can't authenticate to master using just tls-cert-file!"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
test {TLS: switch between tcp and tls ports} {
|
||||
set srv_port [srv 0 port]
|
||||
|
||||
# TLS
|
||||
set rd [redis [srv 0 host] $srv_port 0 1]
|
||||
$rd PING
|
||||
|
||||
# TCP
|
||||
$rd CONFIG SET tls-port 0
|
||||
$rd CONFIG SET port $srv_port
|
||||
$rd close
|
||||
|
||||
set rd [redis [srv 0 host] $srv_port 0 0]
|
||||
$rd PING
|
||||
|
||||
# TLS
|
||||
$rd CONFIG SET port 0
|
||||
$rd CONFIG SET tls-port $srv_port
|
||||
$rd close
|
||||
|
||||
set rd [redis [srv 0 host] $srv_port 0 1]
|
||||
$rd PING
|
||||
$rd close
|
||||
}
|
||||
}
|
||||
}
|
||||
+472
-42
@@ -1,26 +1,51 @@
|
||||
start_server {tags {"tracking"}} {
|
||||
start_server {tags {"tracking network"}} {
|
||||
# Create a deferred client we'll use to redirect invalidation
|
||||
# messages to.
|
||||
set rd1 [redis_deferring_client]
|
||||
$rd1 client id
|
||||
set redir [$rd1 read]
|
||||
$rd1 subscribe __redis__:invalidate
|
||||
$rd1 read ; # Consume the SUBSCRIBE reply.
|
||||
set rd_redirection [redis_deferring_client]
|
||||
$rd_redirection client id
|
||||
set redir_id [$rd_redirection read]
|
||||
$rd_redirection subscribe __redis__:invalidate
|
||||
$rd_redirection read ; # Consume the SUBSCRIBE reply.
|
||||
|
||||
# Create another client as well in order to test NOLOOP
|
||||
set rd2 [redis_deferring_client]
|
||||
# Create another client that's not used as a redirection client
|
||||
# We should always keep this client's buffer clean
|
||||
set rd [redis_deferring_client]
|
||||
|
||||
# Client to be used for SET and GET commands
|
||||
# We don't read this client's buffer
|
||||
set rd_sg [redis_client]
|
||||
|
||||
proc clean_all {} {
|
||||
uplevel {
|
||||
# We should make r TRACKING off first. If r is in RESP3,
|
||||
# r FLUSH ALL will send us tracking-redir-broken or other
|
||||
# info which will not be consumed.
|
||||
r CLIENT TRACKING off
|
||||
$rd QUIT
|
||||
$rd_redirection QUIT
|
||||
set rd [redis_deferring_client]
|
||||
set rd_redirection [redis_deferring_client]
|
||||
$rd_redirection client id
|
||||
set redir_id [$rd_redirection read]
|
||||
$rd_redirection subscribe __redis__:invalidate
|
||||
$rd_redirection read ; # Consume the SUBSCRIBE reply.
|
||||
r FLUSHALL
|
||||
r HELLO 2
|
||||
r config set tracking-table-max-keys 1000000
|
||||
}
|
||||
}
|
||||
|
||||
test {Clients are able to enable tracking and redirect it} {
|
||||
r CLIENT TRACKING on REDIRECT $redir
|
||||
r CLIENT TRACKING on REDIRECT $redir_id
|
||||
} {*OK}
|
||||
|
||||
test {The other connection is able to get invalidations} {
|
||||
r SET a 1
|
||||
r SET b 1
|
||||
r GET a
|
||||
r INCR b ; # This key should not be notified, since it wasn't fetched.
|
||||
r INCR a
|
||||
set keys [lindex [$rd1 read] 2]
|
||||
r INCR b ; # This key should not be notified, since it wasn't fetched.
|
||||
r INCR a
|
||||
set keys [lindex [$rd_redirection read] 2]
|
||||
assert {[llength $keys] == 1}
|
||||
assert {[lindex $keys 0] eq {a}}
|
||||
}
|
||||
@@ -30,87 +55,307 @@ start_server {tags {"tracking"}} {
|
||||
# so that we can check for leaks, as a side effect.
|
||||
r MGET a b c d e f g
|
||||
r CLIENT TRACKING off
|
||||
}
|
||||
} {*OK}
|
||||
|
||||
test {Clients can enable the BCAST mode with the empty prefix} {
|
||||
r CLIENT TRACKING on BCAST REDIRECT $redir
|
||||
r CLIENT TRACKING on BCAST REDIRECT $redir_id
|
||||
} {*OK*}
|
||||
|
||||
test {The connection gets invalidation messages about all the keys} {
|
||||
r MSET a 1 b 2 c 3
|
||||
set keys [lsort [lindex [$rd1 read] 2]]
|
||||
set keys [lsort [lindex [$rd_redirection read] 2]]
|
||||
assert {$keys eq {a b c}}
|
||||
}
|
||||
|
||||
test {Clients can enable the BCAST mode with prefixes} {
|
||||
r CLIENT TRACKING off
|
||||
r CLIENT TRACKING on BCAST REDIRECT $redir PREFIX a: PREFIX b:
|
||||
r CLIENT TRACKING on BCAST REDIRECT $redir_id PREFIX a: PREFIX b:
|
||||
r MULTI
|
||||
r INCR a:1
|
||||
r INCR a:2
|
||||
r INCR b:1
|
||||
r INCR b:2
|
||||
# we should not get this key
|
||||
r INCR c:1
|
||||
r EXEC
|
||||
# Because of the internals, we know we are going to receive
|
||||
# two separated notifications for the two different prefixes.
|
||||
set keys1 [lsort [lindex [$rd1 read] 2]]
|
||||
set keys2 [lsort [lindex [$rd1 read] 2]]
|
||||
set keys1 [lsort [lindex [$rd_redirection read] 2]]
|
||||
set keys2 [lsort [lindex [$rd_redirection read] 2]]
|
||||
set keys [lsort [list {*}$keys1 {*}$keys2]]
|
||||
assert {$keys eq {a:1 a:2 b:1 b:2}}
|
||||
}
|
||||
|
||||
|
||||
test {Adding prefixes to BCAST mode works} {
|
||||
r CLIENT TRACKING on BCAST REDIRECT $redir PREFIX c:
|
||||
r CLIENT TRACKING on BCAST REDIRECT $redir_id PREFIX c:
|
||||
r INCR c:1234
|
||||
set keys [lsort [lindex [$rd1 read] 2]]
|
||||
set keys [lsort [lindex [$rd_redirection read] 2]]
|
||||
assert {$keys eq {c:1234}}
|
||||
}
|
||||
|
||||
test {Tracking NOLOOP mode in standard mode works} {
|
||||
r CLIENT TRACKING off
|
||||
r CLIENT TRACKING on REDIRECT $redir NOLOOP
|
||||
r CLIENT TRACKING on REDIRECT $redir_id NOLOOP
|
||||
r MGET otherkey1 loopkey otherkey2
|
||||
$rd2 SET otherkey1 1; # We should get this
|
||||
$rd_sg SET otherkey1 1; # We should get this
|
||||
r SET loopkey 1 ; # We should not get this
|
||||
$rd2 SET otherkey2 1; # We should get this
|
||||
$rd_sg SET otherkey2 1; # We should get this
|
||||
# Because of the internals, we know we are going to receive
|
||||
# two separated notifications for the two different prefixes.
|
||||
set keys1 [lsort [lindex [$rd1 read] 2]]
|
||||
set keys2 [lsort [lindex [$rd1 read] 2]]
|
||||
# two separated notifications for the two different keys.
|
||||
set keys1 [lsort [lindex [$rd_redirection read] 2]]
|
||||
set keys2 [lsort [lindex [$rd_redirection read] 2]]
|
||||
set keys [lsort [list {*}$keys1 {*}$keys2]]
|
||||
assert {$keys eq {otherkey1 otherkey2}}
|
||||
}
|
||||
|
||||
test {Tracking NOLOOP mode in BCAST mode works} {
|
||||
r CLIENT TRACKING off
|
||||
r CLIENT TRACKING on BCAST REDIRECT $redir NOLOOP
|
||||
$rd2 SET otherkey1 1; # We should get this
|
||||
r CLIENT TRACKING on BCAST REDIRECT $redir_id NOLOOP
|
||||
$rd_sg SET otherkey1 1; # We should get this
|
||||
r SET loopkey 1 ; # We should not get this
|
||||
$rd2 SET otherkey2 1; # We should get this
|
||||
# Because of the internals, we know we are going to receive
|
||||
# two separated notifications for the two different prefixes.
|
||||
set keys1 [lsort [lindex [$rd1 read] 2]]
|
||||
set keys2 [lsort [lindex [$rd1 read] 2]]
|
||||
$rd_sg SET otherkey2 1; # We should get this
|
||||
# Because $rd_sg send command synchronously, we know we are
|
||||
# going to receive two separated notifications.
|
||||
set keys1 [lsort [lindex [$rd_redirection read] 2]]
|
||||
set keys2 [lsort [lindex [$rd_redirection read] 2]]
|
||||
set keys [lsort [list {*}$keys1 {*}$keys2]]
|
||||
assert {$keys eq {otherkey1 otherkey2}}
|
||||
}
|
||||
|
||||
test {Tracking gets notification of expired keys} {
|
||||
r CLIENT TRACKING off
|
||||
r CLIENT TRACKING on BCAST REDIRECT $redir NOLOOP
|
||||
r CLIENT TRACKING on BCAST REDIRECT $redir_id NOLOOP
|
||||
r SET mykey myval px 1
|
||||
r SET mykeyotherkey myval ; # We should not get it
|
||||
after 1000
|
||||
# Because of the internals, we know we are going to receive
|
||||
# two separated notifications for the two different prefixes.
|
||||
set keys1 [lsort [lindex [$rd1 read] 2]]
|
||||
set keys [lsort [list {*}$keys1]]
|
||||
set keys [lsort [lindex [$rd_redirection read] 2]]
|
||||
assert {$keys eq {mykey}}
|
||||
}
|
||||
|
||||
test {HELLO 3 reply is correct} {
|
||||
set reply [r HELLO 3]
|
||||
assert_equal [dict get $reply proto] 3
|
||||
}
|
||||
|
||||
test {HELLO without protover} {
|
||||
set reply [r HELLO 3]
|
||||
assert_equal [dict get $reply proto] 3
|
||||
|
||||
set reply [r HELLO]
|
||||
assert_equal [dict get $reply proto] 3
|
||||
|
||||
set reply [r HELLO 2]
|
||||
assert_equal [dict get $reply proto] 2
|
||||
|
||||
set reply [r HELLO]
|
||||
assert_equal [dict get $reply proto] 2
|
||||
|
||||
# restore RESP3 for next test
|
||||
r HELLO 3
|
||||
}
|
||||
|
||||
test {RESP3 based basic invalidation} {
|
||||
r CLIENT TRACKING off
|
||||
r CLIENT TRACKING on
|
||||
$rd_sg SET key1 1
|
||||
r GET key1
|
||||
$rd_sg SET key1 2
|
||||
r read
|
||||
} {invalidate key1}
|
||||
|
||||
test {RESP3 tracking redirection} {
|
||||
r CLIENT TRACKING off
|
||||
r CLIENT TRACKING on REDIRECT $redir_id
|
||||
$rd_sg SET key1 1
|
||||
r GET key1
|
||||
$rd_sg SET key1 2
|
||||
set res [lindex [$rd_redirection read] 2]
|
||||
assert {$res eq {key1}}
|
||||
}
|
||||
|
||||
test {Invalidations of previous keys can be redirected after switching to RESP3} {
|
||||
r HELLO 2
|
||||
$rd_sg SET key1 1
|
||||
r GET key1
|
||||
r HELLO 3
|
||||
$rd_sg SET key1 2
|
||||
set res [lindex [$rd_redirection read] 2]
|
||||
assert {$res eq {key1}}
|
||||
}
|
||||
|
||||
test {Invalidations of new keys can be redirected after switching to RESP3} {
|
||||
r HELLO 3
|
||||
$rd_sg SET key1 1
|
||||
r GET key1
|
||||
$rd_sg SET key1 2
|
||||
set res [lindex [$rd_redirection read] 2]
|
||||
assert {$res eq {key1}}
|
||||
}
|
||||
|
||||
test {RESP3 Client gets tracking-redir-broken push message after cached key changed when rediretion client is terminated} {
|
||||
r CLIENT TRACKING on REDIRECT $redir_id
|
||||
$rd_sg SET key1 1
|
||||
r GET key1
|
||||
$rd_redirection QUIT
|
||||
assert_equal OK [$rd_redirection read]
|
||||
$rd_sg SET key1 2
|
||||
set MAX_TRIES 100
|
||||
set res -1
|
||||
for {set i 0} {$i <= $MAX_TRIES && $res < 0} {incr i} {
|
||||
set res [lsearch -exact [r PING] "tracking-redir-broken"]
|
||||
}
|
||||
assert {$res >= 0}
|
||||
# Consume PING reply
|
||||
assert_equal PONG [r read]
|
||||
|
||||
# Reinstantiating after QUIT
|
||||
set rd_redirection [redis_deferring_client]
|
||||
$rd_redirection CLIENT ID
|
||||
set redir_id [$rd_redirection read]
|
||||
$rd_redirection SUBSCRIBE __redis__:invalidate
|
||||
$rd_redirection read ; # Consume the SUBSCRIBE reply
|
||||
}
|
||||
|
||||
test {Different clients can redirect to the same connection} {
|
||||
r CLIENT TRACKING on REDIRECT $redir_id
|
||||
$rd CLIENT TRACKING on REDIRECT $redir_id
|
||||
assert_equal OK [$rd read] ; # Consume the TRACKING reply
|
||||
$rd_sg MSET key1 1 key2 1
|
||||
r GET key1
|
||||
$rd GET key2
|
||||
assert_equal 1 [$rd read] ; # Consume the GET reply
|
||||
$rd_sg INCR key1
|
||||
$rd_sg INCR key2
|
||||
set res1 [lindex [$rd_redirection read] 2]
|
||||
set res2 [lindex [$rd_redirection read] 2]
|
||||
assert {$res1 eq {key1}}
|
||||
assert {$res2 eq {key2}}
|
||||
}
|
||||
|
||||
test {Different clients using different protocols can track the same key} {
|
||||
$rd HELLO 3
|
||||
set reply [$rd read] ; # Consume the HELLO reply
|
||||
assert_equal 3 [dict get $reply proto]
|
||||
$rd CLIENT TRACKING on
|
||||
assert_equal OK [$rd read] ; # Consume the TRACKING reply
|
||||
$rd_sg set key1 1
|
||||
r GET key1
|
||||
$rd GET key1
|
||||
assert_equal 1 [$rd read] ; # Consume the GET reply
|
||||
$rd_sg INCR key1
|
||||
set res1 [lindex [$rd_redirection read] 2]
|
||||
$rd PING ; # Non redirecting client has to talk to the server in order to get invalidation message
|
||||
set res2 [lindex [split [$rd read] " "] 1]
|
||||
assert_equal PONG [$rd read] ; # Consume the PING reply, which comes together with the invalidation message
|
||||
assert {$res1 eq {key1}}
|
||||
assert {$res2 eq {key1}}
|
||||
}
|
||||
|
||||
test {No invalidation message when using OPTIN option} {
|
||||
r CLIENT TRACKING on OPTIN REDIRECT $redir_id
|
||||
$rd_sg SET key1 1
|
||||
r GET key1 ; # This key should not be notified, since OPTIN is on and CLIENT CACHING yes wasn't called
|
||||
$rd_sg SET key1 2
|
||||
# Preparing some message to consume on $rd_redirection so we don't get blocked
|
||||
r CLIENT TRACKING off
|
||||
r CLIENT TRACKING on REDIRECT $redir_id
|
||||
$rd_sg SET key2 1
|
||||
r GET key2 ; # This key should be notified
|
||||
$rd_sg SET key2 2
|
||||
set res [lindex [$rd_redirection read] 2]
|
||||
assert {$res eq {key2}}
|
||||
}
|
||||
|
||||
test {Invalidation message sent when using OPTIN option with CLIENT CACHING yes} {
|
||||
r CLIENT TRACKING on OPTIN REDIRECT $redir_id
|
||||
$rd_sg SET key1 3
|
||||
r CLIENT CACHING yes
|
||||
r GET key1
|
||||
$rd_sg SET key1 4
|
||||
set res [lindex [$rd_redirection read] 2]
|
||||
assert {$res eq {key1}}
|
||||
}
|
||||
|
||||
test {Invalidation message sent when using OPTOUT option} {
|
||||
r CLIENT TRACKING off
|
||||
r CLIENT TRACKING on OPTOUT REDIRECT $redir_id
|
||||
$rd_sg SET key1 1
|
||||
r GET key1
|
||||
$rd_sg SET key1 2
|
||||
set res [lindex [$rd_redirection read] 2]
|
||||
assert {$res eq {key1}}
|
||||
}
|
||||
|
||||
test {No invalidation message when using OPTOUT option with CLIENT CACHING no} {
|
||||
$rd_sg SET key1 1
|
||||
r CLIENT CACHING no
|
||||
r GET key1 ; # This key should not be notified, since OPTOUT is on and CLIENT CACHING no was called
|
||||
$rd_sg SET key1 2
|
||||
# Preparing some message to consume on $rd_redirection so we don't get blocked
|
||||
$rd_sg SET key2 1
|
||||
r GET key2 ; # This key should be notified
|
||||
$rd_sg SET key2 2
|
||||
set res [lindex [$rd_redirection read] 2]
|
||||
assert {$res eq {key2}}
|
||||
}
|
||||
|
||||
test {Able to redirect to a RESP3 client} {
|
||||
$rd_redirection UNSUBSCRIBE __redis__:invalidate ; # Need to unsub first before we can do HELLO 3
|
||||
set res [$rd_redirection read] ; # Consume the UNSUBSCRIBE reply
|
||||
assert_equal {__redis__:invalidate} [lindex $res 1]
|
||||
$rd_redirection HELLO 3
|
||||
set res [$rd_redirection read] ; # Consume the HELLO reply
|
||||
assert_equal [dict get $reply proto] 3
|
||||
$rd_redirection SUBSCRIBE __redis__:invalidate
|
||||
set res [$rd_redirection read] ; # Consume the SUBSCRIBE reply
|
||||
assert_equal {__redis__:invalidate} [lindex $res 1]
|
||||
r CLIENT TRACKING on REDIRECT $redir_id
|
||||
$rd_sg SET key1 1
|
||||
r GET key1
|
||||
$rd_sg INCR key1
|
||||
set res [lindex [$rd_redirection read] 1]
|
||||
assert {$res eq {key1}}
|
||||
$rd_redirection HELLO 2
|
||||
set res [$rd_redirection read] ; # Consume the HELLO reply
|
||||
assert_equal [dict get $res proto] 2
|
||||
}
|
||||
|
||||
test {After switching from normal tracking to BCAST mode, no invalidation message is produced for pre-BCAST keys} {
|
||||
r CLIENT TRACKING off
|
||||
r HELLO 3
|
||||
r CLIENT TRACKING on
|
||||
$rd_sg SET key1 1
|
||||
r GET key1
|
||||
r CLIENT TRACKING off
|
||||
r CLIENT TRACKING on BCAST
|
||||
$rd_sg INCR key1
|
||||
set inv_msg [r PING]
|
||||
set ping_reply [r read]
|
||||
assert {$inv_msg eq {invalidate key1}}
|
||||
assert {$ping_reply eq {PONG}}
|
||||
}
|
||||
|
||||
test {BCAST with prefix collisions throw errors} {
|
||||
set r [redis_client]
|
||||
catch {$r CLIENT TRACKING ON BCAST PREFIX FOOBAR PREFIX FOO} output
|
||||
assert_match {ERR Prefix 'FOOBAR'*'FOO'*} $output
|
||||
|
||||
catch {$r CLIENT TRACKING ON BCAST PREFIX FOO PREFIX FOOBAR} output
|
||||
assert_match {ERR Prefix 'FOO'*'FOOBAR'*} $output
|
||||
|
||||
$r CLIENT TRACKING ON BCAST PREFIX FOO PREFIX BAR
|
||||
catch {$r CLIENT TRACKING ON BCAST PREFIX FO} output
|
||||
assert_match {ERR Prefix 'FO'*'FOO'*} $output
|
||||
|
||||
catch {$r CLIENT TRACKING ON BCAST PREFIX BARB} output
|
||||
assert_match {ERR Prefix 'BARB'*'BAR'*} $output
|
||||
|
||||
$r CLIENT TRACKING OFF
|
||||
}
|
||||
|
||||
test {Tracking gets notification on tracking table key eviction} {
|
||||
r CLIENT TRACKING off
|
||||
r CLIENT TRACKING on REDIRECT $redir NOLOOP
|
||||
r CLIENT TRACKING on REDIRECT $redir_id NOLOOP
|
||||
r MSET key1 1 key2 2
|
||||
# Let the server track the two keys for us
|
||||
r MGET key1 key2
|
||||
@@ -122,7 +367,7 @@ start_server {tags {"tracking"}} {
|
||||
# So we check that eventually we'll receive one or the other key,
|
||||
# otherwise the test will die for timeout.
|
||||
while 1 {
|
||||
set keys [lindex [$rd1 read] 2]
|
||||
set keys [lindex [$rd_redirection read] 2]
|
||||
if {$keys eq {key1} || $keys eq {key2}} break
|
||||
}
|
||||
# We should receive an expire notification for one of
|
||||
@@ -130,5 +375,190 @@ start_server {tags {"tracking"}} {
|
||||
assert {$keys eq {key1} || $keys eq {key2}}
|
||||
}
|
||||
|
||||
$rd1 close
|
||||
test {Invalidation message received for flushall} {
|
||||
clean_all
|
||||
r CLIENT TRACKING on REDIRECT $redir_id
|
||||
$rd_sg SET key1 1
|
||||
r GET key1
|
||||
$rd_sg FLUSHALL
|
||||
set msg [$rd_redirection read]
|
||||
assert {[lindex msg 2] eq {} }
|
||||
}
|
||||
|
||||
test {Invalidation message received for flushdb} {
|
||||
clean_all
|
||||
r CLIENT TRACKING on REDIRECT $redir_id
|
||||
$rd_sg SET key1 1
|
||||
r GET key1
|
||||
$rd_sg FLUSHDB
|
||||
set msg [$rd_redirection read]
|
||||
assert {[lindex msg 2] eq {} }
|
||||
}
|
||||
|
||||
# Keys are defined to be evicted 100 at a time by default.
|
||||
# If after eviction the number of keys still surpasses the limit
|
||||
# defined in tracking-table-max-keys, we increases eviction
|
||||
# effort to 200, and then 300, etc.
|
||||
# This test tests this effort incrementation.
|
||||
test {Server is able to evacuate enough keys when num of keys surpasses limit by more than defined initial effort} {
|
||||
clean_all
|
||||
set NUM_OF_KEYS_TO_TEST 250
|
||||
set TRACKING_TABLE_MAX_KEYS 1
|
||||
r CLIENT TRACKING on REDIRECT $redir_id
|
||||
for {set i 0} {$i < $NUM_OF_KEYS_TO_TEST} {incr i} {
|
||||
$rd_sg SET key$i $i
|
||||
r GET key$i
|
||||
}
|
||||
r config set tracking-table-max-keys $TRACKING_TABLE_MAX_KEYS
|
||||
# If not enough keys are evicted, we won't get enough invalidation
|
||||
# messages, and "$rd_redirection read" will block.
|
||||
# If too many keys are evicted, we will get too many invalidation
|
||||
# messages, and the assert will fail.
|
||||
for {set i 0} {$i < $NUM_OF_KEYS_TO_TEST - $TRACKING_TABLE_MAX_KEYS} {incr i} {
|
||||
$rd_redirection read
|
||||
}
|
||||
$rd_redirection PING
|
||||
assert {[$rd_redirection read] eq {pong {}}}
|
||||
}
|
||||
|
||||
test {Tracking info is correct} {
|
||||
clean_all
|
||||
r CLIENT TRACKING on REDIRECT $redir_id
|
||||
$rd_sg SET key1 1
|
||||
$rd_sg SET key2 2
|
||||
r GET key1
|
||||
r GET key2
|
||||
$rd CLIENT TRACKING on BCAST PREFIX prefix:
|
||||
assert [string match *OK* [$rd read]]
|
||||
$rd_sg SET prefix:key1 1
|
||||
$rd_sg SET prefix:key2 2
|
||||
set info [r info]
|
||||
regexp "\r\ntracking_total_items:(.*?)\r\n" $info _ total_items
|
||||
regexp "\r\ntracking_total_keys:(.*?)\r\n" $info _ total_keys
|
||||
regexp "\r\ntracking_total_prefixes:(.*?)\r\n" $info _ total_prefixes
|
||||
regexp "\r\ntracking_clients:(.*?)\r\n" $info _ tracking_clients
|
||||
assert {$total_items == 2}
|
||||
assert {$total_keys == 2}
|
||||
assert {$total_prefixes == 1}
|
||||
assert {$tracking_clients == 2}
|
||||
}
|
||||
|
||||
test {CLIENT GETREDIR provides correct client id} {
|
||||
set res [r CLIENT GETREDIR]
|
||||
assert_equal $redir_id $res
|
||||
r CLIENT TRACKING off
|
||||
set res [r CLIENT GETREDIR]
|
||||
assert_equal -1 $res
|
||||
r CLIENT TRACKING on
|
||||
set res [r CLIENT GETREDIR]
|
||||
assert_equal 0 $res
|
||||
}
|
||||
|
||||
test {CLIENT TRACKINGINFO provides reasonable results when tracking off} {
|
||||
r CLIENT TRACKING off
|
||||
set res [r client trackinginfo]
|
||||
set flags [dict get $res flags]
|
||||
assert_equal {off} $flags
|
||||
set redirect [dict get $res redirect]
|
||||
assert_equal {-1} $redirect
|
||||
set prefixes [dict get $res prefixes]
|
||||
assert_equal {} $prefixes
|
||||
}
|
||||
|
||||
test {CLIENT TRACKINGINFO provides reasonable results when tracking on} {
|
||||
r CLIENT TRACKING on
|
||||
set res [r client trackinginfo]
|
||||
set flags [dict get $res flags]
|
||||
assert_equal {on} $flags
|
||||
set redirect [dict get $res redirect]
|
||||
assert_equal {0} $redirect
|
||||
set prefixes [dict get $res prefixes]
|
||||
assert_equal {} $prefixes
|
||||
}
|
||||
|
||||
test {CLIENT TRACKINGINFO provides reasonable results when tracking on with options} {
|
||||
r CLIENT TRACKING on REDIRECT $redir_id noloop
|
||||
set res [r client trackinginfo]
|
||||
set flags [dict get $res flags]
|
||||
assert_equal {on noloop} $flags
|
||||
set redirect [dict get $res redirect]
|
||||
assert_equal $redir_id $redirect
|
||||
set prefixes [dict get $res prefixes]
|
||||
assert_equal {} $prefixes
|
||||
}
|
||||
|
||||
test {CLIENT TRACKINGINFO provides reasonable results when tracking optin} {
|
||||
r CLIENT TRACKING off
|
||||
r CLIENT TRACKING on optin
|
||||
set res [r client trackinginfo]
|
||||
set flags [dict get $res flags]
|
||||
assert_equal {on optin} $flags
|
||||
set redirect [dict get $res redirect]
|
||||
assert_equal {0} $redirect
|
||||
set prefixes [dict get $res prefixes]
|
||||
assert_equal {} $prefixes
|
||||
|
||||
r CLIENT CACHING yes
|
||||
set res [r client trackinginfo]
|
||||
set flags [dict get $res flags]
|
||||
assert_equal {on optin caching-yes} $flags
|
||||
}
|
||||
|
||||
test {CLIENT TRACKINGINFO provides reasonable results when tracking optout} {
|
||||
r CLIENT TRACKING off
|
||||
r CLIENT TRACKING on optout
|
||||
set res [r client trackinginfo]
|
||||
set flags [dict get $res flags]
|
||||
assert_equal {on optout} $flags
|
||||
set redirect [dict get $res redirect]
|
||||
assert_equal {0} $redirect
|
||||
set prefixes [dict get $res prefixes]
|
||||
assert_equal {} $prefixes
|
||||
|
||||
r CLIENT CACHING no
|
||||
set res [r client trackinginfo]
|
||||
set flags [dict get $res flags]
|
||||
assert_equal {on optout caching-no} $flags
|
||||
}
|
||||
|
||||
test {CLIENT TRACKINGINFO provides reasonable results when tracking bcast mode} {
|
||||
r CLIENT TRACKING off
|
||||
r CLIENT TRACKING on BCAST PREFIX foo PREFIX bar
|
||||
set res [r client trackinginfo]
|
||||
set flags [dict get $res flags]
|
||||
assert_equal {on bcast} $flags
|
||||
set redirect [dict get $res redirect]
|
||||
assert_equal {0} $redirect
|
||||
set prefixes [lsort [dict get $res prefixes]]
|
||||
assert_equal {bar foo} $prefixes
|
||||
|
||||
r CLIENT TRACKING off
|
||||
r CLIENT TRACKING on BCAST
|
||||
set res [r client trackinginfo]
|
||||
set prefixes [dict get $res prefixes]
|
||||
assert_equal {{}} $prefixes
|
||||
}
|
||||
|
||||
test {CLIENT TRACKINGINFO provides reasonable results when tracking redir broken} {
|
||||
clean_all
|
||||
r HELLO 3
|
||||
r CLIENT TRACKING on REDIRECT $redir_id
|
||||
$rd_sg SET key1 1
|
||||
r GET key1
|
||||
$rd_redirection QUIT
|
||||
assert_equal OK [$rd_redirection read]
|
||||
$rd_sg SET key1 2
|
||||
set res [lsearch -exact [r read] "tracking-redir-broken"]
|
||||
assert {$res >= 0}
|
||||
set res [r client trackinginfo]
|
||||
set flags [dict get $res flags]
|
||||
assert_equal {on broken_redirect} $flags
|
||||
set redirect [dict get $res redirect]
|
||||
assert_equal $redir_id $redirect
|
||||
set prefixes [dict get $res prefixes]
|
||||
assert_equal {} $prefixes
|
||||
}
|
||||
|
||||
$rd_redirection close
|
||||
$rd close
|
||||
}
|
||||
+243
-4
@@ -18,6 +18,194 @@ start_server {tags {"hash"}} {
|
||||
assert_encoding ziplist smallhash
|
||||
}
|
||||
|
||||
proc create_hash {key entries} {
|
||||
r del $key
|
||||
foreach entry $entries {
|
||||
r hset $key [lindex $entry 0] [lindex $entry 1]
|
||||
}
|
||||
}
|
||||
|
||||
proc get_keys {l} {
|
||||
set res {}
|
||||
foreach entry $l {
|
||||
set key [lindex $entry 0]
|
||||
lappend res $key
|
||||
}
|
||||
return $res
|
||||
}
|
||||
|
||||
foreach {type contents} "ziplist {{a 1} {b 2} {c 3}} hashtable {{a 1} {b 2} {[randstring 70 90 alpha] 3}}" {
|
||||
set original_max_value [lindex [r config get hash-max-ziplist-value] 1]
|
||||
r config set hash-max-ziplist-value 10
|
||||
create_hash myhash $contents
|
||||
assert_encoding $type myhash
|
||||
|
||||
test "HRANDFIELD - $type" {
|
||||
unset -nocomplain myhash
|
||||
array set myhash {}
|
||||
for {set i 0} {$i < 100} {incr i} {
|
||||
set key [r hrandfield myhash]
|
||||
set myhash($key) 1
|
||||
}
|
||||
assert_equal [lsort [get_keys $contents]] [lsort [array names myhash]]
|
||||
}
|
||||
r config set hash-max-ziplist-value $original_max_value
|
||||
}
|
||||
|
||||
test "HRANDFIELD with RESP3" {
|
||||
r hello 3
|
||||
set res [r hrandfield myhash 3 withvalues]
|
||||
assert_equal [llength $res] 3
|
||||
assert_equal [llength [lindex $res 1]] 2
|
||||
|
||||
set res [r hrandfield myhash 3]
|
||||
assert_equal [llength $res] 3
|
||||
assert_equal [llength [lindex $res 1]] 1
|
||||
}
|
||||
r hello 2
|
||||
|
||||
test "HRANDFIELD count of 0 is handled correctly" {
|
||||
r hrandfield myhash 0
|
||||
} {}
|
||||
|
||||
test "HRANDFIELD with <count> against non existing key" {
|
||||
r hrandfield nonexisting_key 100
|
||||
} {}
|
||||
|
||||
foreach {type contents} "
|
||||
hashtable {{a 1} {b 2} {c 3} {d 4} {e 5} {6 f} {7 g} {8 h} {9 i} {[randstring 70 90 alpha] 10}}
|
||||
ziplist {{a 1} {b 2} {c 3} {d 4} {e 5} {6 f} {7 g} {8 h} {9 i} {10 j}} " {
|
||||
test "HRANDFIELD with <count> - $type" {
|
||||
set original_max_value [lindex [r config get hash-max-ziplist-value] 1]
|
||||
r config set hash-max-ziplist-value 10
|
||||
create_hash myhash $contents
|
||||
assert_encoding $type myhash
|
||||
|
||||
# create a dict for easy lookup
|
||||
unset -nocomplain mydict
|
||||
foreach {k v} [r hgetall myhash] {
|
||||
dict append mydict $k $v
|
||||
}
|
||||
|
||||
# We'll stress different parts of the code, see the implementation
|
||||
# of HRANDFIELD for more information, but basically there are
|
||||
# four different code paths.
|
||||
|
||||
# PATH 1: Use negative count.
|
||||
|
||||
# 1) Check that it returns repeated elements with and without values.
|
||||
set res [r hrandfield myhash -20]
|
||||
assert_equal [llength $res] 20
|
||||
set res [r hrandfield myhash -1001]
|
||||
assert_equal [llength $res] 1001
|
||||
# again with WITHVALUES
|
||||
set res [r hrandfield myhash -20 withvalues]
|
||||
assert_equal [llength $res] 40
|
||||
set res [r hrandfield myhash -1001 withvalues]
|
||||
assert_equal [llength $res] 2002
|
||||
|
||||
# Test random uniform distribution
|
||||
set res [r hrandfield myhash -1000]
|
||||
assert_equal [check_histogram_distribution $res 0.05 0.15] true
|
||||
|
||||
# 2) Check that all the elements actually belong to the original hash.
|
||||
foreach {key val} $res {
|
||||
assert {[dict exists $mydict $key]}
|
||||
}
|
||||
|
||||
# 3) Check that eventually all the elements are returned.
|
||||
# Use both WITHVALUES and without
|
||||
unset -nocomplain auxset
|
||||
set iterations 1000
|
||||
while {$iterations != 0} {
|
||||
incr iterations -1
|
||||
if {[expr {$iterations % 2}] == 0} {
|
||||
set res [r hrandfield myhash -3 withvalues]
|
||||
foreach {key val} $res {
|
||||
dict append auxset $key $val
|
||||
}
|
||||
} else {
|
||||
set res [r hrandfield myhash -3]
|
||||
foreach key $res {
|
||||
dict append auxset $key $val
|
||||
}
|
||||
}
|
||||
if {[lsort [dict keys $mydict]] eq
|
||||
[lsort [dict keys $auxset]]} {
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert {$iterations != 0}
|
||||
|
||||
# PATH 2: positive count (unique behavior) with requested size
|
||||
# equal or greater than set size.
|
||||
foreach size {10 20} {
|
||||
set res [r hrandfield myhash $size]
|
||||
assert_equal [llength $res] 10
|
||||
assert_equal [lsort $res] [lsort [dict keys $mydict]]
|
||||
|
||||
# again with WITHVALUES
|
||||
set res [r hrandfield myhash $size withvalues]
|
||||
assert_equal [llength $res] 20
|
||||
assert_equal [lsort $res] [lsort $mydict]
|
||||
}
|
||||
|
||||
# PATH 3: Ask almost as elements as there are in the set.
|
||||
# In this case the implementation will duplicate the original
|
||||
# set and will remove random elements up to the requested size.
|
||||
#
|
||||
# PATH 4: Ask a number of elements definitely smaller than
|
||||
# the set size.
|
||||
#
|
||||
# We can test both the code paths just changing the size but
|
||||
# using the same code.
|
||||
foreach size {8 2} {
|
||||
set res [r hrandfield myhash $size]
|
||||
assert_equal [llength $res] $size
|
||||
# again with WITHVALUES
|
||||
set res [r hrandfield myhash $size withvalues]
|
||||
assert_equal [llength $res] [expr {$size * 2}]
|
||||
|
||||
# 1) Check that all the elements actually belong to the
|
||||
# original set.
|
||||
foreach ele [dict keys $res] {
|
||||
assert {[dict exists $mydict $ele]}
|
||||
}
|
||||
|
||||
# 2) Check that eventually all the elements are returned.
|
||||
# Use both WITHVALUES and without
|
||||
unset -nocomplain auxset
|
||||
unset -nocomplain allkey
|
||||
set iterations [expr {1000 / $size}]
|
||||
set all_ele_return false
|
||||
while {$iterations != 0} {
|
||||
incr iterations -1
|
||||
if {[expr {$iterations % 2}] == 0} {
|
||||
set res [r hrandfield myhash $size withvalues]
|
||||
foreach {key value} $res {
|
||||
dict append auxset $key $value
|
||||
lappend allkey $key
|
||||
}
|
||||
} else {
|
||||
set res [r hrandfield myhash $size]
|
||||
foreach key $res {
|
||||
dict append auxset $key
|
||||
lappend allkey $key
|
||||
}
|
||||
}
|
||||
if {[lsort [dict keys $mydict]] eq
|
||||
[lsort [dict keys $auxset]]} {
|
||||
set all_ele_return true
|
||||
}
|
||||
}
|
||||
assert_equal $all_ele_return true
|
||||
assert_equal [check_histogram_distribution $allkey 0.05 0.15] true
|
||||
}
|
||||
}
|
||||
r config set hash-max-ziplist-value $original_max_value
|
||||
}
|
||||
|
||||
|
||||
test {HSET/HLEN - Big hash creation} {
|
||||
array set bighash {}
|
||||
for {set i 0} {$i < 1024} {incr i} {
|
||||
@@ -302,7 +490,7 @@ start_server {tags {"hash"}} {
|
||||
r hset smallhash str " 11"
|
||||
r hset bighash str " 11"
|
||||
catch {r hincrby smallhash str 1} smallerr
|
||||
catch {r hincrby smallhash str 1} bigerr
|
||||
catch {r hincrby bighash str 1} bigerr
|
||||
set rv {}
|
||||
lappend rv [string match "ERR*not an integer*" $smallerr]
|
||||
lappend rv [string match "ERR*not an integer*" $bigerr]
|
||||
@@ -312,7 +500,7 @@ start_server {tags {"hash"}} {
|
||||
r hset smallhash str "11 "
|
||||
r hset bighash str "11 "
|
||||
catch {r hincrby smallhash str 1} smallerr
|
||||
catch {r hincrby smallhash str 1} bigerr
|
||||
catch {r hincrby bighash str 1} bigerr
|
||||
set rv {}
|
||||
lappend rv [string match "ERR*not an integer*" $smallerr]
|
||||
lappend rv [string match "ERR*not an integer*" $bigerr]
|
||||
@@ -374,7 +562,7 @@ start_server {tags {"hash"}} {
|
||||
r hset smallhash str " 11"
|
||||
r hset bighash str " 11"
|
||||
catch {r hincrbyfloat smallhash str 1} smallerr
|
||||
catch {r hincrbyfloat smallhash str 1} bigerr
|
||||
catch {r hincrbyfloat bighash str 1} bigerr
|
||||
set rv {}
|
||||
lappend rv [string match "ERR*not*float*" $smallerr]
|
||||
lappend rv [string match "ERR*not*float*" $bigerr]
|
||||
@@ -384,7 +572,7 @@ start_server {tags {"hash"}} {
|
||||
r hset smallhash str "11 "
|
||||
r hset bighash str "11 "
|
||||
catch {r hincrbyfloat smallhash str 1} smallerr
|
||||
catch {r hincrbyfloat smallhash str 1} bigerr
|
||||
catch {r hincrbyfloat bighash str 1} bigerr
|
||||
set rv {}
|
||||
lappend rv [string match "ERR*not*float*" $smallerr]
|
||||
lappend rv [string match "ERR*not*float*" $bigerr]
|
||||
@@ -572,4 +760,55 @@ start_server {tags {"hash"}} {
|
||||
assert {[r hincrbyfloat myhash float -0.1] eq {1.9}}
|
||||
}
|
||||
}
|
||||
|
||||
test {Hash ziplist of various encodings} {
|
||||
r del k
|
||||
r config set hash-max-ziplist-entries 1000000000
|
||||
r config set hash-max-ziplist-value 1000000000
|
||||
r hset k ZIP_INT_8B 127
|
||||
r hset k ZIP_INT_16B 32767
|
||||
r hset k ZIP_INT_32B 2147483647
|
||||
r hset k ZIP_INT_64B 9223372036854775808
|
||||
r hset k ZIP_INT_IMM_MIN 0
|
||||
r hset k ZIP_INT_IMM_MAX 12
|
||||
r hset k ZIP_STR_06B [string repeat x 31]
|
||||
r hset k ZIP_STR_14B [string repeat x 8191]
|
||||
r hset k ZIP_STR_32B [string repeat x 65535]
|
||||
set k [r hgetall k]
|
||||
set dump [r dump k]
|
||||
|
||||
# will be converted to dict at RESTORE
|
||||
r config set hash-max-ziplist-entries 2
|
||||
r config set sanitize-dump-payload no
|
||||
r restore kk 0 $dump
|
||||
set kk [r hgetall kk]
|
||||
|
||||
# make sure the values are right
|
||||
assert_equal [lsort $k] [lsort $kk]
|
||||
assert_equal [dict get $k ZIP_STR_06B] [string repeat x 31]
|
||||
set k [dict remove $k ZIP_STR_06B]
|
||||
assert_equal [dict get $k ZIP_STR_14B] [string repeat x 8191]
|
||||
set k [dict remove $k ZIP_STR_14B]
|
||||
assert_equal [dict get $k ZIP_STR_32B] [string repeat x 65535]
|
||||
set k [dict remove $k ZIP_STR_32B]
|
||||
set _ $k
|
||||
} {ZIP_INT_8B 127 ZIP_INT_16B 32767 ZIP_INT_32B 2147483647 ZIP_INT_64B 9223372036854775808 ZIP_INT_IMM_MIN 0 ZIP_INT_IMM_MAX 12}
|
||||
|
||||
test {Hash ziplist of various encodings - sanitize dump} {
|
||||
r config set sanitize-dump-payload yes
|
||||
r restore kk 0 $dump replace
|
||||
set k [r hgetall k]
|
||||
set kk [r hgetall kk]
|
||||
|
||||
# make sure the values are right
|
||||
assert_equal [lsort $k] [lsort $kk]
|
||||
assert_equal [dict get $k ZIP_STR_06B] [string repeat x 31]
|
||||
set k [dict remove $k ZIP_STR_06B]
|
||||
assert_equal [dict get $k ZIP_STR_14B] [string repeat x 8191]
|
||||
set k [dict remove $k ZIP_STR_14B]
|
||||
assert_equal [dict get $k ZIP_STR_32B] [string repeat x 65535]
|
||||
set k [dict remove $k ZIP_STR_32B]
|
||||
set _ $k
|
||||
} {ZIP_INT_8B 127 ZIP_INT_16B 32767 ZIP_INT_32B 2147483647 ZIP_INT_64B 9223372036854775808 ZIP_INT_IMM_MIN 0 ZIP_INT_IMM_MAX 12}
|
||||
|
||||
}
|
||||
@@ -29,11 +29,11 @@ start_server {
|
||||
set max [expr {$min+int(rand()*$startlen)}]
|
||||
set before_len [llength $mylist]
|
||||
set before_len_r [r llen mylist]
|
||||
assert_equal $before_len $before_len_r
|
||||
set mylist [lrange $mylist $min $max]
|
||||
r ltrim mylist $min $max
|
||||
assert_equal $mylist [r lrange mylist 0 -1] "failed trim"
|
||||
|
||||
set starting [r llen mylist]
|
||||
for {set j [r llen mylist]} {$j < $startlen} {incr j} {
|
||||
set str [randomInt 9223372036854775807]
|
||||
r rpush mylist $str
|
||||
|
||||
+287
-20
@@ -1,3 +1,11 @@
|
||||
proc wait_for_blocked_client {} {
|
||||
wait_for_condition 50 100 {
|
||||
[s blocked_clients] ne 0
|
||||
} else {
|
||||
fail "no blocked clients"
|
||||
}
|
||||
}
|
||||
|
||||
# Setting server-threads to 2 is really single threaded because test mode is enabled (no client allocated to thread 1)
|
||||
# We do this because of the large numbers of nonblocking clients in this tests and the client races that causes
|
||||
start_server {
|
||||
@@ -55,7 +63,7 @@ start_server {
|
||||
|
||||
test {LPOS when RANK is greater than matches} {
|
||||
r DEL mylist
|
||||
r LPUSH l a
|
||||
r LPUSH mylist a
|
||||
assert {[r LPOS mylist b COUNT 10 RANK 5] eq {}}
|
||||
}
|
||||
|
||||
@@ -118,6 +126,17 @@ start_server {
|
||||
test {R/LPOP against empty list} {
|
||||
r lpop non-existing-list
|
||||
} {}
|
||||
|
||||
test {R/LPOP with the optional count argument} {
|
||||
assert_equal 7 [r lpush listcount aa bb cc dd ee ff gg]
|
||||
assert_equal {} [r lpop listcount 0]
|
||||
assert_equal {gg} [r lpop listcount 1]
|
||||
assert_equal {ff ee} [r lpop listcount 2]
|
||||
assert_equal {aa bb} [r rpop listcount 2]
|
||||
assert_equal {cc} [r rpop listcount 1]
|
||||
assert_equal {dd} [r rpop listcount 123]
|
||||
assert_error "*ERR*range*" {r lpop forbarqaz -123}
|
||||
}
|
||||
|
||||
test {Variadic RPUSH/LPUSH} {
|
||||
r del mylist
|
||||
@@ -189,6 +208,7 @@ start_server {
|
||||
|
||||
test "BRPOPLPUSH - $type" {
|
||||
r del target
|
||||
r rpush target bar
|
||||
|
||||
set rd [redis_deferring_client]
|
||||
create_list blist "a b $large c d"
|
||||
@@ -196,9 +216,38 @@ start_server {
|
||||
$rd brpoplpush blist target 1
|
||||
assert_equal d [$rd read]
|
||||
|
||||
assert_equal d [r rpop target]
|
||||
assert_equal d [r lpop target]
|
||||
assert_equal "a b $large c" [r lrange blist 0 -1]
|
||||
}
|
||||
|
||||
foreach wherefrom {left right} {
|
||||
foreach whereto {left right} {
|
||||
test "BLMOVE $wherefrom $whereto - $type" {
|
||||
r del target
|
||||
r rpush target bar
|
||||
|
||||
set rd [redis_deferring_client]
|
||||
create_list blist "a b $large c d"
|
||||
|
||||
$rd blmove blist target $wherefrom $whereto 1
|
||||
set poppedelement [$rd read]
|
||||
|
||||
if {$wherefrom eq "right"} {
|
||||
assert_equal d $poppedelement
|
||||
assert_equal "a b $large c" [r lrange blist 0 -1]
|
||||
} else {
|
||||
assert_equal a $poppedelement
|
||||
assert_equal "b $large c d" [r lrange blist 0 -1]
|
||||
}
|
||||
|
||||
if {$whereto eq "right"} {
|
||||
assert_equal $poppedelement [r rpop target]
|
||||
} else {
|
||||
assert_equal $poppedelement [r lpop target]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
test "BLPOP, LPUSH + DEL should not awake blocked client" {
|
||||
@@ -220,6 +269,8 @@ start_server {
|
||||
r del list
|
||||
|
||||
$rd blpop list 0
|
||||
after 100 ;# Make sure rd is blocked before MULTI
|
||||
|
||||
r multi
|
||||
r lpush list a
|
||||
r del list
|
||||
@@ -278,24 +329,60 @@ start_server {
|
||||
test "BRPOPLPUSH with zero timeout should block indefinitely" {
|
||||
set rd [redis_deferring_client]
|
||||
r del blist target
|
||||
r rpush target bar
|
||||
$rd brpoplpush blist target 0
|
||||
after 1000
|
||||
wait_for_condition 100 10 {
|
||||
[s blocked_clients] == 1
|
||||
} else {
|
||||
fail "Timeout waiting for blocked clients"
|
||||
}
|
||||
r rpush blist foo
|
||||
assert_equal foo [$rd read]
|
||||
assert_equal {foo} [r lrange target 0 -1]
|
||||
assert_equal {foo bar} [r lrange target 0 -1]
|
||||
}
|
||||
|
||||
test "BRPOPLPUSH with a client BLPOPing the target list" {
|
||||
set rd [redis_deferring_client]
|
||||
set rd2 [redis_deferring_client]
|
||||
r del blist target
|
||||
$rd2 blpop target 0
|
||||
$rd brpoplpush blist target 0
|
||||
after 1000
|
||||
r rpush blist foo
|
||||
assert_equal foo [$rd read]
|
||||
assert_equal {target foo} [$rd2 read]
|
||||
assert_equal 0 [r exists target]
|
||||
foreach wherefrom {left right} {
|
||||
foreach whereto {left right} {
|
||||
test "BLMOVE $wherefrom $whereto with zero timeout should block indefinitely" {
|
||||
set rd [redis_deferring_client]
|
||||
r del blist target
|
||||
r rpush target bar
|
||||
$rd blmove blist target $wherefrom $whereto 0
|
||||
wait_for_condition 100 10 {
|
||||
[s blocked_clients] == 1
|
||||
} else {
|
||||
fail "Timeout waiting for blocked clients"
|
||||
}
|
||||
r rpush blist foo
|
||||
assert_equal foo [$rd read]
|
||||
if {$whereto eq "right"} {
|
||||
assert_equal {bar foo} [r lrange target 0 -1]
|
||||
} else {
|
||||
assert_equal {foo bar} [r lrange target 0 -1]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach wherefrom {left right} {
|
||||
foreach whereto {left right} {
|
||||
test "BLMOVE ($wherefrom, $whereto) with a client BLPOPing the target list" {
|
||||
set rd [redis_deferring_client]
|
||||
set rd2 [redis_deferring_client]
|
||||
r del blist target
|
||||
$rd2 blpop target 0
|
||||
$rd blmove blist target $wherefrom $whereto 0
|
||||
wait_for_condition 100 10 {
|
||||
[s blocked_clients] == 2
|
||||
} else {
|
||||
fail "Timeout waiting for blocked clients"
|
||||
}
|
||||
r rpush blist foo
|
||||
assert_equal foo [$rd read]
|
||||
assert_equal {target foo} [$rd2 read]
|
||||
assert_equal 0 [r exists target]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
test "BRPOPLPUSH with wrong source type" {
|
||||
@@ -318,7 +405,11 @@ start_server {
|
||||
r del blist target
|
||||
r set target nolist
|
||||
$rd brpoplpush blist target 0
|
||||
after 1000
|
||||
wait_for_condition 100 10 {
|
||||
[s blocked_clients] == 1
|
||||
} else {
|
||||
fail "Timeout waiting for blocked clients"
|
||||
}
|
||||
r rpush blist foo
|
||||
assert_error "WRONGTYPE*" {$rd read}
|
||||
assert_equal {foo} [r lrange blist 0 -1]
|
||||
@@ -348,14 +439,14 @@ start_server {
|
||||
assert_equal {foo} [r lrange target2 0 -1]
|
||||
}
|
||||
|
||||
test "Linked BRPOPLPUSH" {
|
||||
test "Linked LMOVEs" {
|
||||
set rd1 [redis_deferring_client]
|
||||
set rd2 [redis_deferring_client]
|
||||
|
||||
r del list1 list2 list3
|
||||
|
||||
$rd1 brpoplpush list1 list2 0
|
||||
$rd2 brpoplpush list2 list3 0
|
||||
$rd1 blmove list1 list2 right left 0
|
||||
$rd2 blmove list2 list3 left right 0
|
||||
|
||||
r rpush list1 foo
|
||||
|
||||
@@ -444,7 +535,16 @@ start_server {
|
||||
set rd [redis_deferring_client]
|
||||
|
||||
$rd brpoplpush foo_list bar_list 1
|
||||
after 2000
|
||||
wait_for_condition 100 10 {
|
||||
[s blocked_clients] == 1
|
||||
} else {
|
||||
fail "Timeout waiting for blocked client"
|
||||
}
|
||||
wait_for_condition 500 10 {
|
||||
[s blocked_clients] == 0
|
||||
} else {
|
||||
fail "Timeout waiting for client to unblock"
|
||||
}
|
||||
$rd read
|
||||
} {}
|
||||
|
||||
@@ -669,6 +769,29 @@ start_server {
|
||||
assert_encoding quicklist mylist2
|
||||
}
|
||||
|
||||
foreach wherefrom {left right} {
|
||||
foreach whereto {left right} {
|
||||
test "LMOVE $wherefrom $whereto base case - $type" {
|
||||
r del mylist1 mylist2
|
||||
|
||||
if {$wherefrom eq "right"} {
|
||||
create_list mylist1 "c d $large a"
|
||||
} else {
|
||||
create_list mylist1 "a $large c d"
|
||||
}
|
||||
assert_equal a [r lmove mylist1 mylist2 $wherefrom $whereto]
|
||||
assert_equal $large [r lmove mylist1 mylist2 $wherefrom $whereto]
|
||||
assert_equal "c d" [r lrange mylist1 0 -1]
|
||||
if {$whereto eq "right"} {
|
||||
assert_equal "a $large" [r lrange mylist2 0 -1]
|
||||
} else {
|
||||
assert_equal "$large a" [r lrange mylist2 0 -1]
|
||||
}
|
||||
assert_encoding quicklist mylist2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
test "RPOPLPUSH with the same list as src and dst - $type" {
|
||||
create_list mylist "a $large c"
|
||||
assert_equal "a $large c" [r lrange mylist 0 -1]
|
||||
@@ -676,6 +799,26 @@ start_server {
|
||||
assert_equal "c a $large" [r lrange mylist 0 -1]
|
||||
}
|
||||
|
||||
foreach wherefrom {left right} {
|
||||
foreach whereto {left right} {
|
||||
test "LMOVE $wherefrom $whereto with the same list as src and dst - $type" {
|
||||
if {$wherefrom eq "right"} {
|
||||
create_list mylist "a $large c"
|
||||
assert_equal "a $large c" [r lrange mylist 0 -1]
|
||||
} else {
|
||||
create_list mylist "c a $large"
|
||||
assert_equal "c a $large" [r lrange mylist 0 -1]
|
||||
}
|
||||
assert_equal c [r lmove mylist mylist $wherefrom $whereto]
|
||||
if {$whereto eq "right"} {
|
||||
assert_equal "a $large c" [r lrange mylist 0 -1]
|
||||
} else {
|
||||
assert_equal "c a $large" [r lrange mylist 0 -1]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach {othertype otherlarge} [array get largevalue] {
|
||||
test "RPOPLPUSH with $type source and existing target $othertype" {
|
||||
create_list srclist "a b c $large"
|
||||
@@ -691,6 +834,35 @@ start_server {
|
||||
assert_encoding quicklist dstlist
|
||||
}
|
||||
}
|
||||
|
||||
foreach wherefrom {left right} {
|
||||
foreach whereto {left right} {
|
||||
test "LMOVE $wherefrom $whereto with $type source and existing target $othertype" {
|
||||
create_list dstlist "$otherlarge"
|
||||
|
||||
if {$wherefrom eq "right"} {
|
||||
create_list srclist "a b c $large"
|
||||
} else {
|
||||
create_list srclist "$large c a b"
|
||||
}
|
||||
assert_equal $large [r lmove srclist dstlist $wherefrom $whereto]
|
||||
assert_equal c [r lmove srclist dstlist $wherefrom $whereto]
|
||||
assert_equal "a b" [r lrange srclist 0 -1]
|
||||
|
||||
if {$whereto eq "right"} {
|
||||
assert_equal "$otherlarge $large c" [r lrange dstlist 0 -1]
|
||||
} else {
|
||||
assert_equal "c $large $otherlarge" [r lrange dstlist 0 -1]
|
||||
}
|
||||
|
||||
# When we lmoved a large value, dstlist should be
|
||||
# converted to the same encoding as srclist.
|
||||
if {$type eq "linkedlist"} {
|
||||
assert_encoding quicklist dstlist
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -789,6 +961,12 @@ start_server {
|
||||
assert_equal {} [r lrange nosuchkey 0 1]
|
||||
}
|
||||
|
||||
test {LRANGE with start > end yields an empty array for backward compatibility} {
|
||||
create_list mylist "1 2 3"
|
||||
assert_equal {} [r lrange mylist 1 0]
|
||||
assert_equal {} [r lrange mylist -1 -2]
|
||||
}
|
||||
|
||||
foreach {type large} [array get largevalue] {
|
||||
proc trim_list {type min max} {
|
||||
upvar 1 large large
|
||||
@@ -890,4 +1068,93 @@ start_server {
|
||||
$rd2 close
|
||||
r ping
|
||||
} {PONG}
|
||||
|
||||
test "client unblock tests" {
|
||||
r del l
|
||||
set rd [redis_deferring_client]
|
||||
$rd client id
|
||||
set id [$rd read]
|
||||
|
||||
# test default args
|
||||
$rd blpop l 0
|
||||
wait_for_blocked_client
|
||||
r client unblock $id
|
||||
assert_equal {} [$rd read]
|
||||
|
||||
# test with timeout
|
||||
$rd blpop l 0
|
||||
wait_for_blocked_client
|
||||
r client unblock $id TIMEOUT
|
||||
assert_equal {} [$rd read]
|
||||
|
||||
# test with error
|
||||
$rd blpop l 0
|
||||
wait_for_blocked_client
|
||||
r client unblock $id ERROR
|
||||
catch {[$rd read]} e
|
||||
assert_equal $e "UNBLOCKED client unblocked via CLIENT UNBLOCK"
|
||||
|
||||
# test with invalid client id
|
||||
catch {[r client unblock asd]} e
|
||||
assert_equal $e "ERR value is not an integer or out of range"
|
||||
|
||||
# test with non blocked client
|
||||
set myid [r client id]
|
||||
catch {[r client unblock $myid]} e
|
||||
assert_equal $e {invalid command name "0"}
|
||||
|
||||
# finally, see the this client and list are still functional
|
||||
$rd blpop l 0
|
||||
wait_for_blocked_client
|
||||
r lpush l foo
|
||||
assert_equal {l foo} [$rd read]
|
||||
} {}
|
||||
|
||||
test {List ziplist of various encodings} {
|
||||
r del k
|
||||
r lpush k 127 ;# ZIP_INT_8B
|
||||
r lpush k 32767 ;# ZIP_INT_16B
|
||||
r lpush k 2147483647 ;# ZIP_INT_32B
|
||||
r lpush k 9223372036854775808 ;# ZIP_INT_64B
|
||||
r lpush k 0 ;# ZIP_INT_IMM_MIN
|
||||
r lpush k 12 ;# ZIP_INT_IMM_MAX
|
||||
r lpush k [string repeat x 31] ;# ZIP_STR_06B
|
||||
r lpush k [string repeat x 8191] ;# ZIP_STR_14B
|
||||
r lpush k [string repeat x 65535] ;# ZIP_STR_32B
|
||||
set k [r lrange k 0 -1]
|
||||
set dump [r dump k]
|
||||
|
||||
r config set sanitize-dump-payload no
|
||||
r restore kk 0 $dump
|
||||
set kk [r lrange kk 0 -1]
|
||||
|
||||
# try some forward and backward searches to make sure all encodings
|
||||
# can be traversed
|
||||
assert_equal [r lindex kk 5] {9223372036854775808}
|
||||
assert_equal [r lindex kk -5] {0}
|
||||
assert_equal [r lpos kk foo rank 1] {}
|
||||
assert_equal [r lpos kk foo rank -1] {}
|
||||
|
||||
# make sure the values are right
|
||||
assert_equal $k $kk
|
||||
assert_equal [lpop k] [string repeat x 65535]
|
||||
assert_equal [lpop k] [string repeat x 8191]
|
||||
assert_equal [lpop k] [string repeat x 31]
|
||||
set _ $k
|
||||
} {12 0 9223372036854775808 2147483647 32767 127}
|
||||
|
||||
test {List ziplist of various encodings - sanitize dump} {
|
||||
r config set sanitize-dump-payload yes
|
||||
r restore kk 0 $dump replace
|
||||
set k [r lrange k 0 -1]
|
||||
set kk [r lrange kk 0 -1]
|
||||
|
||||
# make sure the values are right
|
||||
assert_equal $k $kk
|
||||
assert_equal [lpop k] [string repeat x 65535]
|
||||
assert_equal [lpop k] [string repeat x 8191]
|
||||
assert_equal [lpop k] [string repeat x 31]
|
||||
set _ $k
|
||||
} {12 0 9223372036854775808 2147483647 32767 127}
|
||||
|
||||
}
|
||||
+70
-3
@@ -9,7 +9,7 @@ start_server {
|
||||
foreach entry $entries { r sadd $key $entry }
|
||||
}
|
||||
|
||||
test {SADD, SCARD, SISMEMBER, SMEMBERS basics - regular set} {
|
||||
test {SADD, SCARD, SISMEMBER, SMISMEMBER, SMEMBERS basics - regular set} {
|
||||
create_set myset {foo}
|
||||
assert_encoding hashtable myset
|
||||
assert_equal 1 [r sadd myset bar]
|
||||
@@ -18,10 +18,15 @@ start_server {
|
||||
assert_equal 1 [r sismember myset foo]
|
||||
assert_equal 1 [r sismember myset bar]
|
||||
assert_equal 0 [r sismember myset bla]
|
||||
assert_equal {1} [r smismember myset foo]
|
||||
assert_equal {1 1} [r smismember myset foo bar]
|
||||
assert_equal {1 0} [r smismember myset foo bla]
|
||||
assert_equal {0 1} [r smismember myset bla foo]
|
||||
assert_equal {0} [r smismember myset bla]
|
||||
assert_equal {bar foo} [lsort [r smembers myset]]
|
||||
}
|
||||
|
||||
test {SADD, SCARD, SISMEMBER, SMEMBERS basics - intset} {
|
||||
test {SADD, SCARD, SISMEMBER, SMISMEMBER, SMEMBERS basics - intset} {
|
||||
create_set myset {17}
|
||||
assert_encoding intset myset
|
||||
assert_equal 1 [r sadd myset 16]
|
||||
@@ -30,9 +35,33 @@ start_server {
|
||||
assert_equal 1 [r sismember myset 16]
|
||||
assert_equal 1 [r sismember myset 17]
|
||||
assert_equal 0 [r sismember myset 18]
|
||||
assert_equal {1} [r smismember myset 16]
|
||||
assert_equal {1 1} [r smismember myset 16 17]
|
||||
assert_equal {1 0} [r smismember myset 16 18]
|
||||
assert_equal {0 1} [r smismember myset 18 16]
|
||||
assert_equal {0} [r smismember myset 18]
|
||||
assert_equal {16 17} [lsort [r smembers myset]]
|
||||
}
|
||||
|
||||
test {SMISMEMBER against non set} {
|
||||
r lpush mylist foo
|
||||
assert_error WRONGTYPE* {r smismember mylist bar}
|
||||
}
|
||||
|
||||
test {SMISMEMBER non existing key} {
|
||||
assert_equal {0} [r smismember myset1 foo]
|
||||
assert_equal {0 0} [r smismember myset1 foo bar]
|
||||
}
|
||||
|
||||
test {SMISMEMBER requires one or more members} {
|
||||
r del zmscoretest
|
||||
r zadd zmscoretest 10 x
|
||||
r zadd zmscoretest 20 y
|
||||
|
||||
catch {r smismember zmscoretest} e
|
||||
assert_match {*ERR*wrong*number*arg*} $e
|
||||
}
|
||||
|
||||
test {SADD against non set} {
|
||||
r lpush mylist foo
|
||||
assert_error WRONGTYPE* {r sadd mylist bar}
|
||||
@@ -49,6 +78,7 @@ start_server {
|
||||
create_set myset {213244124402402314402033402}
|
||||
assert_encoding hashtable myset
|
||||
assert_equal 1 [r sismember myset 213244124402402314402033402]
|
||||
assert_equal {1} [r smismember myset 213244124402402314402033402]
|
||||
}
|
||||
|
||||
test "SADD overflows the maximum allowed integers in an intset" {
|
||||
@@ -471,7 +501,7 @@ start_server {
|
||||
set iterations 1000
|
||||
while {$iterations != 0} {
|
||||
incr iterations -1
|
||||
set res [r srandmember myset -10]
|
||||
set res [r srandmember myset $size]
|
||||
foreach ele $res {
|
||||
set auxset($ele) 1
|
||||
}
|
||||
@@ -485,6 +515,43 @@ start_server {
|
||||
}
|
||||
}
|
||||
|
||||
foreach {type contents} {
|
||||
hashtable {
|
||||
1 5 10 50 125
|
||||
MARY PATRICIA LINDA BARBARA ELIZABETH
|
||||
}
|
||||
intset {
|
||||
0 1 2 3 4 5 6 7 8 9
|
||||
}
|
||||
} {
|
||||
test "SRANDMEMBER histogram distribution - $type" {
|
||||
create_set myset $contents
|
||||
unset -nocomplain myset
|
||||
array set myset {}
|
||||
foreach ele [r smembers myset] {
|
||||
set myset($ele) 1
|
||||
}
|
||||
|
||||
# Use negative count (PATH 1).
|
||||
set res [r srandmember myset -1000]
|
||||
assert_equal [check_histogram_distribution $res 0.05 0.15] true
|
||||
|
||||
# Use positive count (both PATH 3 and PATH 4).
|
||||
foreach size {8 2} {
|
||||
unset -nocomplain allkey
|
||||
set iterations [expr {1000 / $size}]
|
||||
while {$iterations != 0} {
|
||||
incr iterations -1
|
||||
set res [r srandmember myset $size]
|
||||
foreach ele $res {
|
||||
lappend allkey $ele
|
||||
}
|
||||
}
|
||||
assert_equal [check_histogram_distribution $allkey 0.05 0.15] true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
proc setup_move {} {
|
||||
r del myset3 myset4
|
||||
create_set myset1 {1 a b}
|
||||
|
||||
@@ -27,7 +27,7 @@ start_server {
|
||||
# and not the element "foo bar" which was pre existing in the
|
||||
# stream (see previous test)
|
||||
set reply [
|
||||
r XREADGROUP GROUP mygroup client-1 STREAMS mystream ">"
|
||||
r XREADGROUP GROUP mygroup consumer-1 STREAMS mystream ">"
|
||||
]
|
||||
assert {[llength [lindex $reply 0 1]] == 2}
|
||||
lindex $reply 0 1 0 1
|
||||
@@ -39,13 +39,13 @@ start_server {
|
||||
r XADD mystream * d 4
|
||||
# Read a few elements using a different consumer name
|
||||
set reply [
|
||||
r XREADGROUP GROUP mygroup client-2 STREAMS mystream ">"
|
||||
r XREADGROUP GROUP mygroup consumer-2 STREAMS mystream ">"
|
||||
]
|
||||
assert {[llength [lindex $reply 0 1]] == 2}
|
||||
assert {[lindex $reply 0 1 0 1] eq {c 3}}
|
||||
|
||||
set r1 [r XREADGROUP GROUP mygroup client-1 COUNT 10 STREAMS mystream 0]
|
||||
set r2 [r XREADGROUP GROUP mygroup client-2 COUNT 10 STREAMS mystream 0]
|
||||
set r1 [r XREADGROUP GROUP mygroup consumer-1 COUNT 10 STREAMS mystream 0]
|
||||
set r2 [r XREADGROUP GROUP mygroup consumer-2 COUNT 10 STREAMS mystream 0]
|
||||
assert {[lindex $r1 0 1 0 1] eq {a 1}}
|
||||
assert {[lindex $r2 0 1 0 1] eq {c 3}}
|
||||
}
|
||||
@@ -56,9 +56,9 @@ start_server {
|
||||
for {set j 0} {$j < 4} {incr j} {
|
||||
set item [lindex $pending $j]
|
||||
if {$j < 2} {
|
||||
set owner client-1
|
||||
set owner consumer-1
|
||||
} else {
|
||||
set owner client-2
|
||||
set owner consumer-2
|
||||
}
|
||||
assert {[lindex $item 1] eq $owner}
|
||||
assert {[lindex $item 1] eq $owner}
|
||||
@@ -66,16 +66,47 @@ start_server {
|
||||
}
|
||||
|
||||
test {XPENDING can return single consumer items} {
|
||||
set pending [r XPENDING mystream mygroup - + 10 client-1]
|
||||
set pending [r XPENDING mystream mygroup - + 10 consumer-1]
|
||||
assert {[llength $pending] == 2}
|
||||
}
|
||||
|
||||
test {XACK is able to remove items from the client/group PEL} {
|
||||
set pending [r XPENDING mystream mygroup - + 10 client-1]
|
||||
test {XPENDING only group} {
|
||||
set pending [r XPENDING mystream mygroup]
|
||||
assert {[llength $pending] == 4}
|
||||
}
|
||||
|
||||
test {XPENDING with IDLE} {
|
||||
after 20
|
||||
set pending [r XPENDING mystream mygroup IDLE 99999999 - + 10 consumer-1]
|
||||
assert {[llength $pending] == 0}
|
||||
set pending [r XPENDING mystream mygroup IDLE 1 - + 10 consumer-1]
|
||||
assert {[llength $pending] == 2}
|
||||
set pending [r XPENDING mystream mygroup IDLE 99999999 - + 10]
|
||||
assert {[llength $pending] == 0}
|
||||
set pending [r XPENDING mystream mygroup IDLE 1 - + 10]
|
||||
assert {[llength $pending] == 4}
|
||||
}
|
||||
|
||||
test {XPENDING with exclusive range intervals works as expected} {
|
||||
set pending [r XPENDING mystream mygroup - + 10]
|
||||
assert {[llength $pending] == 4}
|
||||
set startid [lindex [lindex $pending 0] 0]
|
||||
set endid [lindex [lindex $pending 3] 0]
|
||||
set expending [r XPENDING mystream mygroup ($startid ($endid 10]
|
||||
assert {[llength $expending] == 2}
|
||||
for {set j 0} {$j < 2} {incr j} {
|
||||
set itemid [lindex [lindex $expending $j] 0]
|
||||
assert {$itemid ne $startid}
|
||||
assert {$itemid ne $endid}
|
||||
}
|
||||
}
|
||||
|
||||
test {XACK is able to remove items from the consumer/group PEL} {
|
||||
set pending [r XPENDING mystream mygroup - + 10 consumer-1]
|
||||
set id1 [lindex $pending 0 0]
|
||||
set id2 [lindex $pending 1 0]
|
||||
assert {[r XACK mystream mygroup $id1] eq 1}
|
||||
set pending [r XPENDING mystream mygroup - + 10 client-1]
|
||||
set pending [r XPENDING mystream mygroup - + 10 consumer-1]
|
||||
assert {[llength $pending] == 1}
|
||||
set id [lindex $pending 0 0]
|
||||
assert {$id eq $id2}
|
||||
@@ -211,41 +242,52 @@ start_server {
|
||||
set id3 [r XADD mystream * c 3]
|
||||
r XGROUP CREATE mystream mygroup 0
|
||||
|
||||
# Client 1 reads item 1 from the stream without acknowledgements.
|
||||
# Client 2 then claims pending item 1 from the PEL of client 1
|
||||
# Consumer 1 reads item 1 from the stream without acknowledgements.
|
||||
# Consumer 2 then claims pending item 1 from the PEL of consumer 1
|
||||
set reply [
|
||||
r XREADGROUP GROUP mygroup client1 count 1 STREAMS mystream >
|
||||
r XREADGROUP GROUP mygroup consumer1 count 1 STREAMS mystream >
|
||||
]
|
||||
assert {[llength [lindex $reply 0 1 0 1]] == 2}
|
||||
assert {[lindex $reply 0 1 0 1] eq {a 1}}
|
||||
r debug sleep 0.2
|
||||
|
||||
# make sure the entry is present in both the gorup, and the right consumer
|
||||
assert {[llength [r XPENDING mystream mygroup - + 10]] == 1}
|
||||
assert {[llength [r XPENDING mystream mygroup - + 10 consumer1]] == 1}
|
||||
assert {[llength [r XPENDING mystream mygroup - + 10 consumer2]] == 0}
|
||||
|
||||
after 200
|
||||
set reply [
|
||||
r XCLAIM mystream mygroup client2 10 $id1
|
||||
r XCLAIM mystream mygroup consumer2 10 $id1
|
||||
]
|
||||
assert {[llength [lindex $reply 0 1]] == 2}
|
||||
assert {[lindex $reply 0 1] eq {a 1}}
|
||||
|
||||
# Client 1 reads another 2 items from stream
|
||||
r XREADGROUP GROUP mygroup client1 count 2 STREAMS mystream >
|
||||
r debug sleep 0.2
|
||||
# make sure the entry is present in both the gorup, and the right consumer
|
||||
assert {[llength [r XPENDING mystream mygroup - + 10]] == 1}
|
||||
assert {[llength [r XPENDING mystream mygroup - + 10 consumer1]] == 0}
|
||||
assert {[llength [r XPENDING mystream mygroup - + 10 consumer2]] == 1}
|
||||
|
||||
# Delete item 2 from the stream. Now client 1 has PEL that contains
|
||||
# only item 3. Try to use client 2 to claim the deleted item 2
|
||||
# from the PEL of client 1, this should return nil
|
||||
# Consumer 1 reads another 2 items from stream
|
||||
r XREADGROUP GROUP mygroup consumer1 count 2 STREAMS mystream >
|
||||
after 200
|
||||
|
||||
# Delete item 2 from the stream. Now consumer 1 has PEL that contains
|
||||
# only item 3. Try to use consumer 2 to claim the deleted item 2
|
||||
# from the PEL of consumer 1, this should return nil
|
||||
r XDEL mystream $id2
|
||||
set reply [
|
||||
r XCLAIM mystream mygroup client2 10 $id2
|
||||
r XCLAIM mystream mygroup consumer2 10 $id2
|
||||
]
|
||||
assert {[llength $reply] == 1}
|
||||
assert_equal "" [lindex $reply 0]
|
||||
|
||||
# Delete item 3 from the stream. Now client 1 has PEL that is empty.
|
||||
# Try to use client 2 to claim the deleted item 3 from the PEL
|
||||
# of client 1, this should return nil
|
||||
r debug sleep 0.2
|
||||
# Delete item 3 from the stream. Now consumer 1 has PEL that is empty.
|
||||
# Try to use consumer 2 to claim the deleted item 3 from the PEL
|
||||
# of consumer 1, this should return nil
|
||||
after 200
|
||||
r XDEL mystream $id3
|
||||
set reply [
|
||||
r XCLAIM mystream mygroup client2 10 $id3
|
||||
r XCLAIM mystream mygroup consumer2 10 $id3
|
||||
]
|
||||
assert {[llength $reply] == 1}
|
||||
assert_equal "" [lindex $reply 0]
|
||||
@@ -259,16 +301,16 @@ start_server {
|
||||
set id3 [r XADD mystream * c 3]
|
||||
r XGROUP CREATE mystream mygroup 0
|
||||
|
||||
# Client 1 reads item 1 from the stream without acknowledgements.
|
||||
# Client 2 then claims pending item 1 from the PEL of client 1
|
||||
# Consumer 1 reads item 1 from the stream without acknowledgements.
|
||||
# Consumer 2 then claims pending item 1 from the PEL of consumer 1
|
||||
set reply [
|
||||
r XREADGROUP GROUP mygroup client1 count 1 STREAMS mystream >
|
||||
r XREADGROUP GROUP mygroup consumer1 count 1 STREAMS mystream >
|
||||
]
|
||||
assert {[llength [lindex $reply 0 1 0 1]] == 2}
|
||||
assert {[lindex $reply 0 1 0 1] eq {a 1}}
|
||||
r debug sleep 0.2
|
||||
after 200
|
||||
set reply [
|
||||
r XCLAIM mystream mygroup client2 10 $id1
|
||||
r XCLAIM mystream mygroup consumer2 10 $id1
|
||||
]
|
||||
assert {[llength [lindex $reply 0 1]] == 2}
|
||||
assert {[lindex $reply 0 1] eq {a 1}}
|
||||
@@ -279,10 +321,10 @@ start_server {
|
||||
assert {[llength [lindex $reply 0]] == 4}
|
||||
assert {[lindex $reply 0 3] == 2}
|
||||
|
||||
# Client 3 then claims pending item 1 from the PEL of client 2 using JUSTID
|
||||
r debug sleep 0.2
|
||||
# Consumer 3 then claims pending item 1 from the PEL of consumer 2 using JUSTID
|
||||
after 200
|
||||
set reply [
|
||||
r XCLAIM mystream mygroup client3 10 $id1 JUSTID
|
||||
r XCLAIM mystream mygroup consumer3 10 $id1 JUSTID
|
||||
]
|
||||
assert {[llength $reply] == 1}
|
||||
assert {[lindex $reply 0] eq $id1}
|
||||
@@ -294,6 +336,132 @@ start_server {
|
||||
assert {[lindex $reply 0 3] == 2}
|
||||
}
|
||||
|
||||
test {XCLAIM same consumer} {
|
||||
# Add 3 items into the stream, and create a consumer group
|
||||
r del mystream
|
||||
set id1 [r XADD mystream * a 1]
|
||||
set id2 [r XADD mystream * b 2]
|
||||
set id3 [r XADD mystream * c 3]
|
||||
r XGROUP CREATE mystream mygroup 0
|
||||
|
||||
set reply [r XREADGROUP GROUP mygroup consumer1 count 1 STREAMS mystream >]
|
||||
assert {[llength [lindex $reply 0 1 0 1]] == 2}
|
||||
assert {[lindex $reply 0 1 0 1] eq {a 1}}
|
||||
after 200
|
||||
# re-claim with the same consumer that already has it
|
||||
assert {[llength [r XCLAIM mystream mygroup consumer1 10 $id1]] == 1}
|
||||
|
||||
# make sure the entry is still in the PEL
|
||||
set reply [r XPENDING mystream mygroup - + 10]
|
||||
assert {[llength $reply] == 1}
|
||||
assert {[lindex $reply 0 1] eq {consumer1}}
|
||||
}
|
||||
|
||||
test {XAUTOCLAIM can claim PEL items from another consumer} {
|
||||
# Add 3 items into the stream, and create a consumer group
|
||||
r del mystream
|
||||
set id1 [r XADD mystream * a 1]
|
||||
set id2 [r XADD mystream * b 2]
|
||||
set id3 [r XADD mystream * c 3]
|
||||
r XGROUP CREATE mystream mygroup 0
|
||||
|
||||
# Consumer 1 reads item 1 from the stream without acknowledgements.
|
||||
# Consumer 2 then claims pending item 1 from the PEL of consumer 1
|
||||
set reply [r XREADGROUP GROUP mygroup consumer1 count 1 STREAMS mystream >]
|
||||
assert_equal [llength [lindex $reply 0 1 0 1]] 2
|
||||
assert_equal [lindex $reply 0 1 0 1] {a 1}
|
||||
after 200
|
||||
set reply [r XAUTOCLAIM mystream mygroup consumer2 10 - COUNT 1]
|
||||
assert_equal [llength $reply] 2
|
||||
assert_equal [lindex $reply 0] $id1
|
||||
assert_equal [llength [lindex $reply 1]] 1
|
||||
assert_equal [llength [lindex $reply 1 0]] 2
|
||||
assert_equal [llength [lindex $reply 1 0 1]] 2
|
||||
assert_equal [lindex $reply 1 0 1] {a 1}
|
||||
|
||||
# Consumer 1 reads another 2 items from stream
|
||||
r XREADGROUP GROUP mygroup consumer1 count 2 STREAMS mystream >
|
||||
|
||||
# For min-idle-time
|
||||
after 200
|
||||
|
||||
# Delete item 2 from the stream. Now consumer 1 has PEL that contains
|
||||
# only item 3. Try to use consumer 2 to claim the deleted item 2
|
||||
# from the PEL of consumer 1, this should return nil
|
||||
r XDEL mystream $id2
|
||||
set reply [r XAUTOCLAIM mystream mygroup consumer2 10 - COUNT 2]
|
||||
# id1 is self-claimed here but not id2 ('count' was set to 2)
|
||||
assert_equal [llength $reply] 2
|
||||
assert_equal [lindex $reply 0] $id2
|
||||
assert_equal [llength [lindex $reply 1]] 2
|
||||
assert_equal [llength [lindex $reply 1 0]] 2
|
||||
assert_equal [llength [lindex $reply 1 0 1]] 2
|
||||
assert_equal [lindex $reply 1 0 1] {a 1}
|
||||
assert_equal [lindex $reply 1 1] ""
|
||||
|
||||
# Delete item 3 from the stream. Now consumer 1 has PEL that is empty.
|
||||
# Try to use consumer 2 to claim the deleted item 3 from the PEL
|
||||
# of consumer 1, this should return nil
|
||||
after 200
|
||||
r XDEL mystream $id3
|
||||
set reply [r XAUTOCLAIM mystream mygroup consumer2 10 - JUSTID]
|
||||
# id1 is self-claimed here but not id2 and id3 ('count' is default 100)
|
||||
|
||||
# we also test the JUSTID modifier here. note that, when using JUSTID,
|
||||
# deleted entries are returned in reply (consistent with XCLAIM).
|
||||
|
||||
assert_equal [llength $reply] 2
|
||||
assert_equal [lindex $reply 0] "0-0"
|
||||
assert_equal [llength [lindex $reply 1]] 3
|
||||
assert_equal [lindex $reply 1 0] $id1
|
||||
assert_equal [lindex $reply 1 1] $id2
|
||||
assert_equal [lindex $reply 1 2] $id3
|
||||
}
|
||||
|
||||
test {XAUTOCLAIM as an iterator} {
|
||||
# Add 5 items into the stream, and create a consumer group
|
||||
r del mystream
|
||||
set id1 [r XADD mystream * a 1]
|
||||
set id2 [r XADD mystream * b 2]
|
||||
set id3 [r XADD mystream * c 3]
|
||||
set id4 [r XADD mystream * d 4]
|
||||
set id5 [r XADD mystream * e 5]
|
||||
r XGROUP CREATE mystream mygroup 0
|
||||
|
||||
# Read 5 messages into consumer1
|
||||
r XREADGROUP GROUP mygroup consumer1 count 90 STREAMS mystream >
|
||||
|
||||
# For min-idle-time
|
||||
after 200
|
||||
|
||||
# Claim 2 entries
|
||||
set reply [r XAUTOCLAIM mystream mygroup consumer2 10 - COUNT 2]
|
||||
assert_equal [llength $reply] 2
|
||||
set cursor [lindex $reply 0]
|
||||
assert_equal $cursor $id2
|
||||
assert_equal [llength [lindex $reply 1]] 2
|
||||
assert_equal [llength [lindex $reply 1 0 1]] 2
|
||||
assert_equal [lindex $reply 1 0 1] {a 1}
|
||||
|
||||
# Claim 2 more entries
|
||||
set reply [r XAUTOCLAIM mystream mygroup consumer2 10 ($cursor COUNT 2]
|
||||
assert_equal [llength $reply] 2
|
||||
set cursor [lindex $reply 0]
|
||||
assert_equal $cursor $id4
|
||||
assert_equal [llength [lindex $reply 1]] 2
|
||||
assert_equal [llength [lindex $reply 1 0 1]] 2
|
||||
assert_equal [lindex $reply 1 0 1] {c 3}
|
||||
|
||||
# Claim last entry
|
||||
set reply [r XAUTOCLAIM mystream mygroup consumer2 10 ($cursor COUNT 2]
|
||||
assert_equal [llength $reply] 2
|
||||
set cursor [lindex $reply 0]
|
||||
assert_equal $cursor {0-0}
|
||||
assert_equal [llength [lindex $reply 1]] 1
|
||||
assert_equal [llength [lindex $reply 1 0 1]] 2
|
||||
assert_equal [lindex $reply 1 0 1] {e 5}
|
||||
}
|
||||
|
||||
test {XINFO FULL output} {
|
||||
r del x
|
||||
r XADD x 100 a 1
|
||||
@@ -328,6 +496,102 @@ start_server {
|
||||
assert_equal [lindex $reply 9] "{100-0 {a 1}}"
|
||||
}
|
||||
|
||||
test {XGROUP CREATECONSUMER: create consumer if does not exist} {
|
||||
r del mystream
|
||||
r XGROUP CREATE mystream mygroup $ MKSTREAM
|
||||
r XADD mystream * f v
|
||||
|
||||
set reply [r xinfo groups mystream]
|
||||
set group_info [lindex $reply 0]
|
||||
set n_consumers [lindex $group_info 3]
|
||||
assert_equal $n_consumers 0 ;# consumers number in cg
|
||||
|
||||
# create consumer using XREADGROUP
|
||||
r XREADGROUP GROUP mygroup Alice COUNT 1 STREAMS mystream >
|
||||
|
||||
set reply [r xinfo groups mystream]
|
||||
set group_info [lindex $reply 0]
|
||||
set n_consumers [lindex $group_info 3]
|
||||
assert_equal $n_consumers 1 ;# consumers number in cg
|
||||
|
||||
set reply [r xinfo consumers mystream mygroup]
|
||||
set consumer_info [lindex $reply 0]
|
||||
assert_equal [lindex $consumer_info 1] "Alice" ;# consumer name
|
||||
|
||||
# create group using XGROUP CREATECONSUMER when Alice already exists
|
||||
set created [r XGROUP CREATECONSUMER mystream mygroup Alice]
|
||||
assert_equal $created 0
|
||||
|
||||
# create group using XGROUP CREATECONSUMER when Bob does not exist
|
||||
set created [r XGROUP CREATECONSUMER mystream mygroup Bob]
|
||||
assert_equal $created 1
|
||||
|
||||
set reply [r xinfo groups mystream]
|
||||
set group_info [lindex $reply 0]
|
||||
set n_consumers [lindex $group_info 3]
|
||||
assert_equal $n_consumers 2 ;# consumers number in cg
|
||||
|
||||
set reply [r xinfo consumers mystream mygroup]
|
||||
set consumer_info [lindex $reply 0]
|
||||
assert_equal [lindex $consumer_info 1] "Alice" ;# consumer name
|
||||
set consumer_info [lindex $reply 1]
|
||||
assert_equal [lindex $consumer_info 1] "Bob" ;# consumer name
|
||||
}
|
||||
|
||||
test {XGROUP CREATECONSUMER: group must exist} {
|
||||
r del mystream
|
||||
r XADD mystream * f v
|
||||
assert_error "*NOGROUP*" {r XGROUP CREATECONSUMER mystream mygroup consumer}
|
||||
}
|
||||
|
||||
start_server {tags {"stream"} overrides {appendonly yes aof-use-rdb-preamble no appendfsync always}} {
|
||||
test {XREADGROUP with NOACK creates consumer} {
|
||||
r del mystream
|
||||
r XGROUP CREATE mystream mygroup $ MKSTREAM
|
||||
r XADD mystream * f1 v1
|
||||
r XREADGROUP GROUP mygroup Alice NOACK STREAMS mystream ">"
|
||||
set rd [redis_deferring_client]
|
||||
$rd XREADGROUP GROUP mygroup Bob BLOCK 0 NOACK STREAMS mystream ">"
|
||||
r XADD mystream * f2 v2
|
||||
set grpinfo [r xinfo groups mystream]
|
||||
|
||||
r debug loadaof
|
||||
assert {[r xinfo groups mystream] == $grpinfo}
|
||||
set reply [r xinfo consumers mystream mygroup]
|
||||
set consumer_info [lindex $reply 0]
|
||||
assert_equal [lindex $consumer_info 1] "Alice" ;# consumer name
|
||||
set consumer_info [lindex $reply 1]
|
||||
assert_equal [lindex $consumer_info 1] "Bob" ;# consumer name
|
||||
}
|
||||
|
||||
test {Consumer without PEL is present in AOF after AOFRW} {
|
||||
r del mystream
|
||||
r XGROUP CREATE mystream mygroup $ MKSTREAM
|
||||
r XADD mystream * f v
|
||||
r XREADGROUP GROUP mygroup Alice NOACK STREAMS mystream ">"
|
||||
set rd [redis_deferring_client]
|
||||
$rd XREADGROUP GROUP mygroup Bob BLOCK 0 NOACK STREAMS mystream ">"
|
||||
r XGROUP CREATECONSUMER mystream mygroup Charlie
|
||||
set grpinfo [lindex [r xinfo groups mystream] 0]
|
||||
|
||||
r bgrewriteaof
|
||||
waitForBgrewriteaof r
|
||||
r debug loadaof
|
||||
|
||||
set curr_grpinfo [lindex [r xinfo groups mystream] 0]
|
||||
assert {$curr_grpinfo == $grpinfo}
|
||||
set n_consumers [lindex $grpinfo 3]
|
||||
|
||||
# Bob should be created only when there will be new data for this consumer
|
||||
assert_equal $n_consumers 2
|
||||
set reply [r xinfo consumers mystream mygroup]
|
||||
set consumer_info [lindex $reply 0]
|
||||
assert_equal [lindex $consumer_info 1] "Alice"
|
||||
set consumer_info [lindex $reply 1]
|
||||
assert_equal [lindex $consumer_info 1] "Charlie"
|
||||
}
|
||||
}
|
||||
|
||||
start_server {} {
|
||||
set master [srv -1 client]
|
||||
set master_host [srv -1 host]
|
||||
|
||||
+221
-1
@@ -94,6 +94,7 @@ start_server {
|
||||
r XADD mystream MAXLEN 5 * yitem $j
|
||||
}
|
||||
}
|
||||
assert {[r xlen mystream] == 5}
|
||||
set res [r xrange mystream - +]
|
||||
set expected 995
|
||||
foreach r $res {
|
||||
@@ -102,6 +103,75 @@ start_server {
|
||||
}
|
||||
}
|
||||
|
||||
test {XADD with MAXLEN option and the '=' argument} {
|
||||
r DEL mystream
|
||||
for {set j 0} {$j < 1000} {incr j} {
|
||||
if {rand() < 0.9} {
|
||||
r XADD mystream MAXLEN = 5 * xitem $j
|
||||
} else {
|
||||
r XADD mystream MAXLEN = 5 * yitem $j
|
||||
}
|
||||
}
|
||||
assert {[r XLEN mystream] == 5}
|
||||
}
|
||||
|
||||
test {XADD with MAXLEN option and the '~' argument} {
|
||||
r DEL mystream
|
||||
for {set j 0} {$j < 1000} {incr j} {
|
||||
if {rand() < 0.9} {
|
||||
r XADD mystream MAXLEN ~ 555 * xitem $j
|
||||
} else {
|
||||
r XADD mystream MAXLEN ~ 555 * yitem $j
|
||||
}
|
||||
}
|
||||
assert {[r XLEN mystream] == 600}
|
||||
}
|
||||
|
||||
test {XADD with NOMKSTREAM option} {
|
||||
r DEL mystream
|
||||
assert_equal "" [r XADD mystream NOMKSTREAM * item 1 value a]
|
||||
assert_equal 0 [r EXISTS mystream]
|
||||
r XADD mystream * item 1 value a
|
||||
r XADD mystream NOMKSTREAM * item 2 value b
|
||||
assert_equal 2 [r XLEN mystream]
|
||||
set items [r XRANGE mystream - +]
|
||||
assert_equal [lindex $items 0 1] {item 1 value a}
|
||||
assert_equal [lindex $items 1 1] {item 2 value b}
|
||||
}
|
||||
|
||||
test {XADD with MINID option} {
|
||||
r DEL mystream
|
||||
for {set j 1} {$j < 1001} {incr j} {
|
||||
set minid 1000
|
||||
if {$j >= 5} {
|
||||
set minid [expr {$j-5}]
|
||||
}
|
||||
if {rand() < 0.9} {
|
||||
r XADD mystream MINID $minid $j xitem $j
|
||||
} else {
|
||||
r XADD mystream MINID $minid $j yitem $j
|
||||
}
|
||||
}
|
||||
assert {[r xlen mystream] == 6}
|
||||
set res [r xrange mystream - +]
|
||||
set expected 995
|
||||
foreach r $res {
|
||||
assert {[lindex $r 1 1] == $expected}
|
||||
incr expected
|
||||
}
|
||||
}
|
||||
|
||||
test {XTRIM with MINID option} {
|
||||
r DEL mystream
|
||||
r XADD mystream 1-0 f v
|
||||
r XADD mystream 2-0 f v
|
||||
r XADD mystream 3-0 f v
|
||||
r XADD mystream 4-0 f v
|
||||
r XADD mystream 5-0 f v
|
||||
r XTRIM mystream MINID = 3-0
|
||||
assert_equal [r XRANGE mystream - +] {{3-0 {f v}} {4-0 {f v}} {5-0 {f v}}}
|
||||
}
|
||||
|
||||
test {XADD mass insertion and XLEN} {
|
||||
r DEL mystream
|
||||
r multi
|
||||
@@ -156,6 +226,32 @@ start_server {
|
||||
assert {[r xrange mystream - +] == [lreverse [r xrevrange mystream + -]]}
|
||||
}
|
||||
|
||||
test {XRANGE exclusive ranges} {
|
||||
set ids {0-1 0-18446744073709551615 1-0 42-0 42-42
|
||||
18446744073709551615-18446744073709551614
|
||||
18446744073709551615-18446744073709551615}
|
||||
set total [llength $ids]
|
||||
r multi
|
||||
r DEL vipstream
|
||||
foreach id $ids {
|
||||
r XADD vipstream $id foo bar
|
||||
}
|
||||
r exec
|
||||
assert {[llength [r xrange vipstream - +]] == $total}
|
||||
assert {[llength [r xrange vipstream ([lindex $ids 0] +]] == $total-1}
|
||||
assert {[llength [r xrange vipstream - ([lindex $ids $total-1]]] == $total-1}
|
||||
assert {[llength [r xrange vipstream (0-1 (1-0]] == 1}
|
||||
assert {[llength [r xrange vipstream (1-0 (42-42]] == 1}
|
||||
catch {r xrange vipstream (- +} e
|
||||
assert_match {ERR*} $e
|
||||
catch {r xrange vipstream - (+} e
|
||||
assert_match {ERR*} $e
|
||||
catch {r xrange vipstream (18446744073709551615-18446744073709551615 +} e
|
||||
assert_match {ERR*} $e
|
||||
catch {r xrange vipstream - (0-0} e
|
||||
assert_match {ERR*} $e
|
||||
}
|
||||
|
||||
test {XREAD with non empty stream} {
|
||||
set res [r XREAD COUNT 1 STREAMS mystream 0-0]
|
||||
assert {[lrange [lindex $res 0 1 0 1] 0 1] eq {item 0}}
|
||||
@@ -360,7 +456,6 @@ start_server {
|
||||
r del x
|
||||
set rd [redis_deferring_client]
|
||||
$rd XREAD BLOCK 0 STREAMS x 1-18446744073709551615
|
||||
after 100
|
||||
r XADD x 1-1 f v
|
||||
r XADD x 1-18446744073709551615 f v
|
||||
r XADD x 2-1 f v
|
||||
@@ -374,6 +469,69 @@ start_server {
|
||||
r XADD x * f2 v2
|
||||
assert_equal [r XRANGE x - +] {{2577343934890-18446744073709551615 {f v}} {2577343934891-0 {f2 v2}}}
|
||||
}
|
||||
|
||||
test {XTRIM with MAXLEN option basic test} {
|
||||
r DEL mystream
|
||||
for {set j 0} {$j < 1000} {incr j} {
|
||||
if {rand() < 0.9} {
|
||||
r XADD mystream * xitem $j
|
||||
} else {
|
||||
r XADD mystream * yitem $j
|
||||
}
|
||||
}
|
||||
r XTRIM mystream MAXLEN 666
|
||||
assert {[r XLEN mystream] == 666}
|
||||
r XTRIM mystream MAXLEN = 555
|
||||
assert {[r XLEN mystream] == 555}
|
||||
r XTRIM mystream MAXLEN ~ 444
|
||||
assert {[r XLEN mystream] == 500}
|
||||
r XTRIM mystream MAXLEN ~ 400
|
||||
assert {[r XLEN mystream] == 400}
|
||||
}
|
||||
|
||||
test {XADD with LIMIT consecutive calls} {
|
||||
r del mystream
|
||||
r config set stream-node-max-entries 10
|
||||
for {set j 0} {$j < 100} {incr j} {
|
||||
r XADD mystream * xitem v
|
||||
}
|
||||
r XADD mystream MAXLEN ~ 55 LIMIT 30 * xitem v
|
||||
assert {[r xlen mystream] == 71}
|
||||
r XADD mystream MAXLEN ~ 55 LIMIT 30 * xitem v
|
||||
assert {[r xlen mystream] == 62}
|
||||
r config set stream-node-max-entries 100
|
||||
}
|
||||
|
||||
test {XTRIM with ~ is limited} {
|
||||
r del mystream
|
||||
r config set stream-node-max-entries 1
|
||||
for {set j 0} {$j < 102} {incr j} {
|
||||
r XADD mystream * xitem v
|
||||
}
|
||||
r XTRIM mystream MAXLEN ~ 1
|
||||
assert {[r xlen mystream] == 2}
|
||||
r config set stream-node-max-entries 100
|
||||
}
|
||||
|
||||
test {XTRIM without ~ is not limited} {
|
||||
r del mystream
|
||||
r config set stream-node-max-entries 1
|
||||
for {set j 0} {$j < 102} {incr j} {
|
||||
r XADD mystream * xitem v
|
||||
}
|
||||
r XTRIM mystream MAXLEN 1
|
||||
assert {[r xlen mystream] == 1}
|
||||
r config set stream-node-max-entries 100
|
||||
}
|
||||
|
||||
test {XTRIM without ~ and with LIMIT} {
|
||||
r del mystream
|
||||
r config set stream-node-max-entries 1
|
||||
for {set j 0} {$j < 102} {incr j} {
|
||||
r XADD mystream * xitem v
|
||||
}
|
||||
assert_error ERR* {r XTRIM mystream MAXLEN 1 LIMIT 30}
|
||||
}
|
||||
}
|
||||
|
||||
start_server {tags {"stream"} overrides {appendonly yes}} {
|
||||
@@ -391,6 +549,22 @@ start_server {tags {"stream"} overrides {appendonly yes}} {
|
||||
}
|
||||
}
|
||||
|
||||
start_server {tags {"stream"} overrides {appendonly yes}} {
|
||||
test {XADD with MINID > lastid can propagate correctly} {
|
||||
for {set j 0} {$j < 100} {incr j} {
|
||||
set id [expr {$j+1}]
|
||||
r XADD mystream $id xitem v
|
||||
}
|
||||
r XADD mystream MINID 1 * xitem v
|
||||
incr j
|
||||
assert {[r xlen mystream] == $j}
|
||||
r debug loadaof
|
||||
r XADD mystream * xitem v
|
||||
incr j
|
||||
assert {[r xlen mystream] == $j}
|
||||
}
|
||||
}
|
||||
|
||||
start_server {tags {"stream"} overrides {appendonly yes}} {
|
||||
test {XADD with ~ MAXLEN can propagate correctly} {
|
||||
for {set j 0} {$j < 100} {incr j} {
|
||||
@@ -407,6 +581,52 @@ start_server {tags {"stream"} overrides {appendonly yes}} {
|
||||
}
|
||||
}
|
||||
|
||||
start_server {tags {"stream"} overrides {appendonly yes stream-node-max-entries 10}} {
|
||||
test {XADD with ~ MAXLEN and LIMIT can propagate correctly} {
|
||||
for {set j 0} {$j < 100} {incr j} {
|
||||
r XADD mystream * xitem v
|
||||
}
|
||||
r XADD mystream MAXLEN ~ 55 LIMIT 30 * xitem v
|
||||
assert {[r xlen mystream] == 71}
|
||||
r config set stream-node-max-entries 1
|
||||
r debug loadaof
|
||||
r XADD mystream * xitem v
|
||||
assert {[r xlen mystream] == 72}
|
||||
}
|
||||
}
|
||||
|
||||
start_server {tags {"stream"} overrides {appendonly yes}} {
|
||||
test {XADD with ~ MINID can propagate correctly} {
|
||||
for {set j 0} {$j < 100} {incr j} {
|
||||
set id [expr {$j+1}]
|
||||
r XADD mystream $id xitem v
|
||||
}
|
||||
r XADD mystream MINID ~ $j * xitem v
|
||||
incr j
|
||||
assert {[r xlen mystream] == $j}
|
||||
r config set stream-node-max-entries 1
|
||||
r debug loadaof
|
||||
r XADD mystream * xitem v
|
||||
incr j
|
||||
assert {[r xlen mystream] == $j}
|
||||
}
|
||||
}
|
||||
|
||||
start_server {tags {"stream"} overrides {appendonly yes stream-node-max-entries 10}} {
|
||||
test {XADD with ~ MINID and LIMIT can propagate correctly} {
|
||||
for {set j 0} {$j < 100} {incr j} {
|
||||
set id [expr {$j+1}]
|
||||
r XADD mystream $id xitem v
|
||||
}
|
||||
r XADD mystream MINID ~ 55 LIMIT 30 * xitem v
|
||||
assert {[r xlen mystream] == 71}
|
||||
r config set stream-node-max-entries 1
|
||||
r debug loadaof
|
||||
r XADD mystream * xitem v
|
||||
assert {[r xlen mystream] == 72}
|
||||
}
|
||||
}
|
||||
|
||||
start_server {tags {"stream"} overrides {appendonly yes stream-node-max-entries 10}} {
|
||||
test {XTRIM with ~ MAXLEN can propagate correctly} {
|
||||
for {set j 0} {$j < 100} {incr j} {
|
||||
|
||||
@@ -102,6 +102,91 @@ start_server {tags {"string"}} {
|
||||
assert_equal 20 [r get x]
|
||||
}
|
||||
|
||||
test "GETEX EX option" {
|
||||
r del foo
|
||||
r set foo bar
|
||||
r getex foo ex 10
|
||||
assert_range [r ttl foo] 5 10
|
||||
}
|
||||
|
||||
test "GETEX PX option" {
|
||||
r del foo
|
||||
r set foo bar
|
||||
r getex foo px 10000
|
||||
assert_range [r pttl foo] 5000 10000
|
||||
}
|
||||
|
||||
test "GETEX EXAT option" {
|
||||
r del foo
|
||||
r set foo bar
|
||||
r getex foo exat [expr [clock seconds] + 10]
|
||||
assert_range [r ttl foo] 5 10
|
||||
}
|
||||
|
||||
test "GETEX PXAT option" {
|
||||
r del foo
|
||||
r set foo bar
|
||||
r getex foo pxat [expr [clock milliseconds] + 10000]
|
||||
assert_range [r pttl foo] 5000 10000
|
||||
}
|
||||
|
||||
test "GETEX PERSIST option" {
|
||||
r del foo
|
||||
r set foo bar ex 10
|
||||
assert_range [r ttl foo] 5 10
|
||||
r getex foo persist
|
||||
assert_equal -1 [r ttl foo]
|
||||
}
|
||||
|
||||
test "GETEX no option" {
|
||||
r del foo
|
||||
r set foo bar
|
||||
r getex foo
|
||||
assert_equal bar [r getex foo]
|
||||
}
|
||||
|
||||
test "GETEX syntax errors" {
|
||||
set ex {}
|
||||
catch {r getex foo non-existent-option} ex
|
||||
set ex
|
||||
} {*syntax*}
|
||||
|
||||
test "GETEX no arguments" {
|
||||
set ex {}
|
||||
catch {r getex} ex
|
||||
set ex
|
||||
} {*wrong number of arguments*}
|
||||
|
||||
test "GETDEL command" {
|
||||
r del foo
|
||||
r set foo bar
|
||||
assert_equal bar [r getdel foo ]
|
||||
assert_equal {} [r getdel foo ]
|
||||
}
|
||||
|
||||
test {GETDEL propagate as DEL command to replica} {
|
||||
set repl [attach_to_replication_stream]
|
||||
r set foo bar
|
||||
r getdel foo
|
||||
assert_replication_stream $repl {
|
||||
{select *}
|
||||
{set foo bar}
|
||||
{del foo}
|
||||
}
|
||||
}
|
||||
|
||||
test {GETEX without argument does not propagate to replica} {
|
||||
set repl [attach_to_replication_stream]
|
||||
r set foo bar
|
||||
r getex foo
|
||||
r del foo
|
||||
assert_replication_stream $repl {
|
||||
{select *}
|
||||
{set foo bar}
|
||||
{del foo}
|
||||
}
|
||||
}
|
||||
|
||||
test {MGET} {
|
||||
r flushdb
|
||||
r set foo BAR
|
||||
@@ -394,6 +479,35 @@ start_server {tags {"string"}} {
|
||||
list $v1 $v2 [r get foo]
|
||||
} {{} OK 2}
|
||||
|
||||
test {Extended SET GET option} {
|
||||
r del foo
|
||||
r set foo bar
|
||||
set old_value [r set foo bar2 GET]
|
||||
set new_value [r get foo]
|
||||
list $old_value $new_value
|
||||
} {bar bar2}
|
||||
|
||||
test {Extended SET GET option with no previous value} {
|
||||
r del foo
|
||||
set old_value [r set foo bar GET]
|
||||
set new_value [r get foo]
|
||||
list $old_value $new_value
|
||||
} {{} bar}
|
||||
|
||||
test {Extended SET GET with NX option should result in syntax err} {
|
||||
catch {r set foo bar NX GET} err1
|
||||
catch {r set foo bar NX GET} err2
|
||||
list $err1 $err2
|
||||
} {*syntax err* *syntax err*}
|
||||
|
||||
test {Extended SET GET with incorrect type should result in wrong type error} {
|
||||
r del foo
|
||||
r rpush foo waffle
|
||||
catch {r set foo bar GET} err1
|
||||
assert_equal "waffle" [r rpop foo]
|
||||
set err1
|
||||
} {*WRONGTYPE*}
|
||||
|
||||
test {Extended SET EX option} {
|
||||
r del foo
|
||||
r set foo bar ex 10
|
||||
@@ -408,6 +522,17 @@ start_server {tags {"string"}} {
|
||||
assert {$ttl <= 10 && $ttl > 5}
|
||||
}
|
||||
|
||||
test "Extended SET EXAT option" {
|
||||
r del foo
|
||||
r set foo bar exat [expr [clock seconds] + 10]
|
||||
assert_range [r ttl foo] 5 10
|
||||
}
|
||||
|
||||
test "Extended SET PXAT option" {
|
||||
r del foo
|
||||
r set foo bar pxat [expr [clock milliseconds] + 10000]
|
||||
assert_range [r ttl foo] 5 10
|
||||
}
|
||||
test {Extended SET using multiple options at once} {
|
||||
r set foo val
|
||||
assert {[r set foo bar xx px 10000] eq {OK}}
|
||||
|
||||
@@ -7,6 +7,8 @@ start_server {tags {"zset"}} {
|
||||
}
|
||||
|
||||
proc basics {encoding} {
|
||||
set original_max_entries [lindex [r config get zset-max-ziplist-entries] 1]
|
||||
set original_max_value [lindex [r config get zset-max-ziplist-value] 1]
|
||||
if {$encoding == "ziplist"} {
|
||||
r config set zset-max-ziplist-entries 128
|
||||
r config set zset-max-ziplist-value 64
|
||||
@@ -78,6 +80,46 @@ start_server {tags {"zset"}} {
|
||||
assert {[r zscore ztmp y] == 21}
|
||||
}
|
||||
|
||||
test "ZADD GT updates existing elements when new scores are greater" {
|
||||
r del ztmp
|
||||
r zadd ztmp 10 x 20 y 30 z
|
||||
assert {[r zadd ztmp gt ch 5 foo 11 x 21 y 29 z] == 3}
|
||||
assert {[r zcard ztmp] == 4}
|
||||
assert {[r zscore ztmp x] == 11}
|
||||
assert {[r zscore ztmp y] == 21}
|
||||
assert {[r zscore ztmp z] == 30}
|
||||
}
|
||||
|
||||
test "ZADD LT updates existing elements when new scores are lower" {
|
||||
r del ztmp
|
||||
r zadd ztmp 10 x 20 y 30 z
|
||||
assert {[r zadd ztmp lt ch 5 foo 11 x 21 y 29 z] == 2}
|
||||
assert {[r zcard ztmp] == 4}
|
||||
assert {[r zscore ztmp x] == 10}
|
||||
assert {[r zscore ztmp y] == 20}
|
||||
assert {[r zscore ztmp z] == 29}
|
||||
}
|
||||
|
||||
test "ZADD GT XX updates existing elements when new scores are greater and skips new elements" {
|
||||
r del ztmp
|
||||
r zadd ztmp 10 x 20 y 30 z
|
||||
assert {[r zadd ztmp gt xx ch 5 foo 11 x 21 y 29 z] == 2}
|
||||
assert {[r zcard ztmp] == 3}
|
||||
assert {[r zscore ztmp x] == 11}
|
||||
assert {[r zscore ztmp y] == 21}
|
||||
assert {[r zscore ztmp z] == 30}
|
||||
}
|
||||
|
||||
test "ZADD LT XX updates existing elements when new scores are lower and skips new elements" {
|
||||
r del ztmp
|
||||
r zadd ztmp 10 x 20 y 30 z
|
||||
assert {[r zadd ztmp lt xx ch 5 foo 11 x 21 y 29 z] == 1}
|
||||
assert {[r zcard ztmp] == 3}
|
||||
assert {[r zscore ztmp x] == 10}
|
||||
assert {[r zscore ztmp y] == 20}
|
||||
assert {[r zscore ztmp z] == 29}
|
||||
}
|
||||
|
||||
test "ZADD XX and NX are not compatible" {
|
||||
r del ztmp
|
||||
catch {r zadd ztmp xx nx 10 x} err
|
||||
@@ -100,6 +142,24 @@ start_server {tags {"zset"}} {
|
||||
assert {[r zscore ztmp b] == 200}
|
||||
}
|
||||
|
||||
test "ZADD GT and NX are not compatible" {
|
||||
r del ztmp
|
||||
catch {r zadd ztmp gt nx 10 x} err
|
||||
set err
|
||||
} {ERR*}
|
||||
|
||||
test "ZADD LT and NX are not compatible" {
|
||||
r del ztmp
|
||||
catch {r zadd ztmp lt nx 10 x} err
|
||||
set err
|
||||
} {ERR*}
|
||||
|
||||
test "ZADD LT and GT are not compatible" {
|
||||
r del ztmp
|
||||
catch {r zadd ztmp lt gt 10 x} err
|
||||
set err
|
||||
} {ERR*}
|
||||
|
||||
test "ZADD INCR works like ZINCRBY" {
|
||||
r del ztmp
|
||||
r zadd ztmp 10 x 20 y 30 z
|
||||
@@ -374,6 +434,7 @@ start_server {tags {"zset"}} {
|
||||
create_default_zset
|
||||
assert_equal {e 4 f 5} [r zrangebyscore zset 2 5 LIMIT 2 3 WITHSCORES]
|
||||
assert_equal {d 3 c 2} [r zrevrangebyscore zset 5 2 LIMIT 2 3 WITHSCORES]
|
||||
assert_equal {} [r zrangebyscore zset 2 5 LIMIT 12 13 WITHSCORES]
|
||||
}
|
||||
|
||||
test "ZRANGEBYSCORE with non-value min or max" {
|
||||
@@ -554,6 +615,13 @@ start_server {tags {"zset"}} {
|
||||
assert_equal 0 [r exists dst_key]
|
||||
}
|
||||
|
||||
test "ZUNION/ZINTER/ZDIFF against non-existing key - $encoding" {
|
||||
r del zseta
|
||||
assert_equal {} [r zunion 1 zseta]
|
||||
assert_equal {} [r zinter 1 zseta]
|
||||
assert_equal {} [r zdiff 1 zseta]
|
||||
}
|
||||
|
||||
test "ZUNIONSTORE with empty set - $encoding" {
|
||||
r del zseta zsetb
|
||||
r zadd zseta 1 a
|
||||
@@ -562,6 +630,15 @@ start_server {tags {"zset"}} {
|
||||
r zrange zsetc 0 -1 withscores
|
||||
} {a 1 b 2}
|
||||
|
||||
test "ZUNION/ZINTER/ZDIFF with empty set - $encoding" {
|
||||
r del zseta zsetb
|
||||
r zadd zseta 1 a
|
||||
r zadd zseta 2 b
|
||||
assert_equal {a 1 b 2} [r zunion 2 zseta zsetb withscores]
|
||||
assert_equal {} [r zinter 2 zseta zsetb withscores]
|
||||
assert_equal {a 1 b 2} [r zdiff 2 zseta zsetb withscores]
|
||||
}
|
||||
|
||||
test "ZUNIONSTORE basics - $encoding" {
|
||||
r del zseta zsetb zsetc
|
||||
r zadd zseta 1 a
|
||||
@@ -575,11 +652,30 @@ start_server {tags {"zset"}} {
|
||||
assert_equal {a 1 b 3 d 3 c 5} [r zrange zsetc 0 -1 withscores]
|
||||
}
|
||||
|
||||
test "ZUNION/ZINTER/ZDIFF with integer members - $encoding" {
|
||||
r del zsetd zsetf
|
||||
r zadd zsetd 1 1
|
||||
r zadd zsetd 2 2
|
||||
r zadd zsetd 3 3
|
||||
r zadd zsetf 1 1
|
||||
r zadd zsetf 3 3
|
||||
r zadd zsetf 4 4
|
||||
|
||||
assert_equal {1 2 2 2 4 4 3 6} [r zunion 2 zsetd zsetf withscores]
|
||||
assert_equal {1 2 3 6} [r zinter 2 zsetd zsetf withscores]
|
||||
assert_equal {2 2} [r zdiff 2 zsetd zsetf withscores]
|
||||
}
|
||||
|
||||
test "ZUNIONSTORE with weights - $encoding" {
|
||||
assert_equal 4 [r zunionstore zsetc 2 zseta zsetb weights 2 3]
|
||||
assert_equal {a 2 b 7 d 9 c 12} [r zrange zsetc 0 -1 withscores]
|
||||
}
|
||||
|
||||
test "ZUNION with weights - $encoding" {
|
||||
assert_equal {a 2 b 7 d 9 c 12} [r zunion 2 zseta zsetb weights 2 3 withscores]
|
||||
assert_equal {b 7 c 12} [r zinter 2 zseta zsetb weights 2 3 withscores]
|
||||
}
|
||||
|
||||
test "ZUNIONSTORE with a regular set and weights - $encoding" {
|
||||
r del seta
|
||||
r sadd seta a
|
||||
@@ -595,21 +691,45 @@ start_server {tags {"zset"}} {
|
||||
assert_equal {a 1 b 1 c 2 d 3} [r zrange zsetc 0 -1 withscores]
|
||||
}
|
||||
|
||||
test "ZUNION/ZINTER with AGGREGATE MIN - $encoding" {
|
||||
assert_equal {a 1 b 1 c 2 d 3} [r zunion 2 zseta zsetb aggregate min withscores]
|
||||
assert_equal {b 1 c 2} [r zinter 2 zseta zsetb aggregate min withscores]
|
||||
}
|
||||
|
||||
test "ZUNIONSTORE with AGGREGATE MAX - $encoding" {
|
||||
assert_equal 4 [r zunionstore zsetc 2 zseta zsetb aggregate max]
|
||||
assert_equal {a 1 b 2 c 3 d 3} [r zrange zsetc 0 -1 withscores]
|
||||
}
|
||||
|
||||
test "ZUNION/ZINTER with AGGREGATE MAX - $encoding" {
|
||||
assert_equal {a 1 b 2 c 3 d 3} [r zunion 2 zseta zsetb aggregate max withscores]
|
||||
assert_equal {b 2 c 3} [r zinter 2 zseta zsetb aggregate max withscores]
|
||||
}
|
||||
|
||||
test "ZINTERSTORE basics - $encoding" {
|
||||
assert_equal 2 [r zinterstore zsetc 2 zseta zsetb]
|
||||
assert_equal {b 3 c 5} [r zrange zsetc 0 -1 withscores]
|
||||
}
|
||||
|
||||
test "ZINTER basics - $encoding" {
|
||||
assert_equal {b 3 c 5} [r zinter 2 zseta zsetb withscores]
|
||||
}
|
||||
|
||||
test "ZINTER RESP3 - $encoding" {
|
||||
r hello 3
|
||||
assert_equal {{b 3.0} {c 5.0}} [r zinter 2 zseta zsetb withscores]
|
||||
}
|
||||
r hello 2
|
||||
|
||||
test "ZINTERSTORE with weights - $encoding" {
|
||||
assert_equal 2 [r zinterstore zsetc 2 zseta zsetb weights 2 3]
|
||||
assert_equal {b 7 c 12} [r zrange zsetc 0 -1 withscores]
|
||||
}
|
||||
|
||||
test "ZINTER with weights - $encoding" {
|
||||
assert_equal {b 7 c 12} [r zinter 2 zseta zsetb weights 2 3 withscores]
|
||||
}
|
||||
|
||||
test "ZINTERSTORE with a regular set and weights - $encoding" {
|
||||
r del seta
|
||||
r sadd seta a
|
||||
@@ -665,6 +785,80 @@ start_server {tags {"zset"}} {
|
||||
}
|
||||
}
|
||||
|
||||
test "ZDIFFSTORE basics - $encoding" {
|
||||
assert_equal 1 [r zdiffstore zsetc 2 zseta zsetb]
|
||||
assert_equal {a 1} [r zrange zsetc 0 -1 withscores]
|
||||
}
|
||||
|
||||
test "ZDIFF basics - $encoding" {
|
||||
assert_equal {a 1} [r zdiff 2 zseta zsetb withscores]
|
||||
}
|
||||
|
||||
test "ZDIFFSTORE with a regular set - $encoding" {
|
||||
r del seta
|
||||
r sadd seta a
|
||||
r sadd seta b
|
||||
r sadd seta c
|
||||
assert_equal 1 [r zdiffstore zsetc 2 seta zsetb]
|
||||
assert_equal {a 1} [r zrange zsetc 0 -1 withscores]
|
||||
}
|
||||
|
||||
test "ZDIFF subtracting set from itself - $encoding" {
|
||||
assert_equal 0 [r zdiffstore zsetc 2 zseta zseta]
|
||||
assert_equal {} [r zrange zsetc 0 -1 withscores]
|
||||
}
|
||||
|
||||
test "ZDIFF algorithm 1 - $encoding" {
|
||||
r del zseta zsetb zsetc
|
||||
r zadd zseta 1 a
|
||||
r zadd zseta 2 b
|
||||
r zadd zseta 3 c
|
||||
r zadd zsetb 1 b
|
||||
r zadd zsetb 2 c
|
||||
r zadd zsetb 3 d
|
||||
assert_equal 1 [r zdiffstore zsetc 2 zseta zsetb]
|
||||
assert_equal {a 1} [r zrange zsetc 0 -1 withscores]
|
||||
}
|
||||
|
||||
test "ZDIFF algorithm 2 - $encoding" {
|
||||
r del zseta zsetb zsetc zsetd zsete
|
||||
r zadd zseta 1 a
|
||||
r zadd zseta 2 b
|
||||
r zadd zseta 3 c
|
||||
r zadd zseta 5 e
|
||||
r zadd zsetb 1 b
|
||||
r zadd zsetc 1 c
|
||||
r zadd zsetd 1 d
|
||||
assert_equal 2 [r zdiffstore zsete 4 zseta zsetb zsetc zsetd]
|
||||
assert_equal {a 1 e 5} [r zrange zsete 0 -1 withscores]
|
||||
}
|
||||
|
||||
test "ZDIFF fuzzing" {
|
||||
for {set j 0} {$j < 100} {incr j} {
|
||||
unset -nocomplain s
|
||||
array set s {}
|
||||
set args {}
|
||||
set num_sets [expr {[randomInt 10]+1}]
|
||||
for {set i 0} {$i < $num_sets} {incr i} {
|
||||
set num_elements [randomInt 100]
|
||||
r del zset_$i
|
||||
lappend args zset_$i
|
||||
while {$num_elements} {
|
||||
set ele [randomValue]
|
||||
r zadd zset_$i [randomInt 100] $ele
|
||||
if {$i == 0} {
|
||||
set s($ele) x
|
||||
} else {
|
||||
unset -nocomplain s($ele)
|
||||
}
|
||||
incr num_elements -1
|
||||
}
|
||||
}
|
||||
set result [lsort [r zdiff [llength $args] {*}$args]]
|
||||
assert_equal $result [lsort [array names s]]
|
||||
}
|
||||
}
|
||||
|
||||
test "Basic ZPOP with a single key - $encoding" {
|
||||
r del zset
|
||||
assert_equal {} [r zpopmin zset]
|
||||
@@ -733,6 +927,9 @@ start_server {tags {"zset"}} {
|
||||
assert_equal 0 [r zcard z1]
|
||||
assert_equal 1 [r zcard z2]
|
||||
}
|
||||
|
||||
r config set zset-max-ziplist-entries $original_max_entries
|
||||
r config set zset-max-ziplist-value $original_max_value
|
||||
}
|
||||
|
||||
basics ziplist
|
||||
@@ -781,11 +978,57 @@ start_server {tags {"zset"}} {
|
||||
}
|
||||
}
|
||||
|
||||
test "ZUNIONSTORE/ZINTERSTORE/ZDIFFSTORE error if using WITHSCORES " {
|
||||
assert_error "*ERR*syntax*" {r zunionstore foo 2 zsetd zsetf withscores}
|
||||
assert_error "*ERR*syntax*" {r zinterstore foo 2 zsetd zsetf withscores}
|
||||
assert_error "*ERR*syntax*" {r zdiffstore foo 2 zsetd zsetf withscores}
|
||||
}
|
||||
|
||||
test {ZMSCORE retrieve} {
|
||||
r del zmscoretest
|
||||
r zadd zmscoretest 10 x
|
||||
r zadd zmscoretest 20 y
|
||||
|
||||
r zmscore zmscoretest x y
|
||||
} {10 20}
|
||||
|
||||
test {ZMSCORE retrieve from empty set} {
|
||||
r del zmscoretest
|
||||
|
||||
r zmscore zmscoretest x y
|
||||
} {{} {}}
|
||||
|
||||
test {ZMSCORE retrieve with missing member} {
|
||||
r del zmscoretest
|
||||
r zadd zmscoretest 10 x
|
||||
|
||||
r zmscore zmscoretest x y
|
||||
} {10 {}}
|
||||
|
||||
test {ZMSCORE retrieve single member} {
|
||||
r del zmscoretest
|
||||
r zadd zmscoretest 10 x
|
||||
r zadd zmscoretest 20 y
|
||||
|
||||
r zmscore zmscoretest x
|
||||
} {10}
|
||||
|
||||
test {ZMSCORE retrieve requires one or more members} {
|
||||
r del zmscoretest
|
||||
r zadd zmscoretest 10 x
|
||||
r zadd zmscoretest 20 y
|
||||
|
||||
catch {r zmscore zmscoretest} e
|
||||
assert_match {*ERR*wrong*number*arg*} $e
|
||||
}
|
||||
|
||||
test "ZSET commands don't accept the empty strings as valid score" {
|
||||
assert_error "*not*float*" {r zadd myzset "" abc}
|
||||
}
|
||||
|
||||
proc stressers {encoding} {
|
||||
set original_max_entries [lindex [r config get zset-max-ziplist-entries] 1]
|
||||
set original_max_value [lindex [r config get zset-max-ziplist-value] 1]
|
||||
if {$encoding == "ziplist"} {
|
||||
# Little extra to allow proper fuzzing in the sorting stresser
|
||||
r config set zset-max-ziplist-entries 256
|
||||
@@ -815,6 +1058,21 @@ start_server {tags {"zset"}} {
|
||||
}
|
||||
}
|
||||
|
||||
test "ZMSCORE - $encoding" {
|
||||
r del zscoretest
|
||||
set aux {}
|
||||
for {set i 0} {$i < $elements} {incr i} {
|
||||
set score [expr rand()]
|
||||
lappend aux $score
|
||||
r zadd zscoretest $score $i
|
||||
}
|
||||
|
||||
assert_encoding $encoding zscoretest
|
||||
for {set i 0} {$i < $elements} {incr i} {
|
||||
assert_equal [lindex $aux $i] [r zmscore zscoretest $i]
|
||||
}
|
||||
}
|
||||
|
||||
test "ZSCORE after a DEBUG RELOAD - $encoding" {
|
||||
r del zscoretest
|
||||
set aux {}
|
||||
@@ -1195,6 +1453,8 @@ start_server {tags {"zset"}} {
|
||||
r zadd zset 0 foo
|
||||
assert_equal {zset foo 0} [$rd read]
|
||||
}
|
||||
r config set zset-max-ziplist-entries $original_max_entries
|
||||
r config set zset-max-ziplist-value $original_max_value
|
||||
}
|
||||
|
||||
tags {"slow"} {
|
||||
@@ -1227,4 +1487,272 @@ start_server {tags {"zset"}} {
|
||||
}
|
||||
r config set zset-max-ziplist-entries $original_max
|
||||
}
|
||||
|
||||
test {ZRANGESTORE basic} {
|
||||
r flushall
|
||||
r zadd z1 1 a 2 b 3 c 4 d
|
||||
set res [r zrangestore z2 z1 0 -1]
|
||||
assert_equal $res 4
|
||||
r zrange z2 0 -1 withscores
|
||||
} {a 1 b 2 c 3 d 4}
|
||||
|
||||
test {ZRANGESTORE RESP3} {
|
||||
r hello 3
|
||||
r zrange z2 0 -1 withscores
|
||||
} {{a 1.0} {b 2.0} {c 3.0} {d 4.0}}
|
||||
r hello 2
|
||||
|
||||
test {ZRANGESTORE range} {
|
||||
set res [r zrangestore z2 z1 1 2]
|
||||
assert_equal $res 2
|
||||
r zrange z2 0 -1 withscores
|
||||
} {b 2 c 3}
|
||||
|
||||
test {ZRANGESTORE BYLEX} {
|
||||
set res [r zrangestore z2 z1 \[b \[c BYLEX]
|
||||
assert_equal $res 2
|
||||
r zrange z2 0 -1 withscores
|
||||
} {b 2 c 3}
|
||||
|
||||
test {ZRANGESTORE BYSCORE} {
|
||||
set res [r zrangestore z2 z1 1 2 BYSCORE]
|
||||
assert_equal $res 2
|
||||
r zrange z2 0 -1 withscores
|
||||
} {a 1 b 2}
|
||||
|
||||
test {ZRANGESTORE BYSCORE LIMIT} {
|
||||
set res [r zrangestore z2 z1 0 5 BYSCORE LIMIT 0 2]
|
||||
assert_equal $res 2
|
||||
r zrange z2 0 -1 withscores
|
||||
} {a 1 b 2}
|
||||
|
||||
test {ZRANGESTORE BYSCORE REV LIMIT} {
|
||||
set res [r zrangestore z2 z1 5 0 BYSCORE REV LIMIT 0 2]
|
||||
assert_equal $res 2
|
||||
r zrange z2 0 -1 withscores
|
||||
} {c 3 d 4}
|
||||
|
||||
test {ZRANGE BYSCORE REV LIMIT} {
|
||||
r zrange z1 5 0 BYSCORE REV LIMIT 0 2 WITHSCORES
|
||||
} {d 4 c 3}
|
||||
|
||||
test {ZRANGESTORE - empty range} {
|
||||
set res [r zrangestore z2 z1 5 6]
|
||||
assert_equal $res 0
|
||||
r exists z2
|
||||
} {0}
|
||||
|
||||
test {ZRANGESTORE BYLEX - empty range} {
|
||||
set res [r zrangestore z2 z1 \[f \[g BYLEX]
|
||||
assert_equal $res 0
|
||||
r exists z2
|
||||
} {0}
|
||||
|
||||
test {ZRANGESTORE BYSCORE - empty range} {
|
||||
set res [r zrangestore z2 z1 5 6 BYSCORE]
|
||||
assert_equal $res 0
|
||||
r exists z2
|
||||
} {0}
|
||||
|
||||
test {ZRANGE BYLEX} {
|
||||
r zrange z1 \[b \[c BYLEX
|
||||
} {b c}
|
||||
|
||||
test {ZRANGESTORE invalid syntax} {
|
||||
catch {r zrangestore z2 z1 0 -1 limit 1 2} err
|
||||
assert_match "*syntax*" $err
|
||||
catch {r zrangestore z2 z1 0 -1 WITHSCORES} err
|
||||
assert_match "*syntax*" $err
|
||||
}
|
||||
|
||||
test {ZRANGE invalid syntax} {
|
||||
catch {r zrange z1 0 -1 limit 1 2} err
|
||||
assert_match "*syntax*" $err
|
||||
catch {r zrange z1 0 -1 BYLEX WITHSCORES} err
|
||||
assert_match "*syntax*" $err
|
||||
catch {r zrevrange z1 0 -1 BYSCORE} err
|
||||
assert_match "*syntax*" $err
|
||||
catch {r zrangebyscore z1 0 -1 REV} err
|
||||
assert_match "*syntax*" $err
|
||||
}
|
||||
|
||||
proc get_keys {l} {
|
||||
set res {}
|
||||
foreach {score key} $l {
|
||||
lappend res $key
|
||||
}
|
||||
return $res
|
||||
}
|
||||
|
||||
foreach {type contents} "ziplist {1 a 2 b 3 c} skiplist {1 a 2 b 3 [randstring 70 90 alpha]}" {
|
||||
set original_max_value [lindex [r config get zset-max-ziplist-value] 1]
|
||||
r config set zset-max-ziplist-value 10
|
||||
create_zset myzset $contents
|
||||
assert_encoding $type myzset
|
||||
|
||||
test "ZRANDMEMBER - $type" {
|
||||
unset -nocomplain myzset
|
||||
array set myzset {}
|
||||
for {set i 0} {$i < 100} {incr i} {
|
||||
set key [r zrandmember myzset]
|
||||
set myzset($key) 1
|
||||
}
|
||||
assert_equal [lsort [get_keys $contents]] [lsort [array names myzset]]
|
||||
}
|
||||
r config set zset-max-ziplist-value $original_max_value
|
||||
}
|
||||
|
||||
test "ZRANDMEMBER with RESP3" {
|
||||
r hello 3
|
||||
set res [r zrandmember myzset 3 withscores]
|
||||
assert_equal [llength $res] 3
|
||||
assert_equal [llength [lindex $res 1]] 2
|
||||
|
||||
set res [r zrandmember myzset 3]
|
||||
assert_equal [llength $res] 3
|
||||
assert_equal [llength [lindex $res 1]] 1
|
||||
}
|
||||
r hello 2
|
||||
|
||||
test "ZRANDMEMBER count of 0 is handled correctly" {
|
||||
r zrandmember myzset 0
|
||||
} {}
|
||||
|
||||
test "ZRANDMEMBER with <count> against non existing key" {
|
||||
r zrandmember nonexisting_key 100
|
||||
} {}
|
||||
|
||||
foreach {type contents} "
|
||||
skiplist {1 a 2 b 3 c 4 d 5 e 6 f 7 g 7 h 9 i 10 [randstring 70 90 alpha]}
|
||||
ziplist {1 a 2 b 3 c 4 d 5 e 6 f 7 g 7 h 9 i 10 j} " {
|
||||
test "ZRANDMEMBER with <count> - $type" {
|
||||
set original_max_value [lindex [r config get zset-max-ziplist-value] 1]
|
||||
r config set zset-max-ziplist-value 10
|
||||
create_zset myzset $contents
|
||||
assert_encoding $type myzset
|
||||
|
||||
# create a dict for easy lookup
|
||||
unset -nocomplain mydict
|
||||
foreach {k v} [r zrange myzset 0 -1 withscores] {
|
||||
dict append mydict $k $v
|
||||
}
|
||||
|
||||
# We'll stress different parts of the code, see the implementation
|
||||
# of ZRANDMEMBER for more information, but basically there are
|
||||
# four different code paths.
|
||||
|
||||
# PATH 1: Use negative count.
|
||||
|
||||
# 1) Check that it returns repeated elements with and without values.
|
||||
set res [r zrandmember myzset -20]
|
||||
assert_equal [llength $res] 20
|
||||
set res [r zrandmember myzset -1001]
|
||||
assert_equal [llength $res] 1001
|
||||
# again with WITHSCORES
|
||||
set res [r zrandmember myzset -20 withscores]
|
||||
assert_equal [llength $res] 40
|
||||
set res [r zrandmember myzset -1001 withscores]
|
||||
assert_equal [llength $res] 2002
|
||||
|
||||
# Test random uniform distribution
|
||||
set res [r zrandmember myzset -1000]
|
||||
assert_equal [check_histogram_distribution $res 0.05 0.15] true
|
||||
|
||||
# 2) Check that all the elements actually belong to the original zset.
|
||||
foreach {key val} $res {
|
||||
assert {[dict exists $mydict $key]}
|
||||
}
|
||||
|
||||
# 3) Check that eventually all the elements are returned.
|
||||
# Use both WITHSCORES and without
|
||||
unset -nocomplain auxset
|
||||
set iterations 1000
|
||||
while {$iterations != 0} {
|
||||
incr iterations -1
|
||||
if {[expr {$iterations % 2}] == 0} {
|
||||
set res [r zrandmember myzset -3 withscores]
|
||||
foreach {key val} $res {
|
||||
dict append auxset $key $val
|
||||
}
|
||||
} else {
|
||||
set res [r zrandmember myzset -3]
|
||||
foreach key $res {
|
||||
dict append auxset $key $val
|
||||
}
|
||||
}
|
||||
if {[lsort [dict keys $mydict]] eq
|
||||
[lsort [dict keys $auxset]]} {
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert {$iterations != 0}
|
||||
|
||||
# PATH 2: positive count (unique behavior) with requested size
|
||||
# equal or greater than set size.
|
||||
foreach size {10 20} {
|
||||
set res [r zrandmember myzset $size]
|
||||
assert_equal [llength $res] 10
|
||||
assert_equal [lsort $res] [lsort [dict keys $mydict]]
|
||||
|
||||
# again with WITHSCORES
|
||||
set res [r zrandmember myzset $size withscores]
|
||||
assert_equal [llength $res] 20
|
||||
assert_equal [lsort $res] [lsort $mydict]
|
||||
}
|
||||
|
||||
# PATH 3: Ask almost as elements as there are in the set.
|
||||
# In this case the implementation will duplicate the original
|
||||
# set and will remove random elements up to the requested size.
|
||||
#
|
||||
# PATH 4: Ask a number of elements definitely smaller than
|
||||
# the set size.
|
||||
#
|
||||
# We can test both the code paths just changing the size but
|
||||
# using the same code.
|
||||
foreach size {8 2} {
|
||||
set res [r zrandmember myzset $size]
|
||||
assert_equal [llength $res] $size
|
||||
# again with WITHSCORES
|
||||
set res [r zrandmember myzset $size withscores]
|
||||
assert_equal [llength $res] [expr {$size * 2}]
|
||||
|
||||
# 1) Check that all the elements actually belong to the
|
||||
# original set.
|
||||
foreach ele [dict keys $res] {
|
||||
assert {[dict exists $mydict $ele]}
|
||||
}
|
||||
|
||||
# 2) Check that eventually all the elements are returned.
|
||||
# Use both WITHSCORES and without
|
||||
unset -nocomplain auxset
|
||||
unset -nocomplain allkey
|
||||
set iterations [expr {1000 / $size}]
|
||||
set all_ele_return false
|
||||
while {$iterations != 0} {
|
||||
incr iterations -1
|
||||
if {[expr {$iterations % 2}] == 0} {
|
||||
set res [r zrandmember myzset $size withscores]
|
||||
foreach {key value} $res {
|
||||
dict append auxset $key $value
|
||||
lappend allkey $key
|
||||
}
|
||||
} else {
|
||||
set res [r zrandmember myzset $size]
|
||||
foreach key $res {
|
||||
dict append auxset $key
|
||||
lappend allkey $key
|
||||
}
|
||||
}
|
||||
if {[lsort [dict keys $mydict]] eq
|
||||
[lsort [dict keys $auxset]]} {
|
||||
set all_ele_return true
|
||||
}
|
||||
}
|
||||
assert_equal $all_ele_return true
|
||||
assert_equal [check_histogram_distribution $allkey 0.05 0.15] true
|
||||
}
|
||||
}
|
||||
r config set zset-max-ziplist-value $original_max_value
|
||||
}
|
||||
|
||||
}
|
||||
+18
-5
@@ -1,10 +1,11 @@
|
||||
source tests/support/cli.tcl
|
||||
|
||||
start_server {tags {"wait"}} {
|
||||
start_server {tags {"wait network"}} {
|
||||
start_server {} {
|
||||
set slave [srv 0 client]
|
||||
set slave_host [srv 0 host]
|
||||
set slave_port [srv 0 port]
|
||||
set slave_pid [srv 0 pid]
|
||||
set master [srv -1 client]
|
||||
set master_host [srv -1 host]
|
||||
set master_port [srv -1 port]
|
||||
@@ -33,13 +34,25 @@ start_server {} {
|
||||
}
|
||||
|
||||
test {WAIT should not acknowledge 1 additional copy if slave is blocked} {
|
||||
set cmd [rediscli $slave_host $slave_port "debug sleep 5"]
|
||||
exec {*}$cmd > /dev/null 2> /dev/null &
|
||||
after 1000 ;# Give keydb-cli the time to execute the command.
|
||||
exec kill -SIGSTOP $slave_pid
|
||||
$master set foo 0
|
||||
$master incr foo
|
||||
$master incr foo
|
||||
$master incr foo
|
||||
assert {[$master wait 1 3000] == 0}
|
||||
assert {[$master wait 1 1000] == 0}
|
||||
exec kill -SIGCONT $slave_pid
|
||||
assert {[$master wait 1 1000] == 1}
|
||||
}
|
||||
|
||||
test {WAIT implicitly blocks on client pause since ACKs aren't sent} {
|
||||
exec kill -SIGSTOP $slave_pid
|
||||
$master multi
|
||||
$master incr foo
|
||||
$master client pause 10000 write
|
||||
$master exec
|
||||
assert {[$master wait 1 1000] == 0}
|
||||
$master client unpause
|
||||
exec kill -SIGCONT $slave_pid
|
||||
assert {[$master wait 1 1000] == 1}
|
||||
}
|
||||
}}
|
||||
Reference in new issue
Block a user