2013-10-30 06:34:01 -04:00
|
|
|
start_server {tags {"scan"}} {
|
|
|
|
test "SCAN basic" {
|
|
|
|
r flushdb
|
|
|
|
r debug populate 1000
|
|
|
|
|
|
|
|
set cur 0
|
|
|
|
set keys {}
|
|
|
|
while 1 {
|
|
|
|
set res [r scan $cur]
|
|
|
|
set cur [lindex $res 0]
|
|
|
|
set k [lindex $res 1]
|
2013-10-30 06:36:12 -04:00
|
|
|
lappend keys {*}$k
|
2013-10-30 06:34:01 -04:00
|
|
|
if {$cur == 0} break
|
|
|
|
}
|
|
|
|
|
2013-10-30 06:36:12 -04:00
|
|
|
set keys [lsort -unique $keys]
|
2013-10-30 06:34:01 -04:00
|
|
|
assert_equal 1000 [llength $keys]
|
|
|
|
}
|
|
|
|
|
|
|
|
test "SCAN COUNT" {
|
|
|
|
r flushdb
|
|
|
|
r debug populate 1000
|
|
|
|
|
|
|
|
set cur 0
|
|
|
|
set keys {}
|
|
|
|
while 1 {
|
|
|
|
set res [r scan $cur count 5]
|
|
|
|
set cur [lindex $res 0]
|
|
|
|
set k [lindex $res 1]
|
2013-10-30 06:36:12 -04:00
|
|
|
lappend keys {*}$k
|
2013-10-30 06:34:01 -04:00
|
|
|
if {$cur == 0} break
|
|
|
|
}
|
|
|
|
|
2013-10-30 06:36:12 -04:00
|
|
|
set keys [lsort -unique $keys]
|
2013-10-30 06:34:01 -04:00
|
|
|
assert_equal 1000 [llength $keys]
|
|
|
|
}
|
|
|
|
|
|
|
|
test "SCAN MATCH" {
|
|
|
|
r flushdb
|
|
|
|
r debug populate 1000
|
|
|
|
|
|
|
|
set cur 0
|
|
|
|
set keys {}
|
|
|
|
while 1 {
|
|
|
|
set res [r scan $cur match "key:1??"]
|
|
|
|
set cur [lindex $res 0]
|
|
|
|
set k [lindex $res 1]
|
2013-10-30 06:36:12 -04:00
|
|
|
lappend keys {*}$k
|
2013-10-30 06:34:01 -04:00
|
|
|
if {$cur == 0} break
|
|
|
|
}
|
|
|
|
|
2013-10-30 06:36:12 -04:00
|
|
|
set keys [lsort -unique $keys]
|
2013-10-30 06:34:01 -04:00
|
|
|
assert_equal 100 [llength $keys]
|
|
|
|
}
|
2013-10-30 06:58:04 -04:00
|
|
|
|
|
|
|
foreach enc {intset hashtable} {
|
|
|
|
test "SSCAN with encoding $enc" {
|
|
|
|
# Create the Set
|
|
|
|
r del set
|
|
|
|
if {$enc eq {intset}} {
|
|
|
|
set prefix ""
|
|
|
|
} else {
|
|
|
|
set prefix "ele:"
|
|
|
|
}
|
|
|
|
set elements {}
|
|
|
|
for {set j 0} {$j < 100} {incr j} {
|
|
|
|
lappend elements ${prefix}${j}
|
|
|
|
}
|
|
|
|
r sadd set {*}$elements
|
|
|
|
|
|
|
|
# Verify that the encoding matches.
|
|
|
|
assert {[r object encoding set] eq $enc}
|
|
|
|
|
|
|
|
# Test SSCAN
|
|
|
|
set cur 0
|
|
|
|
set keys {}
|
|
|
|
while 1 {
|
|
|
|
set res [r sscan set $cur]
|
|
|
|
set cur [lindex $res 0]
|
|
|
|
set k [lindex $res 1]
|
|
|
|
lappend keys {*}$k
|
|
|
|
if {$cur == 0} break
|
|
|
|
}
|
|
|
|
|
|
|
|
set keys [lsort -unique $keys]
|
|
|
|
assert_equal 100 [llength $keys]
|
|
|
|
}
|
|
|
|
}
|
2013-10-30 11:24:39 -04:00
|
|
|
|
|
|
|
foreach enc {ziplist hashtable} {
|
|
|
|
test "HSCAN with encoding $enc" {
|
|
|
|
# Create the Hash
|
|
|
|
r del hash
|
|
|
|
if {$enc eq {ziplist}} {
|
|
|
|
set count 30
|
|
|
|
} else {
|
|
|
|
set count 1000
|
|
|
|
}
|
|
|
|
set elements {}
|
|
|
|
for {set j 0} {$j < $count} {incr j} {
|
|
|
|
lappend elements key:$j $j
|
|
|
|
}
|
|
|
|
r hmset hash {*}$elements
|
|
|
|
|
|
|
|
# Verify that the encoding matches.
|
|
|
|
assert {[r object encoding hash] eq $enc}
|
|
|
|
|
|
|
|
# Test HSCAN
|
|
|
|
set cur 0
|
|
|
|
set keys {}
|
|
|
|
while 1 {
|
|
|
|
set res [r hscan hash $cur]
|
|
|
|
set cur [lindex $res 0]
|
|
|
|
set k [lindex $res 1]
|
|
|
|
lappend keys {*}$k
|
|
|
|
if {$cur == 0} break
|
|
|
|
}
|
|
|
|
|
|
|
|
set keys2 {}
|
|
|
|
foreach {k v} $keys {
|
|
|
|
assert {$k eq "key:$v"}
|
|
|
|
lappend keys2 $k
|
|
|
|
}
|
|
|
|
|
|
|
|
set keys2 [lsort -unique $keys2]
|
|
|
|
assert_equal $count [llength $keys2]
|
|
|
|
}
|
|
|
|
}
|
2013-10-30 06:34:01 -04:00
|
|
|
}
|