mirror of
https://github.com/fluencelabs/redis
synced 2025-07-31 08:22:01 +00:00
Improve RM_ModuleTypeReplaceValue() API.
With the previous API, a NULL return value was ambiguous and could represent either an old value of NULL or an error condition. The new API returns a status code and allows the old value to be returned by-reference. This commit also includes test coverage based on tests/modules/datatype.c which did not exist at the time of the original commit.
This commit is contained in:
@@ -24,4 +24,21 @@ start_server {tags {"modules"}} {
|
||||
catch {r datatype.restore dtkeycopy $truncated} e
|
||||
set e
|
||||
} {*Invalid*}
|
||||
|
||||
test {DataType: ModuleTypeReplaceValue() happy path works} {
|
||||
r datatype.set key-a 1 AAA
|
||||
r datatype.set key-b 2 BBB
|
||||
|
||||
assert {[r datatype.swap key-a key-b] eq {OK}}
|
||||
assert {[r datatype.get key-a] eq {2 BBB}}
|
||||
assert {[r datatype.get key-b] eq {1 AAA}}
|
||||
}
|
||||
|
||||
test {DataType: ModuleTypeReplaceValue() fails on non-module keys} {
|
||||
r datatype.set key-a 1 AAA
|
||||
r set key-b RedisString
|
||||
|
||||
catch {r datatype.swap key-a key-b} e
|
||||
set e
|
||||
} {*ERR*}
|
||||
}
|
||||
|
Reference in New Issue
Block a user