node.js - Filter data in redis -
i create record in redis using
var data = { 'userid': 'user1' , 'message': 'test message' }; redisclient.hmset('messages:' + 1 , data); var data1 = { 'userid': 'user2' , 'message': 'test message' }; redisclient.hmset('messages:' + 2 , data1);
i want data messages userid = user2.. how this.
you cannot filter directly. should using different keys userid
:
var data1 = { "userid": "user1" , "message': "test message" }; redisclient.hmset("messages:" + data1.userid , data1.message); var data2 = { "userid": "user2" , "message': "test message" }; redisclient.hmset("messages:" + data2.userid , data2.message);
you can use
redisclient.hgetall("messages:user1")
to messages user1
.
if want partition timestamp (which not in original question), you'll have use sorted set instead of hash:
redisclient.zadd("messages:" + data1.userid, new date().gettime(), data1.message);
use
redisclient.zrange("messages:" + data1.userid, 0, -1);
to receive messages sorted timestamp.
Comments
Post a Comment