3

What is the problem?

Accessing redis keys, which contains a hash object, through lua scripting actually returns a array instead of a hash.

Question

What is the best time efficient way to solve this issue?

  • Save the value as a ruby's hash in form of string and than use eval to transform it
  • Split that hash into multiple gets, each with a single value
  • Save the value as a json object in form of string and than use oj gem to load it

Issue Details

HMSET

HMSET "[1, 79, 29, 44]" 0 1 

Redis-rb gem

When accessing the key with redis gem, as expected, it returns a hash

2.1.3 :001 > require "redis"
require  => true
2.1.3 :002 > r = Redis.new
=> #<Redis client v3.2.1 for redis://127.0.0.1:6379/0>
2.1.3 :003 > r.hgetall("[1, 79, 29, 44]")
=> {"0"=>"1"}
2.1.3 :004 > 

Wolverine gem

When accessing the very same key through lua script (hmget.lua) using wolverine it actually returns an array

[1] pry(#<CubosController>)> a = MessagePack.unpack(Wolverine.hmget(["[1, 79, 29, 44]"]))
=> {"[1, 79, 29, 44]"=>["0", "1"]}
[2] pry(#<CubosController>)> a["[1, 79, 29, 44]"].class
=> Array

Redis-db-scripting gem

Has the same problem:

2.1.3 :005 > redis = Redis.new()
=> #<Redis client v3.2.1 for redis://127.0.0.1:6379/0>
2.1.3 :006 > scripts = Redis::Scripting::Module.new(redis,"/Users/rapha/projetos/qlikview/app/wolverine")
=> <Redis::Scripting::Module: 0x3fd69c62aec8    @source_dir="/Users/rapha/projetos/qlikview/app/wolverine" @redis=# <Redis:0x007fad39571730>>
2.1.3 :007 > MessagePack.unpack(scripts.run(:hmget, ["[1, 79, 29, 44]"], []))
=> {"[1, 79, 29, 44]"=>["0", "1"]}

hmget.lua

local data = {}

for _, key in ipairs(KEYS) do
  data[key] = redis.call('HGETALL', key)
end

return cmsgpack.pack(data)

The messagePack compress/decompress is not the issue, already tested that.

Issue opened in Wolverine

https://github.com/Shopify/wolverine/issues/13

Similar issues already fixed

https://github.com/redis/redis-rb/issues/469

Community
  • 1
  • 1
Raphael Ottoni
  • 506
  • 3
  • 14
  • 1
    Do you have a question? – Jordan Running Jun 19 '15 at 04:38
  • I'm not sure about the ruby context and LUA script output needs, but in this question http://stackoverflow.com/questions/34313598/lua-script-to-return-efficient-dictionary-from-redis-hgetall-call I offer a way to approach the flat return value of redis.call in LUA script. – amotzg Dec 16 '15 at 13:46

0 Answers0