Skip to content
This repository has been archived by the owner on Jan 1, 2024. It is now read-only.

Commit

Permalink
Use Redis#exists? and fallback to #exists
Browse files Browse the repository at this point in the history
which could be either boolean or integer
  • Loading branch information
bsedin committed Apr 14, 2022
1 parent 7bba10d commit bb6ae55
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/vanity/adapters/redis_adapter.rb
Expand Up @@ -117,7 +117,13 @@ def get_experiment_completed_at(experiment)

def is_experiment_completed?(experiment) # rubocop:todo Naming/PredicateName
call_redis_with_failover do
@experiments.exists("#{experiment}:completed_at")
if @experiments.respond_to?(:exists?)
@experiments.exists?("#{experiment}:completed_at")
else
exists = @experiments.exists("#{experiment}:completed_at")

exists.is_a?(Numeric) ? exists > 0 : exists
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/adapters/redis_adapter_test.rb
Expand Up @@ -62,7 +62,7 @@ def stub_redis

it "gracefully fails in #is_experiment_completed?" do
redis_adapter, mocked_redis = stub_redis
mocked_redis.stubs(:exists).raises(RuntimeError)
mocked_redis.stubs(:exists?).raises(RuntimeError)

assert_silent do
redis_adapter.is_experiment_completed?("price_options")
Expand Down

0 comments on commit bb6ae55

Please sign in to comment.