Module: Redlics
- Extended by:
- Redlics
- Included in:
- Redlics
- Defined in:
- lib/redlics.rb,
lib/redlics/key.rb,
lib/redlics/query.rb,
lib/redlics/config.rb,
lib/redlics/counter.rb,
lib/redlics/tracker.rb,
lib/redlics/version.rb,
lib/redlics/exception.rb,
lib/redlics/operators.rb,
lib/redlics/connection.rb,
lib/redlics/time_frame.rb,
lib/redlics/granularity.rb,
lib/redlics/query/operation.rb
Overview
Redlics version.
Defined Under Namespace
Modules: Connection, Counter, Exception, Granularity, Key, Operators, Tracker Classes: Config, Query, TimeFrame
Constant Summary collapse
- LUA_CACHE =
Redlics constants.
Hash.new { |h, k| h[k] = Hash.new }
- LUA_SCRIPT =
File.('../lua/script.lua', __FILE__).freeze
- CONTEXTS =
{ counter: { short: :c, long: :counter }, tracker: { short: :t, long: :tracker }, operation: { short: :o, long: :operation } }.freeze
- VERSION =
'0.2.2'
Instance Method Summary collapse
-
#config ⇒ OpenStruct
Get or initialize Redlics config.
-
#configure {|config| ... } ⇒ OpenStruct
Set configuration of Redlics in a block.
-
#redis ⇒ Object
Get or initialize the Redis connection.
-
#script(file, *args) ⇒ String
Load Lua script file and arguments in Redis.
Instance Method Details
#config ⇒ OpenStruct
Get or initialize Redlics config.
75 76 77 |
# File 'lib/redlics.rb', line 75 def config @config ||= Redlics::Config.new end |
#configure {|config| ... } ⇒ OpenStruct
Set configuration of Redlics in a block.
81 82 83 |
# File 'lib/redlics.rb', line 81 def configure yield config if block_given? end |
#redis ⇒ Object
Get or initialize the Redis connection.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/redlics.rb', line 31 def redis raise ArgumentError, 'requires a block' unless block_given? redis_pool.with do |conn| retryable = true begin yield conn rescue Redis::BaseError => e raise e unless config.silent rescue Redis::CommandError => ex (conn.disconnect!; retryable = false; retry) if retryable && ex. =~ /READONLY/ raise unless config.silent end end end |
#script(file, *args) ⇒ String
Load Lua script file and arguments in Redis.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/redlics.rb', line 51 def script(file, *args) begin cache = LUA_CACHE[redis { |r| r.client.[:url] }] if cache.key?(file) sha = cache[file] else src = File.read(file) sha = redis { |r| r.redis.script(:load, src) } cache[file] = sha end redis { |r| r.evalsha(sha, *args) } rescue RuntimeError case $!. when Exception::ErrorPatterns::NOSCRIPT LUA_CACHE[redis { |r| r.client.[:url] }].clear retry else raise $! unless config.silent end end end |