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

113 Add support for Redis clusters #148

Merged
merged 11 commits into from
Jul 20, 2023
Merged

Conversation

wellle
Copy link
Member

@wellle wellle commented Jun 29, 2023

Close #113.

This PR adds support for using rmq with a Redis cluster by allowing to use the Redis hash tags {} instead of the characters [] we used before. We used [] before to allow having certain keys live on the same Redis node using nutcracker, in the same way {} is now used by Redis cluster.

This is a continuation of #128. I took the original commits (with slight modifications) and then added a few more to:

  1. Remove breaking changes, bring back original OpenConnection() functions, make sure their behavior doesn't change compared to master.
  2. Remove the new wrapper that had been added previously.
  3. Add a new OpenClusterConnection() function which uses the different Redis hash keys {} instead of [].
  4. Add a small section about this new function to the Readme.

Note: I managed to run the tests locally by following https://github.com/redis/redis/tree/unstable/utils/create-cluster and then running the tests like this:

REDIS_CLUSTER_ADDR="localhost:30001,localhost:30002,localhost:30003,localhost:30004,localhost:30005,localhost:30006" go test

But in the current state they are not easy to run locally (you need a Redis cluster) and I expect them to fail in CI too. We should try to improve/fix that. Maybe there's a way to set up a working Redis cluster with miniredis (which is already used in some tests)?

zhanglei and others added 8 commits June 27, 2023 14:33
add queue_cluster_test.go

welle: Remove hardcoded connection options.
Add new function OpenConnectionWithOptions() for the new approach.
Rename RedisSingleWrapper back to RedisWrapper
To allow opening RMQ connections which use the Redis hash tags {}
instead of []. This is required to make rmq work with Redis clusters.

This commit also reverts the behavior of all other OpenConnection[...]
functions to behave as before by still using [] instead of {}.

This switch is done by using different Redis key templates. For example
instead of

    rmq::connection::{connection}::queue::[{queue}]::consumers

we would use

    rmq::connection::{connection}::queue::{{queue}}::consumers

when using OpenClusterConnection()
@github-actions
Copy link

github-actions bot commented Jun 29, 2023

Lines Of Code

Language Files Lines Code Comments Blanks Complexity Bytes
Go 29 3025 (+87) 2215 (+64) 291 (+7) 519 (+16) 400 (+3) 80.3K (+3K)
Go (test) 8 (+1) 2445 (+890) 1961 (+713) 82 (+34) 402 (+143) 159 (+72) 72K (+27.7K)
Markdown 1 654 (+9) 485 (+8) 0 169 (+1) 0 24.6K (+459B)
Shell 1 (+1) 125 (+125) 105 (+105) 5 (+5) 15 (+15) 32 (+32) 3K (+3K)
YAML 4 355 (-9) 301 (-9) 16 38 0 13.3K (-3B)

@github-actions
Copy link

Go API Changes

# github.com/adjust/rmq/v5
## compatible changes
OpenClusterConnection: added
OpenConnectionWithRedisOptions: added

# summary
Inferred base version: v5.1.3
Suggested version: v5.2.0

@github-actions
Copy link

github-actions bot commented Jun 29, 2023

Benchmark Result

Benchmark diff with base branch
name     old time/op    new time/op    delta
Queue-2     193µs ± 1%     194µs ± 2%    ~     (p=0.548 n=5+5)

name     old alloc/op   new alloc/op   delta
Queue-2    42.0kB ± 3%    42.3kB ± 7%    ~     (p=0.792 n=5+6)

name     old allocs/op  new allocs/op  delta
Queue-2      91.0 ± 0%      94.2 ± 1%  +3.48%  (p=0.002 n=6+6)
Benchmark result
name     time/op
Queue-2   194µs ± 2%

name     alloc/op
Queue-2  42.3kB ± 7%

name     allocs/op
Queue-2    94.2 ± 1%

@wellle wellle requested a review from vearutop June 30, 2023 10:53
@github-actions
Copy link

Unit Test Coverage

total: (statements) 71.4%
changed lines: (statements) 77.8%, coverage is less than 90.0%, consider testing the changes more thoroughly

Coverage of changed lines
File Function Coverage
Total 77.8%
connection.go 88.9%
connection.go:75 OpenConnectionWithRedisOptions 100.0%
connection.go:93 OpenConnectionWithRmqRedisClient 100.0%
connection.go:98 OpenClusterConnection 100.0%
connection.go:102 openConnection 100.0%
connection.go:268 hijackConnection 100.0%
connection.go:306 openQueue 100.0%
connection.go:70 OpenConnection 0.0%
queue.go 100.0%
queue.go:66 newQueue 100.0%
redis_keys.go 100.0%
redis_keys.go:21 getTemplate 100.0%
redis_wrapper.go 100.0%
redis_wrapper.go:14 Set 100.0%
redis_wrapper.go:19 Del 100.0%
redis_wrapper.go:23 TTL 100.0%
redis_wrapper.go:27 LPush 100.0%
redis_wrapper.go:31 LLen 100.0%
redis_wrapper.go:35 LRem 100.0%
redis_wrapper.go:39 LTrim 100.0%
redis_wrapper.go:44 RPop 100.0%
redis_wrapper.go:48 RPopLPush 100.0%
redis_wrapper.go:61 SAdd 100.0%
redis_wrapper.go:65 SMembers 100.0%
redis_wrapper.go:69 SRem 100.0%
redis_wrapper.go:73 FlushDb 100.0%
test_util.go 38.9%
test_util.go:14 testRedis 69.2%
test_util.go:25 testClusterRedis 14.6%
Coverage diff with base branch
File Function Base Coverage Current Coverage
Total 72.3% 71.4% (-0.9%)
github.com/adjust/rmq/v5/connection.go OpenClusterConnection no function 100.0%
github.com/adjust/rmq/v5/connection.go OpenConnection 100.0% 0.0% (-100.0%)
github.com/adjust/rmq/v5/connection.go OpenConnectionWithRedisOptions no function 100.0%
github.com/adjust/rmq/v5/connection.go OpenConnectionWithRmqRedisClient 75.0% 100.0% (+25.0%)
github.com/adjust/rmq/v5/connection.go openConnection no function 75.0%
github.com/adjust/rmq/v5/queue.go batchTimeout 92.3% 84.6% (-7.7%)
github.com/adjust/rmq/v5/redis_keys.go getTemplate no function 100.0%
github.com/adjust/rmq/v5/test_batch_consumer.go Consume 100.0% 85.7% (-14.3%)
github.com/adjust/rmq/v5/test_util.go testClusterRedis no function 30.8%
github.com/adjust/rmq/v5/test_util.go testRedis no function 60.0%

Copy link
Member

@vearutop vearutop left a comment

Choose a reason for hiding this comment

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

I've updated CI setup to use the mentioned create-cluster script instead of a dockerized service.

Copy link
Member Author

@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.

LGTM, thanks!

@vearutop vearutop merged commit 93f1717 into master Jul 20, 2023
@vearutop vearutop deleted the 113-redis-cluster-support branch July 20, 2023 09:50
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.

redis cluster - CROSSSLOT error
2 participants