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") ⇒ Redic

Returns a new instance of Redic.



6
7
8
9
10
# File 'lib/redic.rb', line 6

def initialize(url = "redis://127.0.0.1:6379")
  @url = url
  @client = Redic::Client.new(url)
  @buffer = []
end

Instance Attribute Details

#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



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

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

#runObject



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

def run
  @client.connect do
    @buffer.each do |args|
      @client.write(args)
    end

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

#write(*args) ⇒ Object



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

def write(*args)
  @buffer << args
end