hkeys return nothing
ovoshlook opened this issue · 5 comments
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
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.
Sorry. Wrong server... all ok
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.
Ok, so this issue can be closed, right?