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

Add support of redis clusters #236

Merged
merged 4 commits into from
Mar 20, 2024
Merged

Add support of redis clusters #236

merged 4 commits into from
Mar 20, 2024

Conversation

Millefeuille42
Copy link
Contributor

Add Redis cluster support as session management backend.
Fixing #235.

Millefeuille42 and others added 2 commits March 5, 2024 14:25
Add Redis cluster support as session management backend
))
if options is None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't this odd? It seems to suggest we are only going to care about the options from the first url that has any

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the way I found to add options (password for example) without adding too much clutter.
Options other than port and host should be the same in every node (or at least we can specify only one with the redis cluster module).

If specifying multiple nodes, it will only parse the first one indeed.
Considering that only one set of options can be provided, what would be the best option in this case? We could merge all parsed url_options eventually.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Adding a redis_options parameter to the RedisClusterNamespaceManager should be the best way.
Any option provided during middleware configuration gets forwarded to the cache, so like you provide the url you can provide redis_options.

If the concern is that it should be possible to provide options via .ini files too, there are options like decoding them from JSON when they are provided as a string instead of a dict.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems good, will add a parameter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

About the .ini part, I'm not very fond of using another format inside a config file (like JSON inside a .ini file). What could be done is using a reference URL as redis_cluster_options, which will be parsed with redis.connection.parse_url and extract options from here.

But this seems as "weird" as using JSON inside a .ini file... Not sure of where to go from here

Copy link
Contributor Author

@Millefeuille42 Millefeuille42 Mar 18, 2024

Choose a reason for hiding this comment

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

Looked at how it is done in other ext/ files and adopted the kwargs solution. Options are not parsed from urls anymore but are provided through kwargs. This seems like it's how the redis-py devs intended, and it will be more sustainable than having explicit options.

from beaker._compat import string_type, PY2


class RedisClusterNamespaceManager(NamespaceManager):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can't this inherit from RedisNamespaceManager and only override __init__? What's the benefit of reimplementing all other methods?

Actually, is there a reason why this can't be a simple option to the RedisNamespaceManager like cluster=true? Or even if "," in urls?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is no point at the moment. Indeed inheriting from RedisNamespaceManager could be the best option to prevent clutter in the RedisNamespaceManager file ans to not reimplementing all.

I did not do that before because I couldn't see it elsewhere in the code and I was not sure if it was ok that some drivers depend on other's code.

Will do that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, using inheritance and overrides to prevent reimplementing identical code.

@Millefeuille42 Millefeuille42 requested a review from amol- March 18, 2024 17:02
@amol-
Copy link
Collaborator

amol- commented Mar 19, 2024

Good, much better.
Could you please also add a testsuite for rediscluster? You can copy it from test_ext_redis.py and replace ext:redis with ext:rediscluster

@Millefeuille42
Copy link
Contributor Author

Done !

@amol- amol- merged commit 977c4a5 into bbangert:master Mar 20, 2024
@amol-
Copy link
Collaborator

amol- commented Apr 4, 2024

@Millefeuille42 are you aware of any way to test redis cluster in GitHub Actions? The newly added tests for cluster are failing because the target redis node is not started in cluster mode, see https://github.com/bbangert/beaker/actions/runs/8556636486/job/23446940757#step:12:261

@Millefeuille42
Copy link
Contributor Author

I think you can refer to something like this https://github.com/vishnudxb/redis-cluster which seems to provide a standard redis cluster.
Unfortunately I have low exp on github actions, could help with how to deploy a redis cluster, but I am not sure about how to integrate it to github actions

@amol-
Copy link
Collaborator

amol- commented Apr 5, 2024

@Millefeuille42 nice, the testsuite correctly runs with the action that you suggested.
But the tests have shown that the current implementation is actually broken, the Synchronizer does not work due to lack of transactions in the redist cluster: https://github.com/bbangert/beaker/actions/runs/8575910114/job/23505874987#step:14:270

Are you aware of a best practice to implement atomic lock release in redis cluster? See https://github.com/bbangert/beaker/blob/master/beaker/ext/redisnm.py#L125-L132

@amol-
Copy link
Collaborator

amol- commented Apr 9, 2024

Lock on cluster has been fixed in #238

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.

2 participants