Skip to content

sUnsubscribe throw CROSSSLOT Keys in request don't hash to the same slot #2502

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

Closed
ngot opened this issue May 10, 2023 · 2 comments
Closed

sUnsubscribe throw CROSSSLOT Keys in request don't hash to the same slot #2502

ngot opened this issue May 10, 2023 · 2 comments
Labels

Comments

@ngot
Copy link

ngot commented May 10, 2023

Description

I'm trying to use sUnsubscribe in the cluster mode. I find out it supports both string and array. Based on the current implementation, the array type implicitly enforces all the channels to be hashed to the same slot, otherwise an error will throw says ErrorReply: CROSSSLOT Keys in request don't hash to the same slot.

Just checking is that a intentional design or a bug?

https://github.com/redis/node-redis/blob/master/packages/client/lib/cluster/index.ts#LL372C10-L372C10

Node.js Version

16

Redis Server Version

No response

Node Redis Version

No response

Platform

No response

Logs

ErrorReply: CROSSSLOT Keys in request don't hash to the same slot
@leibale
Copy link
Contributor

leibale commented May 10, 2023

S[UN]SUBSCRIBE behaves just like any other command, either use "hash tags" or call SSUBSCRIBE twice:

// make sure both channels are in the same slots using "hash tags"
await cluster.SSUBSCRIBE(['{tag}1', '{tag}2'], (message, channel) => {
  console.log(message, channel);
});

// SSBUCRIBE twice, once for each slot
await Promise.all([
  cluster.SSUBSCRIBE('1', (message, channel) => {
    console.log(message, channel);
  }),
  cluster.SSUBSCRIBE('2', (message, channel) => {
    console.log(message, channel);
  })
]);

@ngot
Copy link
Author

ngot commented May 11, 2023

Thanks @leibale . This finding originnates from socketio/socket.io-redis-adapter#500

I believe this is not bug in node-redis. I will close it.

@ngot ngot closed this as completed May 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants