node-redis

How to create LIKE operator search in Redis cache using nodejs?

依然范特西╮ 提交于 2019-12-25 04:14:18
问题 I have a question, is it possible to create a LIKE operator search in Redis? Similar to relational (mysql/oracle) database. I have complex json: {"_id" : ObjectId("581c8b8854fdcd1ff8c944e0"), "Objectcode" : "xxxxx", "Objecttype" : "xxxx", "docid" : "581c8b8554fdcd1ff8c93d10", "description" : "Tags based search .... ", "metaTags" : [ "tag1", "tag2", "tag3", "tag5", "tag6", "tag7", "tag8", "tag9", "tag10" ], "__v" : 0 } and i want to search on array of metaTags how can i do it? Thanks 回答1: You

Socket.io: Not able send message to particular socket using socket.id

痞子三分冷 提交于 2019-12-25 00:42:40
问题 I am storing the socket.id of each user when he login using redis redisClient.set(user._id + ':socket', socket.id) When any post for this user._id is created, i am trying emit an event to the socket of that particular user using the socket.id stored above var mySocket=redisClient.get(user._id + ':socket') socket.broadcast.to(mySocket).emit('my message', msg); The problem is that I am not able to emit to that particular socket using the above code.I am using socket.io version > 1.0. Can

How to get the key from value in key/value pair in redis store client?

心已入冬 提交于 2019-12-24 01:39:13
问题 I am storing username/SocketID pairs in redis store for my socket.io chat application. When the user disconnects i need to remove the username/socketID pair from the redis store. I have seen how to get the value from a key but never a key from a value. Is it possible? or either way how can i delete the key/value pair from just the value. Here's my code For adding to store on connect socket.on('username', function (username) { client.set(username, socket.id, function (err) { console.log

redis.lpush a number of items

风格不统一 提交于 2019-12-23 09:49:49
问题 In my node.js script I have an array of strings, and I want to LPUSH these strings into a Redis queue. I tried: var redis = require('redis').createClient(); redis.lpush('queue', ['1', '2', '3']) which results in a single string being pushed: redis 127.0.0.1:6379> lrange queue 0 -1 1) "1,2,3" Redis supports multiple values in LPUSH command, I am looking for help on utilizing this functionality. I am not asking how to loop over my array and push each item separately. :) EDIT: I know if I do

Wait for several db connections before starting express server?

ⅰ亾dé卋堺 提交于 2019-12-22 09:59:16
问题 I'm working on an Express app. At startup it connects to a Redis server and to a PostgreSQL sever. I'd like to wait for both connections to succeed before starting the express server. Now, if I were waiting on just one callback, I could initiate the Express server within that callback. But how to best do this when waiting on more than one async operation? I'm new to this. Is there a good idiomatic pattern for doing this sort of thing? Maybe grouping promises together or..? 回答1: Promises are

How to store a binary object in redis using node?

别等时光非礼了梦想. 提交于 2019-12-20 11:37:02
问题 I am trying to save a binary object in redis and then serve it back as an image. Here is the code I am using to save the data: var buff=new Buffer(data.data,'base64'); client.set(key,new Buffer(data.data,'base64')); Here is the code to dump the data out: client.get(key,function(err,reply){ var data = reply; response.writeHead(200, {"Content-Type": "image/png"}); response.end(data,'binary'); }); The first few byte of the data seem to be corrupted. The magic number is incorrect. Did some

How to store a binary object in redis using node?

前提是你 提交于 2019-12-20 11:36:05
问题 I am trying to save a binary object in redis and then serve it back as an image. Here is the code I am using to save the data: var buff=new Buffer(data.data,'base64'); client.set(key,new Buffer(data.data,'base64')); Here is the code to dump the data out: client.get(key,function(err,reply){ var data = reply; response.writeHead(200, {"Content-Type": "image/png"}); response.end(data,'binary'); }); The first few byte of the data seem to be corrupted. The magic number is incorrect. Did some

How to store array of objects in Redis?

。_饼干妹妹 提交于 2019-12-20 01:35:13
问题 I have an array of Objects that I want to store in Redis. I can break up the array part and store them as objects but I am not getting how I can get somethings like {0} : {"foo" :"bar", "qux" : "doe"}, {1} : {"name" "Saras", "age" : 23} and then search the db based on name and get the requested key back. I need something like this. but can't come close to getting it right. incr id //correct (integer) 3 get id //correct "3" SADD id {"name" : "Saras"} //wrong SADD myset {"name" : "Saras"} /

how can I get sessions to work using redis, express & socket.io?

。_饼干妹妹 提交于 2019-12-17 22:24:47
问题 So I am trying to get Sessions to work inside my socket.on('connection', ...) I am trying to get this working using recent versions: Socket.io - 0.9.13, Express - 3.1.0 and latest versions of other modules. Anyway I have tried using both modules 'connect-redis' and 'session.socket.io' and they both have similar problems. In my code I have 2 redis stores (socketio.RedisStore and require('connect-redis')(express)), now this program all runs fine, but because express and socket.io need to share

Express Node.JS - Receiving Redis callback, executing promises

流过昼夜 提交于 2019-12-13 00:52:51
问题 I have a Node/Express routing function which executes a Redis call in another module. I want to perform a complex Redis function in one node module and send a simple callback saying it is a success to the routing module. The Redis call executes, but I cannot perform any synchronous functions which retrieves even a simple true value from the Redis call. Here is my Redis function: doctorDB.js var addDoctor = function addDoctor(id, doc){ var fields = Object.keys(doc.fields); return client.multi(