Skip to content

Redis script uses textual comparison #3767

@moozzyk

Description

@moozzyk

Lua will automatically convert string and number types to the correct format to perform calculations. (...) A notable exception: comparison operators (== ~= < > <= >=) do not coerce their arguments.

Consider:

127.0.0.1:6379> SET test 50
OK
127.0.0.1:6379> EVAL "local newvalue = tonumber(redis.call('GET', KEYS[1])) if newvalue < tonumber(ARGV[1]) then return redis.call('SET', KEYS[1], ARGV[1]) else return nil end" 1 test 6
(nil)

vs. the script in the current form:

127.0.0.1:6379> SET test 50
OK
127.0.0.1:6379> EVAL "local newvalue = redis.call('GET', KEYS[1]) if newvalue < ARGV[1] then return redis.call('SET', KEYS[1], ARGV[1]) else return nil end" 1 test 6
OK

This script runs only when reconnecting to Redis.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions