Database Reference
In-Depth Information
end
else
redis.call("SET",KEYS[1],ARGV[1])
return 1
end
To try it out, save this script as timestamps.lua or use the one
included in the topic's source code. After starting the Redis server, try
setting a few different events with timestamps:
$ redis-cli EVAL "$(cat timestamps.lua)" 1 user
'{"ts":0}'
(integer) 1
$ redis-cli EVAL "$(cat timestamps.lua)" 1 user
'{"ts":2}'
(integer) 1
$ redis-cli EVAL "$(cat timestamps.lua)" 1 user
'{"ts":10}'
(integer) 1
$ redis-cli EVAL "$(cat timestamps.lua)" 1 user
'{"ts":5}'
(integer) 0
$ redis-cli GET user
"{\"ts\":10}"
Even though timestamps are presented out of order, the most recent
timestamp is still preserved. More complicated tests of the JSON
objects could be included after line 4 of the preceding code as well. This
also has the advantage of being an atomic operation because updates to
the user are only done through the script, which will always execute in
the same Lua interpreter.
Publish/Subscribe Support
In addition to being a key-value store, Redis can serve as a simple message
bus. This is particularly useful in streaming applications as it allows a
processing system like Storm to notify a front end of important events. An
Search WWH ::




Custom Search