nrk / redis-lua

A Lua client library for the redis key value storage system.
MIT License
731 stars 239 forks source link

hkeys return nothing #45

Closed ovoshlook closed 9 years ago

ovoshlook commented 9 years ago

Hello. Try to get some value from my db

print(client:select(0)) -- return true

value={} value=client:hkeys("myhashtabe") -- like key field1 val1 field2 val2 for k,v in pairs(value) do print(k.." "..v) -- return nothing end

If I do this from redis-cli - everything works

redis_version:2.8.16

ignacio commented 9 years ago

Just tried with:

local redis = require "redis"

local client = redis.connect("127.0.0.1")
print(client:select(0)) -- return true

client:hmset("myhashtabe", "foo", math.random(), "bar", math.random())

local value = client:hkeys("myhashtabe") -- like key field1 val1 field2 val2
for k,v in pairs(value) do
    print(k.." "..v)
end

And I got:

true
1 foo
2 bar

Please check the spelling of the key. myhashtabe seems odd. Maybe it should be myhashtable ? Also, make sure the hash you are trying to access is actually on database 0.

ovoshlook commented 9 years ago

Sorry. Wrong server... all ok

ignacio commented 9 years ago

Let me see if I understood correctly. Running the script works (it outputs the keys of the hash), but, when you use redis-cli, you see nothing.

Could it be that you are connecting to different instances of Redis? Let's do this: open two terminals. In one, run redis-cli -n 0 monitor and in the other run the script. You should see the commands being executed in the first terminal.

ignacio commented 9 years ago

Ok, so this issue can be closed, right?

nrk commented 9 years ago

Thanks @ignacio.