Can i use the same redis instance for the adapter to store data? #3968
-
Was wondering if its okay to use the same Redis instance for some state persistence. Would there be any conflict ? //redis setup
const redisAdapter = require("@socket.io/redis-adapter");
const Redis = require("ioredis");
const pubClient = new Redis();
const subClient = pubClient.duplicate();
pubClient.set("foo", "bar");
pubClient.get("foo", function (err, result) {
if (err) {
console.error(err);
} else {
console.log(result); // Promise resolves to "bar"
}
});
const io = new Server(server, {
cors: {
origin: "http://localhost:3000",
methods: ["GET", "POST"],
},
});
io.adapter(redisAdapter(pubClient, subClient)); |
Beta Was this translation helpful? Give feedback.
Answered by
darrachequesne
Jun 11, 2021
Replies: 1 comment
-
Yes, you can totally reuse the The Reference: https://redis.io/commands/subscribe |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
branlok
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, you can totally reuse the
pubClient
.The
subClient
cannot be used though, as it is put in subscribed state.Reference: https://redis.io/commands/subscribe