node.js store objects in redis

Since the socket is of type Object, you need to convert the object to a string before storing and when retrieving the socket, need to convert it back to an object.

You can use

JSON.stringify(socket) 

to convert to a string and

JSON.parse(socketstr) 

to convert back to an object.

Edit:

Since the release of version 2.0.0, we are able to store objects as hashes into Redis.

client.hmset("hosts", "mjr", "1", "another", "23", "home", "1234");

client.hgetall("hosts", function (err, obj) {
    console.dir(obj);
});

https://redis.io/commands/hset

https://github.com/NodeRedis/node_redis

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)