redis 127.0.0.1:6379> set foo '{"b":20,"a":10}'
OK
The user wants to increment the value of "b" with a single query to Redis in an atomic way: $ cat /tmp/script.lua
obj = cjson.decode(redis.call("GET",KEYS[1]))
obj.b = obj.b + 1
redis.call("SET",KEYS[1],cjson.encode(obj))
return obj.b
$ redis-cli --eval /tmp/script.lua foo
(integer) 21
$ redis-cli --eval /tmp/script.lua foo
(integer) 22
$ redis-cli GET foo
"{\"a\":10,\"b\":22}"
No back and forth from client to server, no locking needed. Basically you can implement your specialized, atomic commands, in Lua.Given that we'll implement new commands only when they are "fundamental" operatons. For instance there is some plan to implement list splicing. When this happens it's worth to write it in C for max performances, so I think we'll unlikely write parts of Redis in Lua itself. Scripting systems is something I love (see Emacs for instance) but IMHO Redis is the instance of system where this does not work: space and time are too important for Redis.
I've seen quite a few blog posts that highlight some amazing way to use Redis and it would be very helpful to have them all in one place.
But I would also like to add that Redis's documentation is one of the best I've seen anywhere. Incredibly easy to find information about any command.
There was also http://evalsha.com/ which looked cool but went nowhere...