Skip to content

[NEW] SET MIN/MAX FLAGS #12454

@tomidotomicode

Description

@tomidotomicode

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions