node-redis

express-session, connect-redis and einaros/ws

怎甘沉沦 提交于 2019-12-11 07:14:28
问题 I seem to be having some trouble getting Express, express-session, connect-redis and websockets/ws to play together nicely. This most likely has to do with my as yet limited understanding of these modules and coding in general. Most of the code here is taken from the respective examples in the repositories as well as other sources trying to accomplish something similar. So what we have here is a websocket-enabled app trying to immediately initiate a websocket connection to the server-side app

Nodejs performance optimization

回眸只為那壹抹淺笑 提交于 2019-12-10 23:28:57
问题 I am new to performance optimization, and while I recognize nodejs may not be the most beginner friendly place to start, it's the task at hand. The observation: simple JSON API requests take in the order of hundreds of milliseconds on a staging server with no load and <10 users in the database. Particularly, the call to /api/get_user is taking ~300ms to execute this code: exports.get_user = function(req, res) { return res.json(req.user) } (Note: we store our sessions in Redis) The stack:

Atomic set only if not already set

喜你入骨 提交于 2019-12-10 14:58:22
问题 Is there any way to do an atomic set only if not already set in Redis? Specifically, I'm creating a user like "myapp:user:user_email" and want Redis to give me back an error if "user_email" is already taken, instead of silently replacing the old value. Something like declare, not replace. 回答1: See SETNX Set key to hold string value if key does not exist. In that case, it is equal to SET. When key already holds a value, no operation is performed. SETNX is short for "SET if N ot e X ists". You

Node.js + Express + Redis, when to close connection?

我是研究僧i 提交于 2019-12-08 15:00:19
问题 I have a Node application that uses Express and node_redis. I'm following the approach outlined in the Learning Node book and creating a single client for the life of the application. Given this approach, when do I call close() on the redis client? Do I even need to? Relevant code var express = require( 'express' ), redis = require( 'redis' ); var app = express(), config = require( './config/application' )[ app.get( 'env' ) ]; // create Redis client var redisClient = redis.createClient();

How can I access the key passed to hgetall when using node_redis?

落爺英雄遲暮 提交于 2019-12-08 00:33:32
问题 I have a node.js (express) application and I'm using node_redis to get all users from my redis db. redis = require "redis" client = redis.createClient() client.smembers "users", (err, user_ids) -> results = new Array() for user_id in user_ids client.hgetall user_id, (err, items) -> results.push items if user_ids.length is results.length res.json results This produces the following result: [ { "name": "user1", "password": "secret" }, { "name": "user2", "password": "secret" } ] Now I want the

What would it take to implement a good redis-client in the web-browser?

无人久伴 提交于 2019-12-07 06:42:52
问题 This has been asked before at Can I connect directly to a Redis server from JavaScript running in a browser? (notice my comment) and Connecting directly to Redis with (client side) javascript? but I wonder about something which would have perfect realtime connection. Reading the (a node-redis client) https://github.com/luin/ioredis source I noticed the net part of node`s library is likely containing the kind of functionality we'd need to reproduce in the browser to do this . Guessing maybe

How can I access the key passed to hgetall when using node_redis?

删除回忆录丶 提交于 2019-12-06 12:07:31
I have a node.js (express) application and I'm using node_redis to get all users from my redis db. redis = require "redis" client = redis.createClient() client.smembers "users", (err, user_ids) -> results = new Array() for user_id in user_ids client.hgetall user_id, (err, items) -> results.push items if user_ids.length is results.length res.json results This produces the following result: [ { "name": "user1", "password": "secret" }, { "name": "user2", "password": "secret" } ] Now I want the user_id to be added to the user result, so I can get the following output: [ { "user:1": { "name":

Redis connection gone from close event

♀尐吖头ヾ 提交于 2019-12-06 03:17:37
问题 In our redis configuration we have set timeout: 7 seconds In node_redis We handle redis connection ready and end event as client.on("ready", function() { logger.info("Connection Successfully Established to ", this.host, this.port); } client.on("end", function() { logger.fatal("Connection Terminated to ", this.host, this.port); } Sample log [2012-07-11 08:21:29.545] [FATAL] Production - Connection Terminated on end to 'x.x.x.9' '6399' [2012-07-11 08:21:29.803] [INFO] Production - Connection

How to use redis to store hierarchical data?

江枫思渺然 提交于 2019-12-05 16:34:28
问题 I have a set of hierarchical data to store, the hierarchy is like site/building/floor, the data, for example { site:'New York', buildings: [ { name:'building a', floors: [ 'Ground':[{room:room1},{room:room2}], 'First':[{room:room1},{room:room2}] ] } ] }, { site:'London', buildings: [ { name:'building a', floors: [ 'Ground':[{room:room1},{room:room2}], 'First':[{room:room1},{room:room2}] ] } ] } I want to store these room data into a set, but I can also query the a subset of rooms by selecting

What would it take to implement a good redis-client in the web-browser?

。_饼干妹妹 提交于 2019-12-05 08:40:08
This has been asked before at Can I connect directly to a Redis server from JavaScript running in a browser? (notice my comment) and Connecting directly to Redis with (client side) javascript? but I wonder about something which would have perfect realtime connection. Reading the (a node-redis client) https://github.com/luin/ioredis source I noticed the net part of node`s library is likely containing the kind of functionality we'd need to reproduce in the browser to do this . Guessing maybe something with hacked together from pieces of webrtc functions could do it ? Prospective benefits relate