-
Notifications
You must be signed in to change notification settings - Fork 24.5k
Description
The problem/use-case that the feature addresses
Superfast min and max finding.
SET TEMPERATUREMIN -24.5 MIN
SET TEMPERATUREMAX 37.8 MAX
Description of the feature
SET TEMPERATUREMIN -24.5 MIN
Set only if current value of key is higher than new value
SET TEMPERATUREMAX 37.8 MAX
Set only if current value of key is smaller than new value
Alternatives you've considered
Client code:
VALUE = GET REDIS.GET(KEY)
IF VALUE>NEWVALUE THEN
REDIS.SET(KEY,VALUE)
END-IF
Requires unnecessary communication via network, and is not atomic (other process/thread/connection could possibly corrupt the value).
Lua code (HASH VARIANT): (example: EVAL INSERT-LUA-CODE-HERE 2 KEY FIELD 8)
local newv = tonumber(ARGV[1])
local temp = tonumber(redis.call('HGET', KEYS[1], KEYS[2]))
if (not temp) or (newv < temp) then
redis.call('HSET', KEYS[1], KEYS[2], newv)
end
Could be done, needs to be either pre-loaded or evaluated every time.
Feature feels small, but useful and use case general enough to warrant consideration for implementation. SET NX and XX variants provide similar feature (these are all "Only Set If Condition" -features).
Additional information
None.