Skip to content

Instantly share code, notes, and snippets.

@Daenyth
Daenyth / sifh.py
Created June 9, 2017 19:50
redis-py "set if higher"
from redis import Redis # type: ignore
from redis.client import Script # type: ignore
def register_set_if_higher(redis: Redis) -> Script:
"""
Returns a redis script taking one key and one argument.
It sets the value in the key to be equal to the argument, iff the current value is unset or lower.
It returns the amount the value was increased by, or the number itself, if the key was unset.
"""