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:
Yossi Gottlieb
2019-12-12 18:50:11 +02:00
parent 118db9eeae
commit 0283db5883
4 changed files with 59 additions and 9 deletions

View File

@@ -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*}
}