I have just discovered how cool node js is and was looking at options for persisting. I saw that you could use redis-client to store data in redis and I have been able to store data ok, like so:
var redis = require('redis-client');
var r = redis.createClient();
var messege = {'name' => 'John Smith'};
var type = "Contact";
r.stream.on( 'connect', function() {
r.incr( 'id' , function( err, id ) {
r.set( type+':'+id, JSON.stringify(messege), function() {
sys.puts("Saved to redis");
});
});
});
This store a key with a json string as the value. I am however trying to retrieve all the keys from redis and loop around them. I am having trouble figuring out the way to do this, could anyone point me in the right direction?
Cheers
Eef
To get keys from redis, you should use the
.keysparameter. The first parameter that you pass is a ‘filter’ and.keyswill return any items matching the filter.For example
r.keys('*', ...)will return all of the keys in redis as an array.Here’s the documentation on this command: http://redis.io/commands/keys
To loop through them, you can just do a simple
for inas follows:r.keys('*', function (keys) {for (key in keys) {
console.log(key);
}
});