Lua script to return efficient dictionary from Redis HGETALL call

后端 未结 1 1889
别那么骄傲
别那么骄傲 2021-01-13 06:36

I need to use Redis HMGET from a Lua script and extract specific values in following code. But redis.call(\'HMGET\', table_key, hkey1, hkey2, ...)

相关标签:
1条回答
  • 2021-01-13 07:09

    After some profiling and tests, we found the following function to have good performance and use it to get a proper table.

    This save the need to call a getter function for each hash key retrieval.

    local function hgetall(hash_key)
        local flat_map = redis.call('HGETALL', hash_key)
        local result = {}
        for i = 1, #flat_map, 2 do
            result[flat_map[i]] = flat_map[i + 1]
        end
        return result
    end
    
    0 讨论(0)
提交回复
热议问题