lib/redis_eval/script.rb in redis_eval-0.2.0 vs lib/redis_eval/script.rb in redis_eval-0.2.1
- old
+ new
@@ -2,12 +2,13 @@
class Script
attr_accessor :parent
attr_reader :source, :sha
def self.build_from_parent(src, parent, with_load: true)
- script = new(src, with_load: with_load)
+ script = new(src, with_load: false)
script.parent = parent
+ script.load if with_load
script
end
def initialize(src, with_load: true)
@source = src
@@ -15,15 +16,15 @@
@redis = nil
self.load if with_load
end
def load
- redis.script(:load, source)
+ redis_without_namespace.script(:load, source)
end
def exist?
- redis.script(:exists, sha)
+ redis_without_namespace.script(:exists, sha)
end
def execute(keys = [], argv = [])
redis.evalsha(sha, Array(keys), Array(argv))
rescue Redis::CommandError => e
@@ -40,7 +41,13 @@
end
def redis=(conn)
@redis = conn
end
+
+ private
+
+ def redis_without_namespace
+ defined?(Redis::Namespace) && redis.is_a?(Redis::Namespace) ? redis.redis : redis
+ end
end
end