socket.io-redis | enable broadcasting of events to multiple separate socket | Socket library
kandi X-RAY | socket.io-redis Summary
kandi X-RAY | socket.io-redis Summary
Adapter to enable broadcasting of events to multiple separate socket.io server nodes.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of socket.io-redis
socket.io-redis Key Features
socket.io-redis Examples and Code Snippets
Community Discussions
Trending Discussions on socket.io-redis
QUESTION
I'm using socket.io together with redis and I need to get the socket object since there's data I need to access that's added during the middleware.
When I do this:
...ANSWER
Answered 2021-May-14 at 20:14In socket.io v4, you can do:
QUESTION
I am working on setting up socket.io in cluster mode using PM2.
I am using socket.io-redis
package and it works fine in cluster mode.
But the problem arises when I want to access all connected sockets. Because processes don't know about socket connections in other processes in cluster mode.
I thought socket.io-redis
keeps track of all the connected sockets and all its session info but it didn't.
Is there any way or solution to access all the socket connection existing in all processes in socket.io/Nodejs?
ANSWER
Answered 2021-Apr-10 at 20:59Socket.io-redis does keep track in a sense..
From their docs
"The Redis adapter extends the broadcast function of the in-memory adapter: the packet is also published to a Redis channel (see below for the format of the channel name).
Each Socket.IO server receives this packet and broadcasts it to its own list of connected sockets."
So basically, redis is used as the broker to tell each socket server to emit based on X channel etc. Allowing you to have a socket.io server in cluster mode work, but as you have mentioned it can fall short when you need to keep track of things outside of just an emit.
So where does this leave us.. Well you can use custom hooks via socket.io-redis but personally I found it to be really difficult to understand and use and had limited success personally. I think with the new version of socket.io and socket.io redis there were some tweaks to make this simpler however I have not tried them.
Instead, what we do is use redis hset and jget to store the socket and an ID of a users, then when we want to get all users online we can query redis to get the list of online users or users in a specific room etc.
What you will want to do is add the redis package and connect in additon to the regular pub / sub.
Then, when a user joins a room or your server for that matter you will do an hset. On the first join ours looks something like this
QUESTION
I'm using socket.io "^1.7.1", and "socket.io-redis": "^6.0.1" when I am doing the following
...ANSWER
Answered 2021-Mar-11 at 06:04So, I was doing some research and it turned out that my socket.io-redis version was not compatible with socket.io. I have updated my socket.io version to 2.4.1 and not this issue is resovled.
QUESTION
When using SocketIO
in an application that runs behind a node-balancer, the official documentation states the way to pass events between those nodes (using SocketIO-Redis
):
ANSWER
Answered 2020-Sep-26 at 18:26How would one implement a Redis-Adapter when using the SocketIO-JS-standalone version?
I don't know why you use "standalone" here. I think you mean the JavaScript Socket.IO client, which does not have anything to do with Redis, regardless of what Socket.IO server you use.
The Redis support is implemented by the server. For the Node Socket.IO server you use the Redis-Adapter project. For the Python Socket.IO server the support for Redis comes built-in, you just need to add the message_queue
argument when you create your server object, as shown in the docs.
QUESTION
I am trying to play around with socket.io and figure out if it suits us. I have ran into a problem while trying stuff out.
so in my server i have the following code:
...ANSWER
Answered 2020-Sep-07 at 12:17change
QUESTION
I have a VPC with 2 public subnets in different availability zones (public subnet-2a and public-subnet-2b). I have two private subnets (private-2a-EB-Instance, private-2b-EB-Instance), and two other private subnets for Elasticache (private-2a-EB-Instance, private-2b-EB-Instance), these two subnets for elasticache are part of a subnet group that I use when creating my Elasticache clusters.
I have create a security group for my ElastiCache(redis) and I have changed its inbound rules so it can accept connection from the security group of my ElasticBeanstalk environment. Didn't solve the problem.
I have followed the instructions on AWS' website, and I can't get it to work. I wonder what I am doing wrong. I am using socket-io-redis and I am wondering if that may be part of the problem.
I have used the .config file offered here , but I get an error when deploying the app. It says there was an error creating it.
I created the cluster from the console and tried to connect it to my EB app using the "Primary Endpoint", but I get the error:
...ANSWER
Answered 2020-Jun-10 at 01:29I think the problem is that you have included https://
in what is supposed to be the hostname. Redis does not connect over HTTP, it uses its own protocol. The error message getaddrinfo ENOTFOUND https://myelasticache.xxxxxxxxx.cache.amazonaws.com
indicates that it is trying to resolve https://myelasticache.xxxxxxxxx.cache.amazonaws.com
when you want it to use myelasticache.xxxxxxxxx.cache.amazonaws.com
.
So try removing https://
and see if it works or if you get another error.
QUESTION
I'm trying to build a realtime (private) chat between users of a video game with 25K+ concurrent connections. We currently run 32 nodes where users can connect through a load balancer. The problem I'm trying to solve is how to route messages to each user?
Currently, we are using socket.io & socket.io-redis, where each websocket joins a room with its user ID, and we emit each message they should receive to that room. The problem with this design is that we are reaching the limits of Redis Pubsub, and Socket.io which doesn't scale well (socket.io emit messages to all nodes which check if the user is connected, this is not viable).
Our current stack is composed of Postgres, Redis & RabbitMQ. I have been thinking about this problem a lot and have come up with 3 different solutions :
- Route all messages with RabbitMQ. When a user connects, we create an exchange with type fanout with the user ID and a queue per websocket connection (we have to handle multiple connections per user). When we want to emit to that user, we simply publish to that exchange. The problem with that approach is that we have to create a lot of queues, and I heard that this may not be very efficient.
- Create a queue for each node in RabbitMQ. When a user connects, we save the node & socket ID in a Redis Set, so that when we have to send a message to that specific user, we first get the list of nodes, emit to each node queue, which then handle routing to specific client in the app. The problems with that approach is that in the case of a node failure, we may store that a user is connected when this is not the case. To fix that, we would need to expire the users's Redis entry but this is not a perfect fix. Also, if we later want to implement group chat, it would mean we have to send duplicates messages in Rabbit, this is not ideal.
- Go all in with Firebase Cloud Messaging. We have a mobile app, and we plan to use it for push notifications when the user isn't connected, but would it be a good fit even if the user is connected?
What do you think is the best fit for our use case? Do you have any other idea?
...ANSWER
Answered 2020-Apr-27 at 12:44I found a better solution : create a binding for each user but using only one queue on each node, then we route each messages to each user.
QUESTION
I'm building a web server in nodejs which relies on redis, postgresql and mongodb. I store all the credentials in the google cloud secret manager, so I have to use asynchronous functions to get them. My code so far:
...ANSWER
Answered 2020-Apr-23 at 17:07you should not do it at application level. ideally it should be handle by your infra.
at app level, implement a health check route, and do your logic there. eg: if mysql or redis is down, return 500 error. infra will see that error and stop routing traffic to that instance / server / container.
QUESTION
Im experimenting abit with Socket.io and Socket.Io-redis. I have my Redis server up and running. The error i get when starting the Socket.Io server is: ReplyError: ERR unknown command 'pubsub' I dont know why i get this error at all.
The Redis version i'm using is 2.4.5
...ANSWER
Answered 2020-Mar-06 at 19:24I fixed it by installing latest version of Redis! :)
QUESTION
I have just initialized a new project with Node.js and trying making the scripts in package.json file to be working.
For example I have the next package.json file:
...ANSWER
Answered 2020-Mar-05 at 22:59npm config set ignore-scripts false
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install socket.io-redis
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page