Class: Stoplight::Infrastructure::Redis::DataStore::Scripting
- Inherits:
-
Object
- Object
- Stoplight::Infrastructure::Redis::DataStore::Scripting
- Defined in:
- lib/stoplight/infrastructure/redis/data_store/scripting.rb
Overview
Note:
Scripts are loaded lazily on first use and cached in memory
Note:
Script files must be named ‘<script_name>.lua` and located in scripts_root
Manages Lua scripts for Redis operations.
This class provides execution of Lua scripts by caching their SHA digests and automatically reloading scripts if they’re evicted from Redis memory.
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
- #call(script_name, keys: [], args: []) ⇒ Object
-
#initialize(redis:, scripts_root: self.class.default_scripts_root) ⇒ Scripting
constructor
A new instance of Scripting.
Constructor Details
#initialize(redis:, scripts_root: self.class.default_scripts_root) ⇒ Scripting
Returns a new instance of Scripting.
27 28 29 30 31 |
# File 'lib/stoplight/infrastructure/redis/data_store/scripting.rb', line 27 def initialize(redis:, scripts_root: self.class.default_scripts_root) @scripts_root = scripts_root @redis = redis @shas = {} end |
Class Method Details
.default_scripts_root ⇒ Object
24 |
# File 'lib/stoplight/infrastructure/redis/data_store/scripting.rb', line 24 def default_scripts_root = SCRIPTS_ROOT |
Instance Method Details
#call(script_name, keys: [], args: []) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/stoplight/infrastructure/redis/data_store/scripting.rb', line 33 def call(script_name, keys: [], args: []) redis.then do |client| client.evalsha(script_sha(script_name), keys: keys.map(&:to_s), argv: args.map(&:to_s)) end rescue ::Redis::CommandError => error if error..include?("NOSCRIPT") reload_script(script_name) retry else raise end end |