diff options
author | meir@redislabs.com <meir@redislabs.com> | 2020-06-14 10:06:00 +0300 |
---|---|---|
committer | meir@redislabs.com <meir@redislabs.com> | 2020-06-14 11:20:15 +0300 |
commit | a89bf734a933e45b9dd3ae85ef4c3b62bd6891d8 (patch) | |
tree | a1a61e0712fb560fda35979fa20a56da457184be /tests/unit/moduleapi/scan.tcl | |
parent | 10553988498acea1d772af69092b67fd5b56d529 (diff) | |
download | redis-a89bf734a933e45b9dd3ae85ef4c3b62bd6891d8.tar.gz |
Fix RM_ScanKey module api not to return int encoded strings
The scan key module API provides the scan callback with the current
field name and value (if it exists). Those arguments are RedisModuleString*
which means it supposes to point to robj which is encoded as a string.
Using createStringObjectFromLongLong function might return robj that
points to an integer and so break a module that tries for example to
use RedisModule_StringPtrLen on the given field/value.
The PR introduces a fix that uses the createObject function and sdsfromlonglong function.
Using those function promise that the field and value pass to the to the
scan callback will be Strings.
The PR also changes the Scan test module to use RedisModule_StringPtrLen
to catch the issue. without this, the issue is hidden because
RedisModule_ReplyWithString knows to handle integer encoding of the
given robj (RedisModuleString).
The PR also introduces a new test to verify the issue is solved.
Diffstat (limited to 'tests/unit/moduleapi/scan.tcl')
-rw-r--r-- | tests/unit/moduleapi/scan.tcl | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/tests/unit/moduleapi/scan.tcl b/tests/unit/moduleapi/scan.tcl index de1672e0a..43a0c4d8a 100644 --- a/tests/unit/moduleapi/scan.tcl +++ b/tests/unit/moduleapi/scan.tcl @@ -16,6 +16,11 @@ start_server {tags {"modules"}} { r hmset hh f1 v1 f2 v2 lsort [r scan.scan_key hh] } {{f1 v1} {f2 v2}} + + test {Module scan hash dict with int value} { + r hmset hh1 f1 1 + lsort [r scan.scan_key hh1] + } {{f1 1}} test {Module scan hash dict} { r config set hash-max-ziplist-entries 2 |