Class: RedisPrescription
- Inherits:
-
Object
- Object
- RedisPrescription
- Defined in:
- lib/redis_prescription.rb,
lib/redis_prescription/errors.rb,
lib/redis_prescription/version.rb,
lib/redis_prescription/adapters.rb,
lib/redis_prescription/adapters/redis.rb,
lib/redis_prescription/adapters/redis_client.rb,
lib/redis_prescription/adapters/redis_namespace.rb
Overview
Lua script executor for redis.
Instead of executing script with ‘EVAL` everytime - loads script once and then runs it with `EVALSHA`.
Direct Known Subclasses
Defined Under Namespace
Modules: Adapters Classes: CommandError, Error, ScriptError
Constant Summary collapse
- VERSION =
Gem version.
"2.6.0"
Instance Attribute Summary collapse
-
#digest ⇒ String
readonly
Lua script SHA1 digest.
-
#source ⇒ String
readonly
Lua script source.
Instance Method Summary collapse
-
#call(redis, keys: EMPTY_LIST, argv: EMPTY_LIST) ⇒ Object
Executes script and return result of execution.
-
#initialize(source) ⇒ RedisPrescription
constructor
A new instance of RedisPrescription.
Constructor Details
#initialize(source) ⇒ RedisPrescription
Returns a new instance of RedisPrescription.
36 37 38 39 |
# File 'lib/redis_prescription.rb', line 36 def initialize(source) @source = -source.to_s @digest = Digest::SHA1.hexdigest(@source).freeze end |
Instance Attribute Details
#digest ⇒ String (readonly)
Lua script SHA1 digest.
33 34 35 |
# File 'lib/redis_prescription.rb', line 33 def digest @digest end |
#source ⇒ String (readonly)
Lua script source.
29 30 31 |
# File 'lib/redis_prescription.rb', line 29 def source @source end |
Instance Method Details
#call(redis, keys: EMPTY_LIST, argv: EMPTY_LIST) ⇒ Object
Executes script and return result of execution.
48 49 50 51 52 |
# File 'lib/redis_prescription.rb', line 48 def call(redis, keys: EMPTY_LIST, argv: EMPTY_LIST) evalsha_with_fallback(Adapters[redis], redis, keys, argv) rescue CommandError => e raise ScriptError.new(e., @source) end |