Wednesday, January 18, 2012

Redis EVAL() in 2.6.0

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 redis
r = redis.Redis()
RandomPushScript = """
local i = tonumber(ARGV[1])
while (i > 0) do
res = redis.call('lpush',KEYS[1],math.random())
i = i-1
end
return res
"""
r.delete('mylist')
print r.eval(RandomPushScript,1,'mylist',10)
# __END__

One of the crappy things about python is the indents. It makes copy/paste to a place like wordpress semi-functional.

2 comments:

  1. Does a version of redis-py for Redis 2.6/2.5 exist yet? That is, is there a version with r.eval() available? I couldn't find it on github.

    ReplyDelete
  2. I have to agree. I checked the code myself. I did not see a method prototype as they did for the other functions. And looking at the test cases there is nothing hidden in there either.

    The last time I did a pip install the STDOUT indicated it was version 2.4.23 which is not even the latest.

    Sorry, but I do not know anything more here. 2.6 will be a great milestone.

    ReplyDelete

prod, staging, QA, dev in your CI/CD?

I've been developing with CI/CD since before it was a straw, let alone a pipeline. No, graduates of 2020 you did not design or discover ...