Skip to content
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

New Wrapper for cluster as in ISSUE #113 #128

Closed
wants to merge 3 commits into from
Closed

Conversation

zcqzcg
Copy link

@zcqzcg zcqzcg commented Sep 26, 2022

Hi team,
Thanks to the authors to provide such a nice and effective rmq for Gophers!

I'm using this packge and have to work with a redis cluster, so I forked and added a new RedisClusterWrapper for the cluster to fit in.

  • NewWrapper for cluster
  • Rename original wrapper as SingleWrapper also the filename
  • Open redis connection with *redis.Option which could allow users to connect their redis more freely
  • Added/modified some tests roughly for the cluster testing.

Please feel free to modify/update these commits

====================
And a big thanks to ISSUE #113 , @obh provided a direction to the cluster path

Best,
David

Copy link
Owner

@wellle wellle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your work on this! 🙌

I have two main concerns right now:

Comment on lines -11 to +12
queueReadyTemplate = "rmq::queue::[{queue}]::ready" // List of deliveries in that {queue} (right is first and oldest, left is last and youngest)
queueRejectedTemplate = "rmq::queue::[{queue}]::rejected" // List of rejected deliveries from that {queue}
queueReadyTemplate = "rmq::queue::{{queue}}::ready" // List of deliveries in that {queue} (right is first and oldest, left is last and youngest)
queueRejectedTemplate = "rmq::queue::{{queue}}::rejected" // List of rejected deliveries from that {queue}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change which is hard to deal with when using a setup which relies on [] (like we do internally). Do you think you could add a way to have {} by default, but switch back to using [] with some sort of flag? 🤔

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah sure, I will see what I can do about this one

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wellle Might know where I can find the setup which relies on [] ? Thanks

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll look into this 👍

Copy link
Owner

@wellle wellle Nov 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I found it already. We use this feature internally: twitter/twemproxy@f08088f

In there they use hash_tag: "{}" to demonstrate.
In our specific setup we use it like this instead: hash_tag: "[]".

So ideally we would be able to support both of these use cases (with {} being the default).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's an idea of how it could be done. I don't like how it uses a global variable, so please let me know if you see a better approach. 🙏

  1. Add a global rmq.HashTag = "{}". This allows users (like us) to set rmq.HashTag = "[]" before opening an rmq connection.

  2. Then in newQueue() we currently have code like this:

    readyKey := strings.Replace(queueReadyTemplate, phQueue, name, 1)

    Let's replace that like this:

    readyKey := queueReadyKey(name)

    So in redis_keys.go we would add these functions which take the rmq.HashTag value into account. For example it may look like this (untested):

    func queueReadyKey(queueName string) string {
    	hashTagOpen, hashTagClose := rmq.HashTag[0], rmq.HashTag[1]
    	return fmt.Sprintf("rmq::queue::%s%s%s::ready", hashTagOpen, queueName, hashTagClose)
    }

Do you think you could try this for the 4 keys which use the {queue} placeholder?

return OpenConnectionWithRmqRedisClient(tag, RedisWrapper{redisClient}, errChan)
// OpenConnectionWithRedisClusterClient opens and returns a new connection for a cluster redis
func OpenConnectionWithRedisClusterClient(tag string, clusterClient *redis.ClusterClient, errChan chan<- error) (Connection, error) {
return OpenConnectionWithRmqRedisClient(tag, RedisClusterWrapper{clusterClient}, errChan)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried using the existing wrapper with the cluster client?

Suggested change
return OpenConnectionWithRmqRedisClient(tag, RedisClusterWrapper{clusterClient}, errChan)
return OpenConnectionWithRmqRedisClient(tag, RedisSingleWrapper{clusterClient}, errChan)

When I compare these files
https://github.com/adjust/rmq/blob/3113601ad47836e110cd3201f160b69c172f9770/redis_wrapper_single.go
https://github.com/adjust/rmq/blob/3113601ad47836e110cd3201f160b69c172f9770/redis_wrapper_cluster.go
it looks like the cluster client has exactly the same functions, so I wonder if it might actually implement the redis.Cmdable interface, in which case we should be able to still use the existing wrapper instead of having the need for two different (but almost identical) wrapper implementations.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I have tried, works fine with me 💯

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so I wonder if it might actually implement the redis.Cmdable interface

This also confuses me, the redis.Client does implement the redis.Cmdable, but, redis.ClusterClient does not.

I have checked the wrapper functions, which is common, and my team also wrapped same functions both for cluster and single redis.

It also needs some work to do to make the code more elegent, such as making new interface to fit the two type of redis clients, I will see what I can do in the future, thanks for pointing out! 👍

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The redis.ClusterClient has implementd Cmdable already, so this wrapper might be not necessary

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for jumping in here! 🙌

Do you think you can take this branch and remove this wrapper again to see if it works without it? Feel free to open a new PR with the updated branch then. Thanks again!

@zcqzcg zcqzcg closed this Oct 8, 2022
@zcqzcg
Copy link
Author

zcqzcg commented Oct 8, 2022

Still needs working, will make PR later

@QuanTran91
Copy link

QuanTran91 commented Nov 21, 2022

How is it going with this PR? I got an issue in which I cannot use the rmq in cluster mode.

@wellle
Copy link
Owner

wellle commented Nov 21, 2022

@zcqzcg: Are you still working on this? If not, maybe someone else can pick up this PR and try to address the review comments above 🙏

@zcqzcg
Copy link
Author

zcqzcg commented Nov 21, 2022

@zcqzcg: Are you still working on this? If not, maybe someone else can pick up this PR and try to address the review comments above 🙏

SoSorry I haven't have enough time to work with this repo for now. Please if someone could take over

@wellle
Copy link
Owner

wellle commented Nov 21, 2022

Thanks for the update!

Any takers? 🙏

@wellle
Copy link
Owner

wellle commented Jan 17, 2024

Seeing the conversation in #113 I feel like this may have been resolved by the changes made related to Redis Cluster. I'm closing it as I'm not sure if this problem still persists. Please feel free to reopen if it does ✌️

@wellle wellle closed this Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants