Class: Redic
- Inherits:
-
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)
@buffer = Hash.new { |h, k| h[k] = [] }
end
|
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
5
6
7
|
# File 'lib/redic.rb', line 5
def client
@client
end
|
#url ⇒ Object
Returns the value of attribute url.
4
5
6
|
# File 'lib/redic.rb', line 4
def url
@url
end
|
Instance Method Details
#buffer ⇒ Object
13
14
15
|
# File 'lib/redic.rb', line 13
def buffer
@buffer[Thread.current.object_id]
end
|
#call(*args) ⇒ Object
32
33
34
35
36
37
|
# File 'lib/redic.rb', line 32
def call(*args)
@client.connect do
@client.write(args)
@client.read
end
end
|
#call!(*args) ⇒ Object
39
40
41
42
43
44
45
46
47
|
# File 'lib/redic.rb', line 39
def call!(*args)
reply = call(*args)
if RuntimeError === reply
raise reply
end
return reply
end
|
#clear ⇒ Object
21
22
23
|
# File 'lib/redic.rb', line 21
def clear
@buffer.clear
end
|
#commit ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# 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
|
25
26
27
28
29
30
|
# 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) ⇒ Object
49
50
51
|
# File 'lib/redic.rb', line 49
def queue(*args)
buffer << args
end
|
#quit ⇒ Object
75
76
77
|
# File 'lib/redic.rb', line 75
def quit
@client.quit
end
|
#reset ⇒ Object
17
18
19
|
# File 'lib/redic.rb', line 17
def reset
@buffer.delete(Thread.current.object_id)
end
|
#timeout ⇒ Object
67
68
69
|
# File 'lib/redic.rb', line 67
def timeout
@client.timeout
end
|
#timeout=(timeout) ⇒ Object
71
72
73
|
# File 'lib/redic.rb', line 71
def timeout=(timeout)
@client.timeout = timeout
end
|