Richard Bucker

Redis EVAL() in 2.6.0

Posted at — Jan 18, 2012

Our friends on the Redis commit team are proponents of the Ruby language when not coding in Lua, tcl or C. And so the EVAL() function example code is written Ruby. That’s all fine and well… but what about <my_lang>?.So I spent all of 30 seconds on a python version of the same code. Chances are pretty good that the code will work. I do not know for certain because 2.6.0 is not ready yet and I’m not in a position to install unstable yet. Of course I could run it in userspace but that’s another topic.import redisr = redis.Redis()RandomPushScript = “" local i = tonumber(ARGV[1]) while (i > 0) do res =‘lpush’,KEYS[1],math.random()) i = i-1 end return res""r.delete(‘mylist’)print r.eval(RandomPushScript,1,‘mylist’,10)# ENDOne of the crappy things about python is the indents. It makes copy/paste to a place like wordpress semi-functional.