class Redic

Attributes

client[R]
url[R]

Public Class Methods

new(url = "redis://127.0.0.1:6379", timeout = 10_000_000) click to toggle source
# File lib/redic.rb, line 7
def initialize(url = "redis://127.0.0.1:6379", timeout = 10_000_000)
  @url = url
  @client = Redic::Client.new(url, timeout)
  @buffer = Hash.new { |h, k| h[k] = [] }
end

Public Instance Methods

buffer() click to toggle source
# File lib/redic.rb, line 13
def buffer
  @buffer[Thread.current.object_id]
end
call(*args) click to toggle source
# File lib/redic.rb, line 32
def call(*args)
  @client.connect do
    @client.write(args)
    @client.read
  end
end
call!(*args) click to toggle source
# File lib/redic.rb, line 39
def call!(*args)
  reply = call(*args)

  if RuntimeError === reply
    raise reply
  end

  return reply
end
clear() click to toggle source
# File lib/redic.rb, line 21
def clear
  @buffer.clear
end
commit() click to toggle source
# File lib/redic.rb, line 53
def commit
  @client.connect do
    buffer.each do |args|
      @client.write(args)
    end

    buffer.map do
      @client.read
    end
  end
ensure
  reset
end
configure(url, timeout = 10_000_000) click to toggle source
# File lib/redic.rb, line 25
def configure(url, timeout = 10_000_000)
  if @url != url
    @url = url
    @client.configure(url, timeout)
  end
end
queue(*args) click to toggle source
# File lib/redic.rb, line 49
def queue(*args)
  buffer << args
end
quit() click to toggle source
# File lib/redic.rb, line 75
def quit
  @client.quit
end
reset() click to toggle source
# File lib/redic.rb, line 17
def reset
  @buffer.delete(Thread.current.object_id)
end
timeout() click to toggle source
# File lib/redic.rb, line 67
def timeout
  @client.timeout
end
timeout=(timeout) click to toggle source
# File lib/redic.rb, line 71
def timeout=(timeout)
  @client.timeout = timeout
end