Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
445aa844
Unverified
Commit
445aa844
authored
Feb 22, 2021
by
Oran Agra
Committed by
GitHub
Feb 22, 2021
Browse files
Merge Redis 6.2.0 GA
Redis 6.2.0 GA
parents
2dba1e39
f098fe31
Changes
89
Hide whitespace changes
Inline
Side-by-side
tests/unit/moduleapi/infotest.tcl
View file @
445aa844
...
@@ -85,5 +85,10 @@ start_server {tags {"modules"}} {
...
@@ -85,5 +85,10 @@ start_server {tags {"modules"}} {
set keys
[
scan
[
regexp -inline
{
keys
\=
([
\d
]
*
)}
$keyspace
]
keys=%d
]
set keys
[
scan
[
regexp -inline
{
keys
\=
([
\d
]
*
)}
$keyspace
]
keys=%d
]
}
{
3
}
}
{
3
}
test
{
module info unsafe fields
}
{
set info
[
r info infotest_unsafe
]
assert_match
{
*infotest_unsafe_field:value=1*
}
$info
}
# TODO: test crash report.
# TODO: test crash report.
}
}
tests/unit/moduleapi/zset.tcl
0 → 100644
View file @
445aa844
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
]
}
}
tests/unit/oom-score-adj.tcl
View file @
445aa844
...
@@ -39,7 +39,12 @@ if {$system_name eq {linux}} {
...
@@ -39,7 +39,12 @@ if {$system_name eq {linux}} {
r bgsave
r bgsave
set child_pid
[
get_child_pid 0
]
set child_pid
[
get_child_pid 0
]
assert_equal
[
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
# Failed oom-score-adj tests can only run unprivileged
...
...
tests/unit/other.tcl
View file @
445aa844
...
@@ -55,7 +55,7 @@ start_server {tags {"other"}} {
...
@@ -55,7 +55,7 @@ start_server {tags {"other"}} {
}
{
*index is out of range*
}
}
{
*index is out of range*
}
tags
{
consistency
}
{
tags
{
consistency
}
{
if
{
!
[
catch
{
package require sha1
}]
}
{
if
{
true
}
{
if
{
$::accurate
}
{
set numops 10000
}
else
{
set numops 1000
}
if
{
$::accurate
}
{
set numops 10000
}
else
{
set numops 1000
}
test
{
Check consistency of different data types after a reload
}
{
test
{
Check consistency of different data types after a reload
}
{
r flushdb
r flushdb
...
...
tests/unit/scripting.tcl
View file @
445aa844
...
@@ -468,6 +468,7 @@ start_server {tags {"scripting"}} {
...
@@ -468,6 +468,7 @@ start_server {tags {"scripting"}} {
r slaveof no one
r slaveof no one
set res
set res
}
{
102
}
}
{
102
}
r config set aof-use-rdb-preamble yes
test
{
EVAL timeout from AOF
}
{
test
{
EVAL timeout from AOF
}
{
# generate a long running script that is propagated to the AOF as script
# generate a long running script that is propagated to the AOF as script
...
@@ -505,8 +506,6 @@ start_server {tags {"scripting"}} {
...
@@ -505,8 +506,6 @@ start_server {tags {"scripting"}} {
$rd close
$rd close
r get x
r get x
}
{
y
}
}
{
y
}
r config set aof-use-rdb-preamble yes
r config set lua-replicate-commands yes
test
{
We can call scripts rewriting client->argv from Lua
}
{
test
{
We can call scripts rewriting client->argv from Lua
}
{
r del myset
r del myset
...
...
tests/unit/tracking.tcl
View file @
445aa844
...
@@ -17,6 +17,10 @@ start_server {tags {"tracking network"}} {
...
@@ -17,6 +17,10 @@ start_server {tags {"tracking network"}} {
proc clean_all
{}
{
proc clean_all
{}
{
uplevel
{
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 QUIT
$rd_redirection QUIT
$rd_redirection QUIT
set rd
[
redis_deferring_client
]
set rd
[
redis_deferring_client
]
...
@@ -26,7 +30,6 @@ start_server {tags {"tracking network"}} {
...
@@ -26,7 +30,6 @@ start_server {tags {"tracking network"}} {
$rd_redirection subscribe __redis__:invalidate
$rd_redirection subscribe __redis__:invalidate
$rd_redirection read
;
# Consume the SUBSCRIBE reply.
$rd_redirection read
;
# Consume the SUBSCRIBE reply.
r FLUSHALL
r FLUSHALL
r CLIENT TRACKING off
r HELLO 2
r HELLO 2
r config set tracking-table-max-keys 1000000
r config set tracking-table-max-keys 1000000
}
}
...
@@ -52,7 +55,7 @@ start_server {tags {"tracking network"}} {
...
@@ -52,7 +55,7 @@ start_server {tags {"tracking network"}} {
# so that we can check for leaks, as a side effect.
# so that we can check for leaks, as a side effect.
r MGET a b c d e f g
r MGET a b c d e f g
r CLIENT TRACKING off
r CLIENT TRACKING off
}
}
{
*OK
}
test
{
Clients can enable the BCAST mode with the empty prefix
}
{
test
{
Clients can enable the BCAST mode with the empty prefix
}
{
r CLIENT TRACKING on BCAST REDIRECT $redir_id
r CLIENT TRACKING on BCAST REDIRECT $redir_id
...
@@ -72,6 +75,8 @@ start_server {tags {"tracking network"}} {
...
@@ -72,6 +75,8 @@ start_server {tags {"tracking network"}} {
r INCR a:2
r INCR a:2
r INCR b:1
r INCR b:1
r INCR b:2
r INCR b:2
# we should not get this key
r INCR c:1
r EXEC
r EXEC
# Because of the internals, we know we are going to receive
# Because of the internals, we know we are going to receive
# two separated notifications for the two different prefixes.
# two separated notifications for the two different prefixes.
...
@@ -96,7 +101,7 @@ start_server {tags {"tracking network"}} {
...
@@ -96,7 +101,7 @@ start_server {tags {"tracking network"}} {
r SET loopkey 1
;
# We should not get this
r SET loopkey 1
;
# We should not get this
$rd_sg 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
# Because of the internals, we know we are going to receive
# two separated notifications for the two different
prefixe
s.
# two separated notifications for the two different
key
s.
set keys1
[
lsort
[
lindex
[
$rd
_redirection read
]
2
]]
set keys1
[
lsort
[
lindex
[
$rd
_redirection read
]
2
]]
set keys2
[
lsort
[
lindex
[
$rd
_redirection read
]
2
]]
set keys2
[
lsort
[
lindex
[
$rd
_redirection read
]
2
]]
set keys
[
lsort
[
list
{*}
$keys1
{*}
$keys2
]]
set keys
[
lsort
[
list
{*}
$keys1
{*}
$keys2
]]
...
@@ -109,8 +114,8 @@ start_server {tags {"tracking network"}} {
...
@@ -109,8 +114,8 @@ start_server {tags {"tracking network"}} {
$rd_sg 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
r SET loopkey 1
;
# We should not get this
$rd_sg 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 receiv
e
# Because
$rd_sg send command synchronously, we know we ar
e
# two separated notifications
for the two different prefixes
.
#
going to receive
two separated notifications.
set keys1
[
lsort
[
lindex
[
$rd
_redirection read
]
2
]]
set keys1
[
lsort
[
lindex
[
$rd
_redirection read
]
2
]]
set keys2
[
lsort
[
lindex
[
$rd
_redirection read
]
2
]]
set keys2
[
lsort
[
lindex
[
$rd
_redirection read
]
2
]]
set keys
[
lsort
[
list
{*}
$keys1
{*}
$keys2
]]
set keys
[
lsort
[
list
{*}
$keys1
{*}
$keys2
]]
...
@@ -123,10 +128,7 @@ start_server {tags {"tracking network"}} {
...
@@ -123,10 +128,7 @@ start_server {tags {"tracking network"}} {
r SET mykey myval px 1
r SET mykey myval px 1
r SET mykeyotherkey myval
;
# We should not get it
r SET mykeyotherkey myval
;
# We should not get it
after 1000
after 1000
# Because of the internals, we know we are going to receive
set keys
[
lsort
[
lindex
[
$rd
_redirection read
]
2
]]
# two separated notifications for the two different prefixes.
set keys1
[
lsort
[
lindex
[
$rd
_redirection read
]
2
]]
set keys
[
lsort
[
list
{*}
$keys1
]]
assert
{
$keys
eq
{
mykey
}}
assert
{
$keys
eq
{
mykey
}}
}
}
...
@@ -172,6 +174,7 @@ start_server {tags {"tracking network"}} {
...
@@ -172,6 +174,7 @@ start_server {tags {"tracking network"}} {
}
}
test
{
Invalidations of previous keys can be redirected after switching to RESP3
}
{
test
{
Invalidations of previous keys can be redirected after switching to RESP3
}
{
r HELLO 2
$rd_sg SET key1 1
$rd_sg SET key1 1
r GET key1
r GET key1
r HELLO 3
r HELLO 3
...
@@ -194,28 +197,33 @@ start_server {tags {"tracking network"}} {
...
@@ -194,28 +197,33 @@ start_server {tags {"tracking network"}} {
$rd_sg SET key1 1
$rd_sg SET key1 1
r GET key1
r GET key1
$rd_redirection QUIT
$rd_redirection QUIT
assert_equal OK
[
$rd
_redirection read
]
$rd_sg SET key1 2
$rd_sg SET key1 2
set MAX_TRIES 100
set MAX_TRIES 100
for
{
set i 0
}
{
$i
<= $MAX_TRIES && $res <= 0
}
{
incr i
}
{
set res -1
for
{
set i 0
}
{
$i
<= $MAX_TRIES && $res < 0
}
{
incr i
}
{
set res
[
lsearch -exact
[
r PING
]
"tracking-redir-broken"
]
set res
[
lsearch -exact
[
r PING
]
"tracking-redir-broken"
]
}
}
assert
{
$res
>= 0
}
assert
{
$res
>= 0
}
}
# Consume PING reply
assert_equal PONG
[
r read
]
test
{
Different clients can redirect to the same connection
}
{
# Reinstantiating after QUIT
# Reinstantiating after QUIT
set rd_redirection
[
redis_deferring_client
]
set rd_redirection
[
redis_deferring_client
]
$rd_redirection CLIENT ID
$rd_redirection CLIENT ID
set redir_id
[
$rd
_redirection read
]
set redir_id
[
$rd
_redirection read
]
$rd_redirection SUBSCRIBE __redis__:invalidate
$rd_redirection SUBSCRIBE __redis__:invalidate
$rd_redirection read
;
# Consume the SUBSCRIBE reply
$rd_redirection read
;
# Consume the SUBSCRIBE reply
}
test
{
Different clients can redirect to the same connection
}
{
r CLIENT TRACKING on REDIRECT $redir_id
r CLIENT TRACKING on REDIRECT $redir_id
$rd CLIENT TRACKING on REDIRECT $redir_id
$rd CLIENT TRACKING on REDIRECT $redir_id
$rd read
;
# Consume the TRACKING reply
assert_equal OK
[
$rd
read
]
;
# Consume the TRACKING reply
$rd_sg MSET key1 1 key2 1
$rd_sg MSET key1 1 key2 1
r GET key1
r GET key1
$rd GET key2
$rd GET key2
$rd read
;
# Consume the GET reply
assert_equal 1
[
$rd
read
]
;
# Consume the GET reply
$rd_sg INCR key1
$rd_sg INCR key1
$rd_sg INCR key2
$rd_sg INCR key2
set res1
[
lindex
[
$rd
_redirection read
]
2
]
set res1
[
lindex
[
$rd
_redirection read
]
2
]
...
@@ -226,18 +234,19 @@ start_server {tags {"tracking network"}} {
...
@@ -226,18 +234,19 @@ start_server {tags {"tracking network"}} {
test
{
Different clients using different protocols can track the same key
}
{
test
{
Different clients using different protocols can track the same key
}
{
$rd HELLO 3
$rd HELLO 3
$rd read
;
# Consume the HELLO reply
set reply
[
$rd
read
]
;
# Consume the HELLO reply
assert_equal 3
[
dict get $reply proto
]
$rd CLIENT TRACKING on
$rd CLIENT TRACKING on
$rd read
;
# Consume the TRACKING reply
assert_equal OK
[
$rd
read
]
;
# Consume the TRACKING reply
$rd_sg set key1 1
$rd_sg set key1 1
r GET key1
r GET key1
$rd GET key1
$rd GET key1
$rd read
;
# Consume the GET reply
assert_equal 1
[
$rd
read
]
;
# Consume the GET reply
$rd_sg INCR key1
$rd_sg INCR key1
set res1
[
lindex
[
$rd
_redirection read
]
2
]
set res1
[
lindex
[
$rd
_redirection read
]
2
]
$rd PING
;
# Non redirecting client has to talk to the server in order to get invalidation message
$rd PING
;
# Non redirecting client has to talk to the server in order to get invalidation message
set res2
[
lindex
[
split
[
$rd
read
]
" "
]
1
]
set res2
[
lindex
[
split
[
$rd
read
]
" "
]
1
]
$rd read
;
# Consume the PING reply, which comes together with the invalidation message
assert_equal PONG
[
$rd
read
]
;
# Consume the PING reply, which comes together with the invalidation message
assert
{
$res1
eq
{
key1
}}
assert
{
$res1
eq
{
key1
}}
assert
{
$res2
eq
{
key1
}}
assert
{
$res2
eq
{
key1
}}
}
}
...
@@ -292,35 +301,36 @@ start_server {tags {"tracking network"}} {
...
@@ -292,35 +301,36 @@ start_server {tags {"tracking network"}} {
test
{
Able to redirect to a RESP3 client
}
{
test
{
Able to redirect to a RESP3 client
}
{
$rd_redirection UNSUBSCRIBE __redis__:invalidate
;
# Need to unsub first before we can do HELLO 3
$rd_redirection UNSUBSCRIBE __redis__:invalidate
;
# Need to unsub first before we can do HELLO 3
$rd_redirection read
;
# Consume the UNSUBSCRIBE reply
set res
[
$rd
_redirection read
]
;
# Consume the UNSUBSCRIBE reply
assert_equal
{
__redis__:invalidate
}
[
lindex $res 1
]
$rd_redirection HELLO 3
$rd_redirection HELLO 3
$rd_redirection read
;
# Consume the HELLO reply
set res
[
$rd
_redirection read
]
;
# Consume the HELLO reply
assert_equal
[
dict get $reply proto
]
3
$rd_redirection SUBSCRIBE __redis__:invalidate
$rd_redirection SUBSCRIBE __redis__:invalidate
$rd_redirection read
;
# Consume the SUBSCRIBE reply
set res
[
$rd
_redirection read
]
;
# Consume the SUBSCRIBE reply
assert_equal
{
__redis__:invalidate
}
[
lindex $res 1
]
r CLIENT TRACKING on REDIRECT $redir_id
r CLIENT TRACKING on REDIRECT $redir_id
$rd_sg SET key1 1
$rd_sg SET key1 1
r GET key1
r GET key1
$rd_sg INCR key1
$rd_sg INCR key1
set res
[
lindex
[
$rd
_redirection read
]
1
]
set res
[
lindex
[
$rd
_redirection read
]
1
]
assert
{
$res
eq
{
key1
}}
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
}
{
test
{
After switching from normal tracking to BCAST mode, no invalidation message is produced for pre-BCAST keys
}
{
$rd HELLO 3
r CLIENT TRACKING off
$rd read
;
# Consume the HELLO reply
r HELLO 3
$rd CLIENT TRACKING on
r CLIENT TRACKING on
$rd read
;
# Consume the TRACKING reply
$rd_sg SET key1 1
$rd_sg SET key1 1
$rd GET key1
r GET key1
$rd read
;
# Consume the GET reply
r CLIENT TRACKING off
$rd CLIENT TRACKING off
r CLIENT TRACKING on BCAST
$rd read
;
# Consume the TRACKING reply
$rd CLIENT TRACKING on BCAST
$rd read
;
# Consume the TRACKING reply
$rd_sg INCR key1
$rd_sg INCR key1
$rd PING
set inv_msg
[
r PING
]
set inv_msg
[
$rd
read
]
set ping_reply
[
r read
]
set ping_reply
[
$rd
read
]
assert
{
$inv
_msg eq
{
invalidate key1
}}
assert
{
$inv
_msg eq
{
invalidate key1
}}
assert
{
$ping
_reply eq
{
PONG
}}
assert
{
$ping
_reply eq
{
PONG
}}
}
}
...
@@ -344,7 +354,6 @@ start_server {tags {"tracking network"}} {
...
@@ -344,7 +354,6 @@ start_server {tags {"tracking network"}} {
}
}
test
{
Tracking gets notification on tracking table key eviction
}
{
test
{
Tracking gets notification on tracking table key eviction
}
{
$rd_redirection HELLO 2
r CLIENT TRACKING off
r CLIENT TRACKING off
r CLIENT TRACKING on REDIRECT $redir_id NOLOOP
r CLIENT TRACKING on REDIRECT $redir_id NOLOOP
r MSET key1 1 key2 2
r MSET key1 1 key2 2
...
@@ -368,7 +377,6 @@ start_server {tags {"tracking network"}} {
...
@@ -368,7 +377,6 @@ start_server {tags {"tracking network"}} {
test
{
Invalidation message received for flushall
}
{
test
{
Invalidation message received for flushall
}
{
clean_all
clean_all
r CLIENT TRACKING off
r CLIENT TRACKING on REDIRECT $redir_id
r CLIENT TRACKING on REDIRECT $redir_id
$rd_sg SET key1 1
$rd_sg SET key1 1
r GET key1
r GET key1
...
@@ -379,7 +387,6 @@ start_server {tags {"tracking network"}} {
...
@@ -379,7 +387,6 @@ start_server {tags {"tracking network"}} {
test
{
Invalidation message received for flushdb
}
{
test
{
Invalidation message received for flushdb
}
{
clean_all
clean_all
r CLIENT TRACKING off
r CLIENT TRACKING on REDIRECT $redir_id
r CLIENT TRACKING on REDIRECT $redir_id
$rd_sg SET key1 1
$rd_sg SET key1 1
r GET key1
r GET key1
...
@@ -422,15 +429,29 @@ start_server {tags {"tracking network"}} {
...
@@ -422,15 +429,29 @@ start_server {tags {"tracking network"}} {
r GET key1
r GET key1
r GET key2
r GET key2
$rd CLIENT TRACKING on BCAST PREFIX prefix:
$rd CLIENT TRACKING on BCAST PREFIX prefix:
assert
[
string match *OK*
[
$rd
read
]]
$rd_sg SET prefix:key1 1
$rd_sg SET prefix:key1 1
$rd_sg SET prefix:key2 2
$rd_sg SET prefix:key2 2
set info
[
r info
]
set info
[
r info
]
regexp
"
\r\n
tracking_total_items:(.*?)
\r\n
"
$info _ total_items
regexp
"
\r\n
tracking_total_items:(.*?)
\r\n
"
$info _ total_items
regexp
"
\r\n
tracking_total_keys:(.*?)
\r\n
"
$info _ total_keys
regexp
"
\r\n
tracking_total_keys:(.*?)
\r\n
"
$info _ total_keys
regexp
"
\r\n
tracking_total_prefixes:(.*?)
\r\n
"
$info _ total_prefixes
regexp
"
\r\n
tracking_total_prefixes:(.*?)
\r\n
"
$info _ total_prefixes
regexp
"
\r\n
tracking_clients:(.*?)
\r\n
"
$info _ tracking_clients
assert
{
$total
_items == 2
}
assert
{
$total
_items == 2
}
assert
{
$total
_keys == 2
}
assert
{
$total
_keys == 2
}
assert
{
$total
_prefixes == 1
}
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
}
{
test
{
CLIENT TRACKINGINFO provides reasonable results when tracking off
}
{
...
@@ -510,6 +531,32 @@ start_server {tags {"tracking network"}} {
...
@@ -510,6 +531,32 @@ start_server {tags {"tracking network"}} {
assert_equal
{
0
}
$redirect
assert_equal
{
0
}
$redirect
set prefixes
[
lsort
[
dict get $res prefixes
]]
set prefixes
[
lsort
[
dict get $res prefixes
]]
assert_equal
{
bar foo
}
$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_redirection close
...
...
tests/unit/type/hash.tcl
View file @
445aa844
...
@@ -96,9 +96,17 @@ start_server {tags {"hash"}} {
...
@@ -96,9 +96,17 @@ start_server {tags {"hash"}} {
# 1) Check that it returns repeated elements with and without values.
# 1) Check that it returns repeated elements with and without values.
set res
[
r hrandfield myhash -20
]
set res
[
r hrandfield myhash -20
]
assert_equal
[
llength $res
]
20
assert_equal
[
llength $res
]
20
set res
[
r hrandfield myhash -1001
]
assert_equal
[
llength $res
]
1001
# again with WITHVALUES
# again with WITHVALUES
set res
[
r hrandfield myhash -20 withvalues
]
set res
[
r hrandfield myhash -20 withvalues
]
assert_equal
[
llength $res
]
40
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.
# 2) Check that all the elements actually belong to the original hash.
foreach
{
key val
}
$res
{
foreach
{
key val
}
$res
{
...
@@ -167,26 +175,31 @@ start_server {tags {"hash"}} {
...
@@ -167,26 +175,31 @@ start_server {tags {"hash"}} {
# 2) Check that eventually all the elements are returned.
# 2) Check that eventually all the elements are returned.
# Use both WITHVALUES and without
# Use both WITHVALUES and without
unset -nocomplain auxset
unset -nocomplain auxset
set iterations 1000
unset -nocomplain allkey
set iterations
[
expr
{
1000 / $size
}]
set all_ele_return false
while
{
$iterations
!= 0
}
{
while
{
$iterations
!= 0
}
{
incr iterations -1
incr iterations -1
if
{[
expr
{
$iterations
% 2
}]
== 0
}
{
if
{[
expr
{
$iterations
% 2
}]
== 0
}
{
set res
[
r hrandfield myhash $size withvalues
]
set res
[
r hrandfield myhash $size withvalues
]
foreach
{
key value
}
$res
{
foreach
{
key value
}
$res
{
dict append auxset $key $value
dict append auxset $key $value
lappend allkey $key
}
}
}
else
{
}
else
{
set res
[
r hrandfield myhash $size
]
set res
[
r hrandfield myhash $size
]
foreach key $res
{
foreach key $res
{
dict append auxset $key
dict append auxset $key
lappend allkey $key
}
}
}
}
if
{[
lsort
[
dict keys $mydict
]]
eq
if
{[
lsort
[
dict keys $mydict
]]
eq
[
lsort
[
dict keys $auxset
]]}
{
[
lsort
[
dict keys $auxset
]]}
{
break
;
set all_ele_return true
}
}
}
}
assert
{
$iterations
!= 0
}
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
r config set hash-max-ziplist-value $original_max_value
...
...
tests/unit/type/set.tcl
View file @
445aa844
...
@@ -515,6 +515,43 @@ start_server {
...
@@ -515,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
{}
{
proc setup_move
{}
{
r del myset3 myset4
r del myset3 myset4
create_set myset1
{
1 a b
}
create_set myset1
{
1 a b
}
...
...
tests/unit/type/zset.tcl
View file @
445aa844
...
@@ -1646,9 +1646,17 @@ start_server {tags {"zset"}} {
...
@@ -1646,9 +1646,17 @@ start_server {tags {"zset"}} {
# 1) Check that it returns repeated elements with and without values.
# 1) Check that it returns repeated elements with and without values.
set res
[
r zrandmember myzset -20
]
set res
[
r zrandmember myzset -20
]
assert_equal
[
llength $res
]
20
assert_equal
[
llength $res
]
20
set res
[
r zrandmember myzset -1001
]
assert_equal
[
llength $res
]
1001
# again with WITHSCORES
# again with WITHSCORES
set res
[
r zrandmember myzset -20 withscores
]
set res
[
r zrandmember myzset -20 withscores
]
assert_equal
[
llength $res
]
40
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.
# 2) Check that all the elements actually belong to the original zset.
foreach
{
key val
}
$res
{
foreach
{
key val
}
$res
{
...
@@ -1717,26 +1725,31 @@ start_server {tags {"zset"}} {
...
@@ -1717,26 +1725,31 @@ start_server {tags {"zset"}} {
# 2) Check that eventually all the elements are returned.
# 2) Check that eventually all the elements are returned.
# Use both WITHSCORES and without
# Use both WITHSCORES and without
unset -nocomplain auxset
unset -nocomplain auxset
set iterations 1000
unset -nocomplain allkey
set iterations
[
expr
{
1000 / $size
}]
set all_ele_return false
while
{
$iterations
!= 0
}
{
while
{
$iterations
!= 0
}
{
incr iterations -1
incr iterations -1
if
{[
expr
{
$iterations
% 2
}]
== 0
}
{
if
{[
expr
{
$iterations
% 2
}]
== 0
}
{
set res
[
r zrandmember myzset $size withscores
]
set res
[
r zrandmember myzset $size withscores
]
foreach
{
key value
}
$res
{
foreach
{
key value
}
$res
{
dict append auxset $key $value
dict append auxset $key $value
lappend allkey $key
}
}
}
else
{
}
else
{
set res
[
r zrandmember myzset $size
]
set res
[
r zrandmember myzset $size
]
foreach key $res
{
foreach key $res
{
dict append auxset $key
dict append auxset $key
lappend allkey $key
}
}
}
}
if
{[
lsort
[
dict keys $mydict
]]
eq
if
{[
lsort
[
dict keys $mydict
]]
eq
[
lsort
[
dict keys $auxset
]]}
{
[
lsort
[
dict keys $auxset
]]}
{
break
;
set all_ele_return true
}
}
}
}
assert
{
$iterations
!= 0
}
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
r config set zset-max-ziplist-value $original_max_value
...
...
Prev
1
2
3
4
5
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment