-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ssubscribe within a cluster is not working properly #1759
Comments
Thanks for raising this up! Yeah we currently don't route messages to the right node and also don't subscribe to the right node. Should think about a solution for that. |
I'm facing the same problem, I'm not getting the 'smessage' event when I register the sSubscribe function. |
With a total of 3 Redis servers (ports 6379, 6380, 6381) deployed in a Redis Cluster using Docker Compose, I executed the code below. import { Cluster, Redis } from 'ioredis'
async function getRedisClient(): Promise<Cluster> {
return new Promise(async (resolve, reject) => {
const redisClient = new Redis.Cluster([
{
host: 'localhost',
port: 6379
}
], {
scaleReads: 'slave',
retryDelayOnMoved: 100,
redisOptions: {
username: 'default',
password: 'redispw',
tls: undefined
},
})
redisClient.on('error', (err: Error) => {
console.error('[Ioredis] on ERROR', err)
})
redisClient.on('connect', async () => {
console.log('Redis cluster connected')
resolve(redisClient)
})
})
}
async function main() {
const publisher = await getRedisClient()
const subscriber = await getRedisClient()
subscriber.on('smessage', (channel: string, message: string) => {
console.log('smessage', channel, message)
})
subscriber.on('message', (channel: string, message: string) => {
console.log('message', channel, message)
})
await subscriber.ssubscribe('hello1') // Too many redirection error (127.0.0.1:6380)
await subscriber.ssubscribe('hello2') // Too many redirection error (127.0.0.1:6381)
await subscriber.ssubscribe('hello3') // ok (127.0.0.1:6379)
await publisher.spublish('hello3', '{"name": "honsemiro"}')
}
main() Of these, only the 'hello3' channel was successful in subscribing to the shard channel. My guess is that there are different shards that are assigned based on the checksum value, and that's why it subscribes to certain shards and not others. Here's the error message.
|
is there any updates on this? @luin |
If it's helpful to anyone reading this -- the library node-redis (v4) supports sharded pubsub commands properly (SSUBSCRIBE, SPUBLISH, SUNSUBCRIBE) For my project I had to migrate off of |
Any news about it ? I'd prefer not to migrate to |
@tominou we ended up using |
Hi! It seems there is an issue with the spublish()/ssubscribe() methods added in 6285e80:
The
smessage
event is not received. It works with classic publish()/subscribe() though:My
docker-compose.yml
, for reproducibility:The test case here looks a bit weird, shouldn't it be something like:
Thanks in advance!
The text was updated successfully, but these errors were encountered: