Skip to content

Commit

Permalink
Deal with error message format change in redis 5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
tobischo committed Mar 29, 2024
1 parent d3a55a9 commit eb64959
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/gcra/redis_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ class RedisStore

# Digest::SHA1.hexdigest(CAS_SCRIPT)
CAS_SHA = "89118e702230c0d65969c5fc557a6e942a2f4d31".freeze
CAS_SCRIPT_MISSING_KEY_RESPONSE = 'key does not exist'.freeze
SCRIPT_NOT_IN_CACHE_RESPONSE = 'NOSCRIPT No matching script. Please use EVAL.'.freeze
CAS_SCRIPT_MISSING_KEY_RESPONSE_PATTERN = Regexp.new('^key does not exist')
SCRIPT_NOT_IN_CACHE_RESPONSE_PATTERN = Regexp.new(
'^NOSCRIPT No matching script. Please use EVAL.',
)

def initialize(redis, key_prefix, options = {})
@redis = redis
Expand Down Expand Up @@ -76,9 +78,9 @@ def compare_and_set_with_ttl(key, old_value, new_value, ttl_nano)
end
raise
rescue Redis::CommandError => e
if e.message == CAS_SCRIPT_MISSING_KEY_RESPONSE
if e.message =~ CAS_SCRIPT_MISSING_KEY_RESPONSE_PATTERN
return false
elsif e.message == SCRIPT_NOT_IN_CACHE_RESPONSE && !retried
elsif e.message =~ SCRIPT_NOT_IN_CACHE_RESPONSE_PATTERN && !retried
@redis.script('load', CAS_SCRIPT)
retried = true
retry
Expand Down

0 comments on commit eb64959

Please sign in to comment.