Skip to content

Instantly share code, notes, and snippets.

@ydnar
Last active January 12, 2018 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ydnar/59095235190c3db081e178fad011db06 to your computer and use it in GitHub Desktop.
Save ydnar/59095235190c3db081e178fad011db06 to your computer and use it in GitHub Desktop.
Lua one-liner to implement an “EXPIRENX” command in Redis
DEL example.com
HSET example.com status reserved
EVAL "return redis.call('TTL',KEYS[1])>0 or redis.call('EXPIRE',KEYS[1],ARGV[1])" 1 example.com 111111
HGETALL example.com
TTL example.com
HSET example.com comment IANA
EVAL "return redis.call('TTL',KEYS[1])>0 or redis.call('EXPIRE',KEYS[1],ARGV[1])" 1 example.com 222222
HGETALL example.com
TTL example.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment