2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-07 12:02:53 +08:00

DEV: Consolidate Redis evalsha logic into DiscourseRedis::EvalHelper (#15957)

This commit is contained in:
David Taylor 2022-02-15 16:06:12 +00:00 committed by GitHub
parent dd5373cc4c
commit 11c93342dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 79 additions and 49 deletions

View file

@ -161,4 +161,20 @@ class DiscourseRedis
key[(namespace.length + 1)..-1]
end
class EvalHelper
def initialize(script)
@script = script
@sha1 = Digest::SHA1.hexdigest(script)
end
def eval(redis, *args, **kwargs)
redis.evalsha @sha1, *args, **kwargs
rescue ::Redis::CommandError => e
if e.to_s =~ /^NOSCRIPT/
redis.eval @script, *args, **kwargs
else
raise
end
end
end
end