Skip to content

Make shards in redis.Ring publicly accessible #3341

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

Open
jaapz opened this issue Apr 10, 2025 · 3 comments
Open

Make shards in redis.Ring publicly accessible #3341

jaapz opened this issue Apr 10, 2025 · 3 comments

Comments

@jaapz
Copy link

jaapz commented Apr 10, 2025

We use redis.Ring to shard load across servers. We shard mainly PubSub related commands, PSUBSCRIBE, SUBSCRIBE, PUNSUBSCRIBE and UNSUBSCRIBE.

Because these commands put the redis connection in a special "pubsub" mode, after which you cannot use it for anything else than pubsub, we try to re-use these connections as much as possible.

What we'd like to do is set up a pubsub connection for every shard in the ring at application start, and then re-use that pubsub connection when we need to subscribe or unsubscribe on a topic.

However for that to be possible, we need two things:

  • access to the list of shards, so we can immediately create a pubsub connection for each shard in the ring
  • access to ringSharding.GetByKey so we can determine which shard pubsub connection we can re-use for a given topic

However, on redis.Ring the sharding attribute, which contains an instance of *ringSharding, is not publicly accessible, so we cannot access the shards list or the GetByKey function.

We are working around this for now, but it's rather ugly, because we need to make assumptions in our own code on how topics are distributed over the ring.

Would it be possible to make redis.Ring.sharding public, or at least provide some public methods on redis.Ring to return the list of shards access the GetByKey function?

I would be open to create a merge request if there is a chance of it being accepted.

@ndyakov
Copy link
Member

ndyakov commented Apr 10, 2025

Hello @jaapz , as far as I remember, the distribution of keys for Ring will be done with consistent hashing and you can even provide the algorithm. @htemelski maybe you can take a look if it makes sense to export the ring sharding.

@jaapz
Copy link
Author

jaapz commented Apr 15, 2025

Correct, we're using that as well. But if we want to determine on our side which server will be returned for a given topic, then we need to basically copy code that is already present in redis.Ring. It would be nicer if we could simply call something like redis.Ring.Sharding.GetByKey(mytopic) or redis.Ring.GetByKey(mytopic) and get the shard like that.

@ndyakov
Copy link
Member

ndyakov commented Apr 17, 2025

@ofekshenawa if you have the time you may look into this and if it makes sense to be exposed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants