I'm trying to get all hget values out of my redis db. But the array logs stays empty. Could you guys please take a look into it? Thanks
getAllHMSets = (cb) ->
client.keys "log:*", (err, logKeys) ->
if not err and logKeys isnt null
logs = new Array()
i = 0
while i < logKeys.length
client.hgetall logKeys[i], (err, log) ->
if not err and log isnt null
logs.push log
i++
if logs.length is logKeys.length
cb logs if typeof cb is "function"
I think there are 2 problems with your code:
you should write it in more idiomatic CoffeeScript
your call to hgetall must also use a callback eitherwise your array will never be filled.
getAllHMSets = (cb) ->
client.keys "log:*", (err, logKeys) ->
if not err and logKeys isnt null
logs = []
for value in logKeys
client.hgetall logKeys[i], (err, log) ->
if not err and log isnt null
logs.push log
if logs.length is logKeys.length
cb logs if typeof cb is "function"