Comments (2)
Fixed by you in dcbb87d
from node-redis.
This still occurs in the following situation:
Start redis-server
run node client.js (see file below)
restart redis-server
The client remembers it is in subscribe mode and somehow thinks the connect attempt is a command?
127.0.0.1:6379 failed - connect ECONNREFUSED
Some error happened to the redis client: Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED
Connected
/Users/george/code/touchPals/touchNode/node_modules/redis/index.js:680
throw new Error("Connection in pub/sub mode, only pub/sub commands may
^
Error: Connection in pub/sub mode, only pub/sub commands may be used
at RedisClient.send_command (/Users/george/code/touchPals/touchNode/node_modules/redis/index.js:680:15)
at RedisClient. (/Users/george/code/touchPals/touchNode/node_modules/redis/index.js:826:25)
at RedisClient.ready_check (/Users/george/code/touchPals/touchNode/node_modules/redis/index.js:340:10)
at RedisClient.on_connect (/Users/george/code/touchPals/touchNode/node_modules/redis/index.js:216:18)
at Socket. (/Users/george/code/touchPals/touchNode/node_modules/redis/index.js:66:14)
at Socket.emit (events.js:64:17)
at Object.afterConnect as oncomplete
Test client:
var fs = require('fs');
var options = {
key: fs.readFileSync('../certificates/arranged_marriage.key'),
cert: fs.readFileSync('../certificates/arranged_marriage.crt')
};
console.log("Things are going well");
var app = require('https').createServer(options);
app.listen(8000);
var WebSocketServer = require('ws').Server;
var wss = new WebSocketServer({server: app});
// var WebSocketServer = require('ws').Server,
// wss = new WebSocketServer({port:8000, host:'localhost'});
var socketByToken = {};
// Good to know about this potential bug - it occurs sometimes when
// the redis server is down and the client tries to reconnect before a certain number of tries
// #20
var redis = require("redis"),
redisClient = redis.createClient();
wss.on('connection', function(ws) {
console.log("Server: someone connected to me");
// console.log('additional info:');
// console.log(ws);
ws.on('message', function(token) {
console.log('received token: %s', token);
// Extract token from message
socketByToken[token] = this;
});
ws.on('error', function(error) {
console.log('some error happened:' + error);
console.log('A client may have called Close');
});
});
redisClient.on("message", function (channel, jsonMessage) {
console.log("Received message:");
console.log(jsonMessage);
// This is a potential security issue - JSON objects can contain code
var parsedMessage = "";
try {
parsedMessage = JSON.parse(jsonMessage);
var token = parsedMessage.token;
delete parsedMessage.token;
console.log("About to send command: " + JSON.stringify(parsedMessage) + " to user with token: " + token);
socketByToken[token].send(JSON.stringify(parsedMessage));
} catch (err) {
console.log(err);
return;
}
console.log("Sent message: " + parsedMessage + " to user with token: " + token);
});
redisClient.on("error", function (error) {
console.log("Some error happened to the redis client: " + error);
});
redisClient.on("connect", function (maybe) {
console.log("Connected");
});
redisClient.subscribe("chats");
console.log("Connected to Redis...");
wss.on('close', function(ws) {
console.log("Server: someone disconnected to me");
});
from node-redis.
Related Issues (20)
- JSONPath syntax - problem with filtering JSON objects using "?()" syntax HOT 1
- @redis/client from 1.5.16 to 1.5.17 breaking change
- Client fails to reconnect to redis cluster after version upgrade in kubernetes HOT 1
- Long term support for legacy mode? HOT 2
- client.connect() does not throw error on non-existing or closed host:port pair HOT 1
- Has the pipeline function been removed from node-redis? HOT 7
- Command parameter enums not exported
- cluster slots not rediscovered on scale-down cluster HOT 1
- JSON.MGET not a readonly command
- Client network socket disconnected before secure TLS connection was established
- EVAL/EVALSHA | Cluster mode | Wrong node infer
- Achieve atomic updates with node-redis zIncrBy for multiple members HOT 2
- Connecting to Cluster not working with docker ENETUNREACH HOT 15
- Redis client does not quit when `isolationPoolOptions` is provided HOT 1
- Connecting to Cluster not working in Private Network
- Pub/sub subscription does not resubscribe successfully after a socket closed unexpectedly error
- Migrating from ioredis with keyv on ApolloServer
- Cluster connections fails after upgrade to 1.5.17 from 1.5.16
- HGET can return null, but TypeScript says it can't
- disableReconnect parameter is not exposed for modification HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-redis.