ActiveSupport::Cache::RedisCacheStore should support Redis instances for redis
kwarg
#32233
+7
−1
Conversation
…for `redis` kwarg
activesupport/lib/active_support/cache/redis_cache_store.rb
Outdated
if redis.respond_to?(:call) | ||
if redis.is_a?(Redis) | ||
redis | ||
elsif redis.respond_to?(:call) | ||
redis.call | ||
elsif redis | ||
redis |
as3richa
Mar 13, 2018
Author
I left this branch untouched. My rationale is that someone may want to provide an object that is workalike with Redis (ie. implementing get
, set
, etc. with a different backend) but that doesn't inherit from Redis. Should this branch remain?
I left this branch untouched. My rationale is that someone may want to provide an object that is workalike with Redis (ie. implementing get
, set
, etc. with a different backend) but that doesn't inherit from Redis. Should this branch remain?
matthewd
Mar 13, 2018
Member
Hmm... the triple branch does seem a bit ugly.
If we're going to have to use an is_a?
check to distinguish them, maybe we'd be better changing the existing condition to is_a?(Proc)
?
Hmm... the triple branch does seem a bit ugly.
If we're going to have to use an is_a?
check to distinguish them, maybe we'd be better changing the existing condition to is_a?(Proc)
?
as3richa
Mar 13, 2018
Author
Sure, SGTM
Sure, SGTM
as3richa
Mar 13, 2018
Author
Pushed
Pushed
2 commits
Mar 12, 2018
added … Redis instances for `redis` kwarg
cf7e25d
jeremy
added a commit
that referenced
this pull request
Mar 13, 2018
Since `Redis#call` duck types as a Proc, we'd call `#call` on it, thinking it's a Proc. Fixed by check for the Proc explicitly instead of duck typing on `#call`. Closes #32233
jeremy
added a commit
that referenced
this pull request
Mar 13, 2018
Since `Redis#call` duck types as a Proc, we'd call `#call` on it, thinking it's a Proc. Fixed by check for the Proc explicitly instead of duck typing on `#call`. References #32233
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Summary
Fixes a bug in #31134
ActiveSupport::Cache::RedisCacheStore should support operating upon a Redis instance given in its initializer (via the
redis
keyword argument). Ref: https://github.com/rails/rails/blob/master/activesupport/lib/active_support/cache/redis_cache_store.rb#L109-L116In actual fact, because
Redis.new.respond_to?(:call)
,RedisCacheStore
will instead treat a Redis instance like a proc,call
ing it to populate its@redis
: https://github.com/rails/rails/blob/master/activesupport/lib/active_support/cache/redis_cache_store.rb#L121-L122Obviously this doesn't have the correct semantics. The test case added in my first commit fails with a
Redis::TimeoutError
(if indeed a Redis instance is running on127.0.0.1:6379
).With the fix given in my second commit,
RedisCacheStore#redis
is precisely equal to the Redis instance given to the initializer, if indeed one was given.Other Information
I'm a first-time contributor😁 please let me know if I need to update any changelog or open this PR against a branch other than master.