Class: Restruct::Connection
- Inherits:
-
Object
- Object
- Restruct::Connection
- Defined in:
- lib/restruct/connection.rb
Instance Method Summary collapse
- #batch ⇒ Object
- #call(*args) ⇒ Object
- #clone ⇒ Object
-
#initialize(*args) ⇒ Connection
constructor
A new instance of Connection.
- #lazy(*args) ⇒ Object
- #read ⇒ Object
- #script(lua_src, *args) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Connection
4 5 6 7 8 9 |
# File 'lib/restruct/connection.rb', line 4 def initialize(*args) @args = args @redis = Redic.new *args @scripts = {} @nesting = ::Hash.new { |h,k| h[k] = 0 } end |
Instance Method Details
#batch ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/restruct/connection.rb', line 35 def batch incr_nesting begin result = yield ensure decr_nesting end commit unless nested? rescue => ex redis.clear unless nested? raise ex end |
#call(*args) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/restruct/connection.rb', line 11 def call(*args) raise ArgumentError if args.empty? redis.call! *args rescue RuntimeError => ex raise ConnectionErrorFactory.create(ex) end |
#clone ⇒ Object
52 53 54 |
# File 'lib/restruct/connection.rb', line 52 def clone Connection.new *@args end |
#lazy(*args) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/restruct/connection.rb', line 18 def lazy(*args) if nested? redis.queue *args nil else call *args end end |
#read ⇒ Object
48 49 50 |
# File 'lib/restruct/connection.rb', line 48 def read redis.client.read end |
#script(lua_src, *args) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/restruct/connection.rb', line 27 def script(lua_src, *args) scripts[lua_src] ||= call 'SCRIPT', 'LOAD', lua_src call 'EVALSHA', scripts[lua_src], *args rescue NoScriptError scripts.delete lua_src retry end |