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

Recommend alternatives to the deprecated Redis.current in the README and deprecation message #1064

Closed
henrik opened this issue Feb 3, 2022 · 11 comments

Comments

@henrik
Copy link

henrik commented Feb 3, 2022

I'd be happy to make a PR if someone more knowledgeable can say what alternatives are suitable to recommend.

This would make for a better upgrade experience.

@NobodysNightmare
Copy link

NobodysNightmare commented Feb 3, 2022

If it helps, I asked a similar question on the commit introducing the deprecation and got the following response from @byroot:


Because multi-threaded environments are very much the default these days, and sharing the same Redis instance between threads leads to tons of locking.

So I prefer not to encourage this anymore. As you said it's super easy to just use $redis instead if that's really what you want.

It's not the role of a database client to manage the lifecycle to the connection, it's up to the application to do that.

Do you recommend building an own place to store the redis client if needed

Yes. And you likely want to a connection pool with it.

@byroot
Copy link
Collaborator

byroot commented Feb 3, 2022

I didn't expect people to still be using this to be honest.

There really isn't one replacement for it. If you really want the same behavior, you can use $redis global variable, at least it makes it obvious it's a shared global client. But I'd feel really weird recommending that in README or warning message.

The solution is mostly application specific so it's hard to give one guideline.

@henrik
Copy link
Author

henrik commented Feb 3, 2022

Thanks! It's fine for the recommendation to include that nuance, I think. Doesn't have to be super long. Maybe something along these lines?

You can replace it with a global $redis = Redis.new(…), though this will share a single connection between threads, and could lead to lock contention in a multi-threaded environment. To avoid that, you can add a connection pool, e.g. as discussed in https://github.com/mperham/sidekiq/wiki/Using-Redis#complete-control.

For the single-connection case I guess there's no practical benefit (beyond subjective aesthetics) to replacing $redis with an accessor assigned at app boot, so I'm thinking this might be good enough.

@byroot
Copy link
Collaborator

byroot commented Feb 3, 2022

I'd like to wait a bit to see if it's really causing confusion. I wouldn't be against a "deprecated" section in the readme, or better in a deprecations.md, but I'd rather not make the warning messages too big.

@henrik
Copy link
Author

henrik commented Feb 3, 2022

Alright. This issue and the updates to https://stackoverflow.com/questions/21075781/redis-global-variable-with-ruby-on-rails/34673035#34673035 may in themselves help people get an idea about their options, so perhaps it's fine. I thought it was odd to see the deprecation in the changelog without any context about reasons or alternatives.

pgwillia added a commit to ualbertalib/jupiter that referenced this issue Feb 8, 2022
Post-install message from sidekiq-unique-jobs:
IMPORTANT!

Automatic configuration of the sidekiq middleware is no longer done.
Please see: https://github.com/mhenrixon/sidekiq-unique-jobs/blob/master/README.md#add-the-middleware

`Redis.current=` is deprecated and will be removed in 5.0 redis/redis-rb#1064
pgwillia added a commit to ualbertalib/jupiter that referenced this issue Feb 15, 2022
Post-install message from sidekiq-unique-jobs:
IMPORTANT!

Automatic configuration of the sidekiq middleware is no longer done.
Please see: https://github.com/mhenrixon/sidekiq-unique-jobs/blob/master/README.md#add-the-middleware

`Redis.current=` is deprecated and will be removed in 5.0 redis/redis-rb#1064
@kylesnowschwartz
Copy link

For the record, this deprecation lead to some confusion on my team as well. I was very glad of this conversation and the suggestions and resources provided to point me in the right direction of how to solve this deprecation.

kylesnowschwartz added a commit to envato/rack-ecg that referenced this issue Feb 20, 2022
Redis-rb, the Redis gem used by Rails apps, is deprecating a part of its
API which stores a global Redis connection. See
redis/redis-rb#1064 for context around that
deprecation.

To prepare for when this behavior will be removed, we must update this
application so that Redis will be passed in as an instance to be
checked, because it will not be globally available.
kylesnowschwartz added a commit to envato/rack-ecg that referenced this issue Feb 20, 2022
Redis-rb, the Redis gem used by Rails apps, is deprecating a part of its
API which stores a global Redis connection. See
redis/redis-rb#1064 for context around that
deprecation.

To prepare for when this behavior will be removed, we must update this
application so that Redis will be passed in as an instance to be
checked, because it will not be globally available.
kylesnowschwartz added a commit to envato/rack-ecg that referenced this issue Feb 20, 2022
Redis-rb, the Redis gem used by Rails apps, is deprecating a part of its
API which stores a global Redis connection. See
redis/redis-rb#1064 for context around that
deprecation.

To prepare for when this behavior will be removed, we must update this
application so that Redis will be passed in as an instance to be
checked, because it will not be globally available.
kylesnowschwartz added a commit to envato/rack-ecg that referenced this issue Feb 21, 2022
Redis-rb, the Redis gem used by Rails apps, is deprecating a part of its
API which stores a global Redis connection. See
redis/redis-rb#1064 for context around that
deprecation.

To prepare for when this behavior will be removed, we must update this
application so that Redis will be passed in as an instance to be
checked, because it will not be globally available.
@nickjj
Copy link

nickjj commented Feb 28, 2022

It left me wondering what to do too. I was using it so I could do things like Redis.current.ping in a health check URL, I also liked knowing it was there if I had to drop into using the raw Redis client instead of Rail's cache.

It would be great if the README file had a few examples of what to do in various use cases, for example if you're running a single Redis instance when using a multi-threaded web app server such as using Puma, etc.. Are there traffic considerations to take into account when picking a specific solution?

@NobodysNightmare
Copy link

NobodysNightmare commented Feb 28, 2022 via email

BARK-AFUNG-SCHWARZ added a commit to BARK-AFUNG-SCHWARZ/redis_reliable_queue that referenced this issue Apr 20, 2023
because current has been removed in later versions without replacement.

See redis/redis-rb#1064
@mi-wada
Copy link

mi-wada commented May 1, 2024

@henrik
Does this issue seem to be resolved by the following section, right?

https://github.com/redis/redis-rb?tab=readme-ov-file#connection-pooling-and-thread-safety

@NobodysNightmare
Copy link

NobodysNightmare commented May 1, 2024 via email

@henrik
Copy link
Author

henrik commented May 3, 2024

Yeah, agreed. Closing this issue 🫡

@henrik henrik closed this as completed May 3, 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

No branches or pull requests

6 participants