node.js - redis.lindex() is returning true rather than the value at the index -
i have existing key value list: key value1 value2.
in redis-cli, run lrange key 0 -1, returns:
1) value1 2) value2 this confirms key value list exists. in redis-cli, running lindex key 0 returns:
"value1" however, in node app, when execute console.log(redis.lindex('key', 0)), prints true rather value @ index.
what doing wrong?
note: i'm using node-redis package.
calls command functions in node-redis asynchronous, homecoming results in callback , not straight function call. phone call lindex should this:
redis.lindex('key', 0, function(err, result) { if (err) { /* handle error */ } else { console.log(result); } }); if need "return" result whatever function you're in, you'll have callback. this:
function calllindex(callback) { /* ... stuff ... */ redis.lindex('key', 0, function(err, result) { // if need process result before "returning" it, here // pass result on callback callback(err, result) }); } which you'd phone call this:
calllindex(function(err, result) { // utilize result here }); node.js redis node-redis
No comments:
Post a Comment