Class: Redic

Inherits:
Object
  • Object
show all
Defined in:
lib/redic.rb,
lib/redic/client.rb,
lib/redic/connection.rb

Defined Under Namespace

Modules: Connection Classes: Client

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url = "redis://127.0.0.1:6379", timeout = 10_000_000) ⇒ Redic

Returns a new instance of Redic.


7
8
9
10
11
# 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)
  @queue = []
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client


5
6
7
# File 'lib/redic.rb', line 5

def client
  @client
end

#urlObject (readonly)

Returns the value of attribute url


4
5
6
# File 'lib/redic.rb', line 4

def url
  @url
end

Instance Method Details

#call(*args) ⇒ Object


13
14
15
16
17
18
# File 'lib/redic.rb', line 13

def call(*args)
  @client.connect do
    @client.write(args)
    @client.read
  end
end

#commitObject


24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/redic.rb', line 24

def commit
  @client.connect do
    @queue.each do |args|
      @client.write(args)
    end

    @queue.map do
      @client.read
    end
  end
ensure
  @queue.clear
end

#queue(*args) ⇒ Object


20
21
22
# File 'lib/redic.rb', line 20

def queue(*args)
  @queue << args
end

#timeoutObject


38
39
40
# File 'lib/redic.rb', line 38

def timeout
  @client.timeout
end