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 5e167ad
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
Original file line number Diff line number Diff line change
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 == true || exists > 0
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/adapters/redis_adapter_test.rb
Original file line number Diff line number Diff line change
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 5e167ad

Please sign in to comment.