class Brpoplpush::RedisScript::Script
Interface to dealing with .lua files
@author Mikael Henriksson <mikael@mhenrixon.com>
Attributes
call_count[R]
@!attribute [rw] call_count
@return [Integer] the number of times the script was called/executed
name[R]
@!attribute [r] script_name
@return [Symbol, String] the name of the script without extension
path[R]
@!attribute [r] script_path
@return [String] the path to the script on disk
root_path[R]
@!attribute [r] root_path
@return [Pathname]
sha[R]
@!attribute [rw] sha
@return [String] the sha of the script
source[R]
@!attribute [r] source
@return [String] the source code of the lua script
Public Class Methods
load(name, root_path, conn)
click to toggle source
# File lib/brpoplpush/redis_script/script.rb, line 9 def self.load(name, root_path, conn) script = new(name: name, root_path: root_path) script.load(conn) end
new(name:, root_path:)
click to toggle source
# File lib/brpoplpush/redis_script/script.rb, line 39 def initialize(name:, root_path:) @name = name @root_path = root_path @path = root_path.join("#{name}.lua").to_s @source = render_file @sha = compiled_sha @call_count = 0 end
Public Instance Methods
==(other)
click to toggle source
# File lib/brpoplpush/redis_script/script.rb, line 48 def ==(other) sha == compiled_sha && compiled_sha == other.sha end
changed?()
click to toggle source
# File lib/brpoplpush/redis_script/script.rb, line 56 def changed? compiled_sha != sha end
compiled_sha()
click to toggle source
# File lib/brpoplpush/redis_script/script.rb, line 64 def compiled_sha Digest::SHA1.hexdigest(source) end
increment_call_count()
click to toggle source
# File lib/brpoplpush/redis_script/script.rb, line 52 def increment_call_count @call_count += 1 end
load(conn)
click to toggle source
# File lib/brpoplpush/redis_script/script.rb, line 68 def load(conn) @sha = if conn.respond_to?(:namespace) conn.redis.script(:load, source) else conn.script(:load, source) end self end
render_file()
click to toggle source
# File lib/brpoplpush/redis_script/script.rb, line 60 def render_file Template.new(root_path).render(path) end