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:
parent
dd5373cc4c
commit
11c93342dc
5 changed files with 79 additions and 49 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue