2015-02-25 04:31:29 -05:00
|
|
|
start_server {tags {"keyspace"}} {
|
|
|
|
test {DEL against a single item} {
|
|
|
|
r set x foo
|
|
|
|
assert {[r get x] eq "foo"}
|
|
|
|
r del x
|
|
|
|
r get x
|
|
|
|
} {}
|
|
|
|
|
|
|
|
test {Vararg DEL} {
|
2021-06-09 08:13:24 -04:00
|
|
|
r set foo1{t} a
|
|
|
|
r set foo2{t} b
|
|
|
|
r set foo3{t} c
|
|
|
|
list [r del foo1{t} foo2{t} foo3{t} foo4{t}] [r mget foo1{t} foo2{t} foo3{t}]
|
2015-02-25 04:31:29 -05:00
|
|
|
} {3 {{} {} {}}}
|
|
|
|
|
2021-06-09 08:13:24 -04:00
|
|
|
test {Untagged multi-key commands} {
|
|
|
|
r mset foo1 a foo2 b foo3 c
|
|
|
|
assert_equal {a b c {}} [r mget foo1 foo2 foo3 foo4]
|
|
|
|
r del foo1 foo2 foo3 foo4
|
|
|
|
} {3} {cluster:skip}
|
|
|
|
|
2015-02-25 04:31:29 -05:00
|
|
|
test {KEYS with pattern} {
|
|
|
|
foreach key {key_x key_y key_z foo_a foo_b foo_c} {
|
|
|
|
r set $key hello
|
|
|
|
}
|
|
|
|
lsort [r keys foo*]
|
|
|
|
} {foo_a foo_b foo_c}
|
|
|
|
|
|
|
|
test {KEYS to get all keys} {
|
|
|
|
lsort [r keys *]
|
|
|
|
} {foo_a foo_b foo_c key_x key_y key_z}
|
|
|
|
|
|
|
|
test {DBSIZE} {
|
|
|
|
r dbsize
|
|
|
|
} {6}
|
|
|
|
|
|
|
|
test {DEL all keys} {
|
|
|
|
foreach key [r keys *] {r del $key}
|
|
|
|
r dbsize
|
|
|
|
} {0}
|
|
|
|
|
|
|
|
test "DEL against expired key" {
|
|
|
|
r debug set-active-expire 0
|
|
|
|
r setex keyExpire 1 valExpire
|
|
|
|
after 1100
|
|
|
|
assert_equal 0 [r del keyExpire]
|
|
|
|
r debug set-active-expire 1
|
2021-06-09 08:13:24 -04:00
|
|
|
} {OK} {needs:debug}
|
2015-02-25 04:31:29 -05:00
|
|
|
|
|
|
|
test {EXISTS} {
|
|
|
|
set res {}
|
|
|
|
r set newkey test
|
|
|
|
append res [r exists newkey]
|
|
|
|
r del newkey
|
|
|
|
append res [r exists newkey]
|
|
|
|
} {10}
|
|
|
|
|
|
|
|
test {Zero length value in key. SET/GET/EXISTS} {
|
|
|
|
r set emptykey {}
|
|
|
|
set res [r get emptykey]
|
|
|
|
append res [r exists emptykey]
|
|
|
|
r del emptykey
|
|
|
|
append res [r exists emptykey]
|
|
|
|
} {10}
|
|
|
|
|
|
|
|
test {Commands pipelining} {
|
|
|
|
set fd [r channel]
|
|
|
|
puts -nonewline $fd "SET k1 xyzk\r\nGET k1\r\nPING\r\n"
|
|
|
|
flush $fd
|
|
|
|
set res {}
|
|
|
|
append res [string match OK* [r read]]
|
|
|
|
append res [r read]
|
|
|
|
append res [string match PONG* [r read]]
|
|
|
|
format $res
|
|
|
|
} {1xyzk1}
|
|
|
|
|
|
|
|
test {Non existing command} {
|
|
|
|
catch {r foobaredcommand} err
|
|
|
|
string match ERR* $err
|
|
|
|
} {1}
|
|
|
|
|
|
|
|
test {RENAME basic usage} {
|
2021-06-09 08:13:24 -04:00
|
|
|
r set mykey{t} hello
|
|
|
|
r rename mykey{t} mykey1{t}
|
|
|
|
r rename mykey1{t} mykey2{t}
|
|
|
|
r get mykey2{t}
|
2015-02-25 04:31:29 -05:00
|
|
|
} {hello}
|
|
|
|
|
|
|
|
test {RENAME source key should no longer exist} {
|
|
|
|
r exists mykey
|
|
|
|
} {0}
|
|
|
|
|
|
|
|
test {RENAME against already existing key} {
|
2021-06-09 08:13:24 -04:00
|
|
|
r set mykey{t} a
|
|
|
|
r set mykey2{t} b
|
|
|
|
r rename mykey2{t} mykey{t}
|
|
|
|
set res [r get mykey{t}]
|
|
|
|
append res [r exists mykey2{t}]
|
2015-02-25 04:31:29 -05:00
|
|
|
} {b0}
|
|
|
|
|
|
|
|
test {RENAMENX basic usage} {
|
2021-06-09 08:13:24 -04:00
|
|
|
r del mykey{t}
|
|
|
|
r del mykey2{t}
|
|
|
|
r set mykey{t} foobar
|
|
|
|
r renamenx mykey{t} mykey2{t}
|
|
|
|
set res [r get mykey2{t}]
|
|
|
|
append res [r exists mykey{t}]
|
2015-02-25 04:31:29 -05:00
|
|
|
} {foobar0}
|
|
|
|
|
|
|
|
test {RENAMENX against already existing key} {
|
2021-06-09 08:13:24 -04:00
|
|
|
r set mykey{t} foo
|
|
|
|
r set mykey2{t} bar
|
|
|
|
r renamenx mykey{t} mykey2{t}
|
2015-02-25 04:31:29 -05:00
|
|
|
} {0}
|
|
|
|
|
|
|
|
test {RENAMENX against already existing key (2)} {
|
2021-06-09 08:13:24 -04:00
|
|
|
set res [r get mykey{t}]
|
|
|
|
append res [r get mykey2{t}]
|
2015-02-25 04:31:29 -05:00
|
|
|
} {foobar}
|
|
|
|
|
|
|
|
test {RENAME against non existing source key} {
|
2021-06-09 08:13:24 -04:00
|
|
|
catch {r rename nokey{t} foobar{t}} err
|
2015-02-25 04:31:29 -05:00
|
|
|
format $err
|
|
|
|
} {ERR*}
|
|
|
|
|
|
|
|
test {RENAME where source and dest key are the same (existing)} {
|
|
|
|
r set mykey foo
|
|
|
|
r rename mykey mykey
|
|
|
|
} {OK}
|
|
|
|
|
|
|
|
test {RENAMENX where source and dest key are the same (existing)} {
|
|
|
|
r set mykey foo
|
|
|
|
r renamenx mykey mykey
|
|
|
|
} {0}
|
|
|
|
|
|
|
|
test {RENAME where source and dest key are the same (non existing)} {
|
|
|
|
r del mykey
|
|
|
|
catch {r rename mykey mykey} err
|
|
|
|
format $err
|
|
|
|
} {ERR*}
|
|
|
|
|
|
|
|
test {RENAME with volatile key, should move the TTL as well} {
|
2021-06-09 08:13:24 -04:00
|
|
|
r del mykey{t} mykey2{t}
|
|
|
|
r set mykey{t} foo
|
|
|
|
r expire mykey{t} 100
|
|
|
|
assert {[r ttl mykey{t}] > 95 && [r ttl mykey{t}] <= 100}
|
|
|
|
r rename mykey{t} mykey2{t}
|
|
|
|
assert {[r ttl mykey2{t}] > 95 && [r ttl mykey2{t}] <= 100}
|
2015-02-25 04:31:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
test {RENAME with volatile key, should not inherit TTL of target key} {
|
2021-06-09 08:13:24 -04:00
|
|
|
r del mykey{t} mykey2{t}
|
|
|
|
r set mykey{t} foo
|
|
|
|
r set mykey2{t} bar
|
|
|
|
r expire mykey2{t} 100
|
|
|
|
assert {[r ttl mykey{t}] == -1 && [r ttl mykey2{t}] > 0}
|
|
|
|
r rename mykey{t} mykey2{t}
|
|
|
|
r ttl mykey2{t}
|
2015-02-25 04:31:29 -05:00
|
|
|
} {-1}
|
|
|
|
|
|
|
|
test {DEL all keys again (DB 0)} {
|
|
|
|
foreach key [r keys *] {
|
|
|
|
r del $key
|
|
|
|
}
|
|
|
|
r dbsize
|
|
|
|
} {0}
|
|
|
|
|
|
|
|
test {DEL all keys again (DB 1)} {
|
|
|
|
r select 10
|
|
|
|
foreach key [r keys *] {
|
|
|
|
r del $key
|
|
|
|
}
|
|
|
|
set res [r dbsize]
|
|
|
|
r select 9
|
|
|
|
format $res
|
2021-06-09 08:13:24 -04:00
|
|
|
} {0} {singledb:skip}
|
2015-02-25 04:31:29 -05:00
|
|
|
|
2020-11-17 05:03:05 -05:00
|
|
|
test {COPY basic usage for string} {
|
2021-06-09 08:13:24 -04:00
|
|
|
r set mykey{t} foobar
|
2020-11-17 05:03:05 -05:00
|
|
|
set res {}
|
2021-06-09 08:13:24 -04:00
|
|
|
r copy mykey{t} mynewkey{t}
|
|
|
|
lappend res [r get mynewkey{t}]
|
2020-11-17 05:03:05 -05:00
|
|
|
lappend res [r dbsize]
|
2021-06-09 08:13:24 -04:00
|
|
|
if {$::singledb} {
|
|
|
|
assert_equal [list foobar 2] [format $res]
|
|
|
|
} else {
|
|
|
|
r copy mykey{t} mynewkey{t} DB 10
|
|
|
|
r select 10
|
|
|
|
lappend res [r get mynewkey{t}]
|
|
|
|
lappend res [r dbsize]
|
|
|
|
r select 9
|
|
|
|
assert_equal [list foobar 2 foobar 1] [format $res]
|
|
|
|
}
|
|
|
|
}
|
2020-11-17 05:03:05 -05:00
|
|
|
|
|
|
|
test {COPY for string does not replace an existing key without REPLACE option} {
|
2021-06-09 08:13:24 -04:00
|
|
|
r set mykey2{t} hello
|
|
|
|
catch {r copy mykey2{t} mynewkey{t} DB 10} e
|
2020-11-17 05:03:05 -05:00
|
|
|
set e
|
2021-06-09 08:13:24 -04:00
|
|
|
} {0} {singledb:skip}
|
2020-11-17 05:03:05 -05:00
|
|
|
|
|
|
|
test {COPY for string can replace an existing key with REPLACE option} {
|
2021-06-09 08:13:24 -04:00
|
|
|
r copy mykey2{t} mynewkey{t} DB 10 REPLACE
|
2020-11-17 05:03:05 -05:00
|
|
|
r select 10
|
2021-06-09 08:13:24 -04:00
|
|
|
r get mynewkey{t}
|
|
|
|
} {hello} {singledb:skip}
|
2020-11-17 05:03:05 -05:00
|
|
|
|
|
|
|
test {COPY for string ensures that copied data is independent of copying data} {
|
|
|
|
r flushdb
|
|
|
|
r select 9
|
2021-06-09 08:13:24 -04:00
|
|
|
r set mykey{t} foobar
|
2020-11-17 05:03:05 -05:00
|
|
|
set res {}
|
2021-06-09 08:13:24 -04:00
|
|
|
r copy mykey{t} mynewkey{t} DB 10
|
2020-11-17 05:03:05 -05:00
|
|
|
r select 10
|
2021-06-09 08:13:24 -04:00
|
|
|
lappend res [r get mynewkey{t}]
|
|
|
|
r set mynewkey{t} hoge
|
|
|
|
lappend res [r get mynewkey{t}]
|
2020-11-17 05:03:05 -05:00
|
|
|
r select 9
|
2021-06-09 08:13:24 -04:00
|
|
|
lappend res [r get mykey{t}]
|
2020-11-17 05:03:05 -05:00
|
|
|
r select 10
|
|
|
|
r flushdb
|
|
|
|
r select 9
|
|
|
|
format $res
|
2021-06-09 08:13:24 -04:00
|
|
|
} [list foobar hoge foobar] {singledb:skip}
|
2020-11-17 05:03:05 -05:00
|
|
|
|
|
|
|
test {COPY for string does not copy data to no-integer DB} {
|
2021-06-09 08:13:24 -04:00
|
|
|
r set mykey{t} foobar
|
|
|
|
catch {r copy mykey{t} mynewkey{t} DB notanumber} e
|
2020-11-17 05:03:05 -05:00
|
|
|
set e
|
Improve dbid range check for SELECT, MOVE, COPY (#8085)
SELECT used to read the index into a `long` variable, and then pass it to a function
that takes an `int`, possibly causing an overflow before the range check.
Now all these commands use better and cleaner range check, and that also results in
a slight change of the error response in case of an invalid database index.
SELECT:
in the past it would have returned either `-ERR invalid DB index` (if not a number),
or `-ERR DB index is out of range` (if not between 1..16 or alike).
now it'll return either `-ERR value is out of range` (if not a number), or
`-ERR value is out of range, value must between -2147483648 and 2147483647`
(if not in the range for an int), or `-ERR DB index is out of range`
(if not between 0..16 or alike)
MOVE:
in the past it would only fail with `-ERR index out of range` no matter the reason.
now return the same errors as the new ones for SELECT mentioned above.
(i.e. unlike for SELECT even for a value like 17 we changed the error message)
COPY:
doesn't really matter how it behaved in the past (new command), new behavior is
like the above two.
2020-12-01 14:41:26 -05:00
|
|
|
} {ERR value is not an integer or out of range}
|
2020-11-17 05:03:05 -05:00
|
|
|
|
|
|
|
test {COPY can copy key expire metadata as well} {
|
2021-06-09 08:13:24 -04:00
|
|
|
r set mykey{t} foobar ex 100
|
|
|
|
r copy mykey{t} mynewkey{t} REPLACE
|
|
|
|
assert {[r ttl mynewkey{t}] > 0 && [r ttl mynewkey{t}] <= 100}
|
|
|
|
assert {[r get mynewkey{t}] eq "foobar"}
|
2020-11-17 05:03:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
test {COPY does not create an expire if it does not exist} {
|
2021-06-09 08:13:24 -04:00
|
|
|
r set mykey{t} foobar
|
|
|
|
assert {[r ttl mykey{t}] == -1}
|
|
|
|
r copy mykey{t} mynewkey{t} REPLACE
|
|
|
|
assert {[r ttl mynewkey{t}] == -1}
|
|
|
|
assert {[r get mynewkey{t}] eq "foobar"}
|
2020-11-17 05:03:05 -05:00
|
|
|
}
|
|
|
|
|
Add listpack encoding for list (#11303)
Improve memory efficiency of list keys
## Description of the feature
The new listpack encoding uses the old `list-max-listpack-size` config
to perform the conversion, which we can think it of as a node inside a
quicklist, but without 80 bytes overhead (internal fragmentation included)
of quicklist and quicklistNode structs.
For example, a list key with 5 items of 10 chars each, now takes 128 bytes
instead of 208 it used to take.
## Conversion rules
* Convert listpack to quicklist
When the listpack length or size reaches the `list-max-listpack-size` limit,
it will be converted to a quicklist.
* Convert quicklist to listpack
When a quicklist has only one node, and its length or size is reduced to half
of the `list-max-listpack-size` limit, it will be converted to a listpack.
This is done to avoid frequent conversions when we add or remove at the bounding size or length.
## Interface changes
1. add list entry param to listTypeSetIteratorDirection
When list encoding is listpack, `listTypeIterator->lpi` points to the next entry of current entry,
so when changing the direction, we need to use the current node (listTypeEntry->p) to
update `listTypeIterator->lpi` to the next node in the reverse direction.
## Benchmark
### Listpack VS Quicklist with one node
* LPUSH - roughly 0.3% improvement
* LRANGE - roughly 13% improvement
### Both are quicklist
* LRANGE - roughly 3% improvement
* LRANGE without pipeline - roughly 3% improvement
From the benchmark, as we can see from the results
1. When list is quicklist encoding, LRANGE improves performance by <5%.
2. When list is listpack encoding, LRANGE improves performance by ~13%,
the main enhancement is brought by `addListListpackRangeReply()`.
## Memory usage
1M lists(key:0~key:1000000) with 5 items of 10 chars ("hellohello") each.
shows memory usage down by 35.49%, from 214MB to 138MB.
## Note
1. Add conversion callback to support doing some work before conversion
Since the quicklist iterator decompresses the current node when it is released, we can
no longer decompress the quicklist after we convert the list.
2022-11-16 13:29:46 -05:00
|
|
|
source "tests/unit/type/list-common.tcl"
|
|
|
|
foreach {type large} [array get largevalue] {
|
|
|
|
set origin_config [config_get_set list-max-listpack-size -1]
|
|
|
|
test "COPY basic usage for list - $type" {
|
2021-06-09 08:13:24 -04:00
|
|
|
r del mylist{t} mynewlist{t}
|
Add listpack encoding for list (#11303)
Improve memory efficiency of list keys
## Description of the feature
The new listpack encoding uses the old `list-max-listpack-size` config
to perform the conversion, which we can think it of as a node inside a
quicklist, but without 80 bytes overhead (internal fragmentation included)
of quicklist and quicklistNode structs.
For example, a list key with 5 items of 10 chars each, now takes 128 bytes
instead of 208 it used to take.
## Conversion rules
* Convert listpack to quicklist
When the listpack length or size reaches the `list-max-listpack-size` limit,
it will be converted to a quicklist.
* Convert quicklist to listpack
When a quicklist has only one node, and its length or size is reduced to half
of the `list-max-listpack-size` limit, it will be converted to a listpack.
This is done to avoid frequent conversions when we add or remove at the bounding size or length.
## Interface changes
1. add list entry param to listTypeSetIteratorDirection
When list encoding is listpack, `listTypeIterator->lpi` points to the next entry of current entry,
so when changing the direction, we need to use the current node (listTypeEntry->p) to
update `listTypeIterator->lpi` to the next node in the reverse direction.
## Benchmark
### Listpack VS Quicklist with one node
* LPUSH - roughly 0.3% improvement
* LRANGE - roughly 13% improvement
### Both are quicklist
* LRANGE - roughly 3% improvement
* LRANGE without pipeline - roughly 3% improvement
From the benchmark, as we can see from the results
1. When list is quicklist encoding, LRANGE improves performance by <5%.
2. When list is listpack encoding, LRANGE improves performance by ~13%,
the main enhancement is brought by `addListListpackRangeReply()`.
## Memory usage
1M lists(key:0~key:1000000) with 5 items of 10 chars ("hellohello") each.
shows memory usage down by 35.49%, from 214MB to 138MB.
## Note
1. Add conversion callback to support doing some work before conversion
Since the quicklist iterator decompresses the current node when it is released, we can
no longer decompress the quicklist after we convert the list.
2022-11-16 13:29:46 -05:00
|
|
|
r lpush mylist{t} a b $large c d
|
|
|
|
assert_encoding $type mylist{t}
|
2021-06-09 08:13:24 -04:00
|
|
|
r copy mylist{t} mynewlist{t}
|
Add listpack encoding for list (#11303)
Improve memory efficiency of list keys
## Description of the feature
The new listpack encoding uses the old `list-max-listpack-size` config
to perform the conversion, which we can think it of as a node inside a
quicklist, but without 80 bytes overhead (internal fragmentation included)
of quicklist and quicklistNode structs.
For example, a list key with 5 items of 10 chars each, now takes 128 bytes
instead of 208 it used to take.
## Conversion rules
* Convert listpack to quicklist
When the listpack length or size reaches the `list-max-listpack-size` limit,
it will be converted to a quicklist.
* Convert quicklist to listpack
When a quicklist has only one node, and its length or size is reduced to half
of the `list-max-listpack-size` limit, it will be converted to a listpack.
This is done to avoid frequent conversions when we add or remove at the bounding size or length.
## Interface changes
1. add list entry param to listTypeSetIteratorDirection
When list encoding is listpack, `listTypeIterator->lpi` points to the next entry of current entry,
so when changing the direction, we need to use the current node (listTypeEntry->p) to
update `listTypeIterator->lpi` to the next node in the reverse direction.
## Benchmark
### Listpack VS Quicklist with one node
* LPUSH - roughly 0.3% improvement
* LRANGE - roughly 13% improvement
### Both are quicklist
* LRANGE - roughly 3% improvement
* LRANGE without pipeline - roughly 3% improvement
From the benchmark, as we can see from the results
1. When list is quicklist encoding, LRANGE improves performance by <5%.
2. When list is listpack encoding, LRANGE improves performance by ~13%,
the main enhancement is brought by `addListListpackRangeReply()`.
## Memory usage
1M lists(key:0~key:1000000) with 5 items of 10 chars ("hellohello") each.
shows memory usage down by 35.49%, from 214MB to 138MB.
## Note
1. Add conversion callback to support doing some work before conversion
Since the quicklist iterator decompresses the current node when it is released, we can
no longer decompress the quicklist after we convert the list.
2022-11-16 13:29:46 -05:00
|
|
|
assert_encoding $type mynewlist{t}
|
2021-06-09 08:13:24 -04:00
|
|
|
set digest [debug_digest_value mylist{t}]
|
|
|
|
assert_equal $digest [debug_digest_value mynewlist{t}]
|
2021-12-19 10:41:51 -05:00
|
|
|
assert_refcount 1 mylist{t}
|
|
|
|
assert_refcount 1 mynewlist{t}
|
2021-06-09 08:13:24 -04:00
|
|
|
r del mylist{t}
|
|
|
|
assert_equal $digest [debug_digest_value mynewlist{t}]
|
2020-11-17 05:03:05 -05:00
|
|
|
}
|
Add listpack encoding for list (#11303)
Improve memory efficiency of list keys
## Description of the feature
The new listpack encoding uses the old `list-max-listpack-size` config
to perform the conversion, which we can think it of as a node inside a
quicklist, but without 80 bytes overhead (internal fragmentation included)
of quicklist and quicklistNode structs.
For example, a list key with 5 items of 10 chars each, now takes 128 bytes
instead of 208 it used to take.
## Conversion rules
* Convert listpack to quicklist
When the listpack length or size reaches the `list-max-listpack-size` limit,
it will be converted to a quicklist.
* Convert quicklist to listpack
When a quicklist has only one node, and its length or size is reduced to half
of the `list-max-listpack-size` limit, it will be converted to a listpack.
This is done to avoid frequent conversions when we add or remove at the bounding size or length.
## Interface changes
1. add list entry param to listTypeSetIteratorDirection
When list encoding is listpack, `listTypeIterator->lpi` points to the next entry of current entry,
so when changing the direction, we need to use the current node (listTypeEntry->p) to
update `listTypeIterator->lpi` to the next node in the reverse direction.
## Benchmark
### Listpack VS Quicklist with one node
* LPUSH - roughly 0.3% improvement
* LRANGE - roughly 13% improvement
### Both are quicklist
* LRANGE - roughly 3% improvement
* LRANGE without pipeline - roughly 3% improvement
From the benchmark, as we can see from the results
1. When list is quicklist encoding, LRANGE improves performance by <5%.
2. When list is listpack encoding, LRANGE improves performance by ~13%,
the main enhancement is brought by `addListListpackRangeReply()`.
## Memory usage
1M lists(key:0~key:1000000) with 5 items of 10 chars ("hellohello") each.
shows memory usage down by 35.49%, from 214MB to 138MB.
## Note
1. Add conversion callback to support doing some work before conversion
Since the quicklist iterator decompresses the current node when it is released, we can
no longer decompress the quicklist after we convert the list.
2022-11-16 13:29:46 -05:00
|
|
|
config_set list-max-listpack-size $origin_config
|
|
|
|
}
|
2020-11-17 05:03:05 -05:00
|
|
|
|
2022-11-09 12:50:07 -05:00
|
|
|
foreach type {intset listpack hashtable} {
|
|
|
|
test {COPY basic usage for $type set} {
|
|
|
|
r del set1{t} newset1{t}
|
|
|
|
r sadd set1{t} 1 2 3
|
|
|
|
if {$type ne "intset"} {
|
|
|
|
r sadd set1{t} a
|
|
|
|
}
|
|
|
|
if {$type eq "hashtable"} {
|
|
|
|
for {set i 4} {$i < 200} {incr i} {
|
|
|
|
r sadd set1{t} $i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert_encoding $type set1{t}
|
|
|
|
r copy set1{t} newset1{t}
|
|
|
|
set digest [debug_digest_value set1{t}]
|
|
|
|
assert_equal $digest [debug_digest_value newset1{t}]
|
|
|
|
assert_refcount 1 set1{t}
|
|
|
|
assert_refcount 1 newset1{t}
|
|
|
|
r del set1{t}
|
|
|
|
assert_equal $digest [debug_digest_value newset1{t}]
|
|
|
|
}
|
2020-11-17 05:03:05 -05:00
|
|
|
}
|
|
|
|
|
2021-09-09 11:18:53 -04:00
|
|
|
test {COPY basic usage for listpack sorted set} {
|
2021-06-09 08:13:24 -04:00
|
|
|
r del zset1{t} newzset1{t}
|
|
|
|
r zadd zset1{t} 123 foobar
|
2021-09-09 11:18:53 -04:00
|
|
|
assert_encoding listpack zset1{t}
|
2021-06-09 08:13:24 -04:00
|
|
|
r copy zset1{t} newzset1{t}
|
|
|
|
set digest [debug_digest_value zset1{t}]
|
|
|
|
assert_equal $digest [debug_digest_value newzset1{t}]
|
2021-12-19 10:41:51 -05:00
|
|
|
assert_refcount 1 zset1{t}
|
|
|
|
assert_refcount 1 newzset1{t}
|
2021-06-09 08:13:24 -04:00
|
|
|
r del zset1{t}
|
|
|
|
assert_equal $digest [debug_digest_value newzset1{t}]
|
2020-11-17 05:03:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
test {COPY basic usage for skiplist sorted set} {
|
2021-06-09 08:13:24 -04:00
|
|
|
r del zset2{t} newzset2{t}
|
2020-11-17 05:03:05 -05:00
|
|
|
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} {
|
2021-06-09 08:13:24 -04:00
|
|
|
r zadd zset2{t} [randomInt 50] ele-[randomInt 10]
|
2020-11-17 05:03:05 -05:00
|
|
|
}
|
2021-06-09 08:13:24 -04:00
|
|
|
assert_encoding skiplist zset2{t}
|
|
|
|
r copy zset2{t} newzset2{t}
|
|
|
|
set digest [debug_digest_value zset2{t}]
|
|
|
|
assert_equal $digest [debug_digest_value newzset2{t}]
|
2021-12-19 10:41:51 -05:00
|
|
|
assert_refcount 1 zset2{t}
|
|
|
|
assert_refcount 1 newzset2{t}
|
2021-06-09 08:13:24 -04:00
|
|
|
r del zset2{t}
|
|
|
|
assert_equal $digest [debug_digest_value newzset2{t}]
|
2020-11-17 05:03:05 -05:00
|
|
|
r config set zset-max-ziplist-entries $original_max
|
|
|
|
}
|
|
|
|
|
2021-08-10 02:18:49 -04:00
|
|
|
test {COPY basic usage for listpack hash} {
|
2021-06-09 08:13:24 -04:00
|
|
|
r del hash1{t} newhash1{t}
|
|
|
|
r hset hash1{t} tmp 17179869184
|
2021-08-10 02:18:49 -04:00
|
|
|
assert_encoding listpack hash1{t}
|
2021-06-09 08:13:24 -04:00
|
|
|
r copy hash1{t} newhash1{t}
|
|
|
|
set digest [debug_digest_value hash1{t}]
|
|
|
|
assert_equal $digest [debug_digest_value newhash1{t}]
|
2021-12-19 10:41:51 -05:00
|
|
|
assert_refcount 1 hash1{t}
|
|
|
|
assert_refcount 1 newhash1{t}
|
2021-06-09 08:13:24 -04:00
|
|
|
r del hash1{t}
|
|
|
|
assert_equal $digest [debug_digest_value newhash1{t}]
|
2020-11-17 05:03:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
test {COPY basic usage for hashtable hash} {
|
2021-06-09 08:13:24 -04:00
|
|
|
r del hash2{t} newhash2{t}
|
2020-11-17 05:03:05 -05:00
|
|
|
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} {
|
2021-06-09 08:13:24 -04:00
|
|
|
r hset hash2{t} [randomValue] [randomValue]
|
2020-11-17 05:03:05 -05:00
|
|
|
}
|
2021-06-09 08:13:24 -04:00
|
|
|
assert_encoding hashtable hash2{t}
|
|
|
|
r copy hash2{t} newhash2{t}
|
|
|
|
set digest [debug_digest_value hash2{t}]
|
|
|
|
assert_equal $digest [debug_digest_value newhash2{t}]
|
2021-12-19 10:41:51 -05:00
|
|
|
assert_refcount 1 hash2{t}
|
|
|
|
assert_refcount 1 newhash2{t}
|
2021-06-09 08:13:24 -04:00
|
|
|
r del hash2{t}
|
|
|
|
assert_equal $digest [debug_digest_value newhash2{t}]
|
2020-11-17 05:03:05 -05:00
|
|
|
r config set hash-max-ziplist-entries $original_max
|
|
|
|
}
|
|
|
|
|
|
|
|
test {COPY basic usage for stream} {
|
2021-06-09 08:13:24 -04:00
|
|
|
r del mystream{t} mynewstream{t}
|
2020-11-17 05:03:05 -05:00
|
|
|
for {set i 0} {$i < 1000} {incr i} {
|
2021-06-09 08:13:24 -04:00
|
|
|
r XADD mystream{t} * item 2 value b
|
2020-11-17 05:03:05 -05:00
|
|
|
}
|
2021-06-09 08:13:24 -04:00
|
|
|
r copy mystream{t} mynewstream{t}
|
|
|
|
set digest [debug_digest_value mystream{t}]
|
|
|
|
assert_equal $digest [debug_digest_value mynewstream{t}]
|
2021-12-19 10:41:51 -05:00
|
|
|
assert_refcount 1 mystream{t}
|
|
|
|
assert_refcount 1 mynewstream{t}
|
2021-06-09 08:13:24 -04:00
|
|
|
r del mystream{t}
|
|
|
|
assert_equal $digest [debug_digest_value mynewstream{t}]
|
2020-11-17 05:03:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
test {COPY basic usage for stream-cgroups} {
|
2021-06-09 08:13:24 -04:00
|
|
|
r del x{t}
|
|
|
|
r XADD x{t} 100 a 1
|
|
|
|
set id [r XADD x{t} 101 b 1]
|
|
|
|
r XADD x{t} 102 c 1
|
|
|
|
r XADD x{t} 103 e 1
|
|
|
|
r XADD x{t} 104 f 1
|
|
|
|
r XADD x{t} 105 g 1
|
|
|
|
r XGROUP CREATE x{t} g1 0
|
|
|
|
r XGROUP CREATE x{t} g2 0
|
|
|
|
r XREADGROUP GROUP g1 Alice COUNT 1 STREAMS x{t} >
|
|
|
|
r XREADGROUP GROUP g1 Bob COUNT 1 STREAMS x{t} >
|
|
|
|
r XREADGROUP GROUP g1 Bob NOACK COUNT 1 STREAMS x{t} >
|
|
|
|
r XREADGROUP GROUP g2 Charlie COUNT 4 STREAMS x{t} >
|
|
|
|
r XGROUP SETID x{t} g1 $id
|
|
|
|
r XREADGROUP GROUP g1 Dave COUNT 3 STREAMS x{t} >
|
|
|
|
r XDEL x{t} 103
|
|
|
|
|
|
|
|
r copy x{t} newx{t}
|
|
|
|
set info [r xinfo stream x{t} full]
|
|
|
|
assert_equal $info [r xinfo stream newx{t} full]
|
2021-12-19 10:41:51 -05:00
|
|
|
assert_refcount 1 x{t}
|
|
|
|
assert_refcount 1 newx{t}
|
2021-06-09 08:13:24 -04:00
|
|
|
r del x{t}
|
|
|
|
assert_equal $info [r xinfo stream newx{t} full]
|
2020-11-17 05:03:05 -05:00
|
|
|
r flushdb
|
|
|
|
}
|
|
|
|
|
2015-02-25 04:31:29 -05:00
|
|
|
test {MOVE basic usage} {
|
|
|
|
r set mykey foobar
|
|
|
|
r move mykey 10
|
|
|
|
set res {}
|
|
|
|
lappend res [r exists mykey]
|
|
|
|
lappend res [r dbsize]
|
|
|
|
r select 10
|
|
|
|
lappend res [r get mykey]
|
|
|
|
lappend res [r dbsize]
|
|
|
|
r select 9
|
|
|
|
format $res
|
2021-06-09 08:13:24 -04:00
|
|
|
} [list 0 0 foobar 1] {singledb:skip}
|
2015-02-25 04:31:29 -05:00
|
|
|
|
|
|
|
test {MOVE against key existing in the target DB} {
|
|
|
|
r set mykey hello
|
|
|
|
r move mykey 10
|
2021-06-09 08:13:24 -04:00
|
|
|
} {0} {singledb:skip}
|
2015-02-25 04:31:29 -05:00
|
|
|
|
|
|
|
test {MOVE against non-integer DB (#1428)} {
|
|
|
|
r set mykey hello
|
|
|
|
catch {r move mykey notanumber} e
|
|
|
|
set e
|
2021-06-09 08:13:24 -04:00
|
|
|
} {ERR value is not an integer or out of range} {singledb:skip}
|
2015-02-25 04:31:29 -05:00
|
|
|
|
2015-09-14 06:28:22 -04:00
|
|
|
test {MOVE can move key expire metadata as well} {
|
|
|
|
r select 10
|
|
|
|
r flushdb
|
|
|
|
r select 9
|
|
|
|
r set mykey foo ex 100
|
|
|
|
r move mykey 10
|
|
|
|
assert {[r ttl mykey] == -2}
|
|
|
|
r select 10
|
|
|
|
assert {[r ttl mykey] > 0 && [r ttl mykey] <= 100}
|
|
|
|
assert {[r get mykey] eq "foo"}
|
|
|
|
r select 9
|
2021-06-09 08:13:24 -04:00
|
|
|
} {OK} {singledb:skip}
|
2015-09-14 06:28:22 -04:00
|
|
|
|
2015-09-14 06:35:51 -04:00
|
|
|
test {MOVE does not create an expire if it does not exist} {
|
|
|
|
r select 10
|
|
|
|
r flushdb
|
|
|
|
r select 9
|
|
|
|
r set mykey foo
|
|
|
|
r move mykey 10
|
|
|
|
assert {[r ttl mykey] == -2}
|
|
|
|
r select 10
|
|
|
|
assert {[r ttl mykey] == -1}
|
|
|
|
assert {[r get mykey] eq "foo"}
|
|
|
|
r select 9
|
2021-06-09 08:13:24 -04:00
|
|
|
} {OK} {singledb:skip}
|
2015-09-14 06:35:51 -04:00
|
|
|
|
2015-02-25 04:31:29 -05:00
|
|
|
test {SET/GET keys in different DBs} {
|
|
|
|
r set a hello
|
|
|
|
r set b world
|
|
|
|
r select 10
|
|
|
|
r set a foo
|
|
|
|
r set b bared
|
|
|
|
r select 9
|
|
|
|
set res {}
|
|
|
|
lappend res [r get a]
|
|
|
|
lappend res [r get b]
|
|
|
|
r select 10
|
|
|
|
lappend res [r get a]
|
|
|
|
lappend res [r get b]
|
|
|
|
r select 9
|
|
|
|
format $res
|
2021-06-09 08:13:24 -04:00
|
|
|
} {hello world foo bared} {singledb:skip}
|
2015-02-25 04:31:29 -05:00
|
|
|
|
|
|
|
test {RANDOMKEY} {
|
|
|
|
r flushdb
|
|
|
|
r set foo x
|
|
|
|
r set bar y
|
|
|
|
set foo_seen 0
|
|
|
|
set bar_seen 0
|
|
|
|
for {set i 0} {$i < 100} {incr i} {
|
|
|
|
set rkey [r randomkey]
|
|
|
|
if {$rkey eq {foo}} {
|
|
|
|
set foo_seen 1
|
|
|
|
}
|
|
|
|
if {$rkey eq {bar}} {
|
|
|
|
set bar_seen 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
list $foo_seen $bar_seen
|
|
|
|
} {1 1}
|
|
|
|
|
|
|
|
test {RANDOMKEY against empty DB} {
|
|
|
|
r flushdb
|
|
|
|
r randomkey
|
|
|
|
} {}
|
|
|
|
|
|
|
|
test {RANDOMKEY regression 1} {
|
|
|
|
r flushdb
|
|
|
|
r set x 10
|
|
|
|
r del x
|
|
|
|
r randomkey
|
|
|
|
} {}
|
|
|
|
|
|
|
|
test {KEYS * two times with long key, Github issue #1208} {
|
|
|
|
r flushdb
|
|
|
|
r set dlskeriewrioeuwqoirueioqwrueoqwrueqw test
|
|
|
|
r keys *
|
|
|
|
r keys *
|
|
|
|
} {dlskeriewrioeuwqoirueioqwrueoqwrueqw}
|
2023-02-28 08:15:26 -05:00
|
|
|
|
|
|
|
test {Regression for pattern matching long nested loops} {
|
|
|
|
r flushdb
|
|
|
|
r SET aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 1
|
|
|
|
r KEYS "a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*b"
|
|
|
|
} {}
|
2015-02-25 04:31:29 -05:00
|
|
|
}
|