Class: Redic
- Inherits:
-
Object
- Object
- Redic
- Defined in:
- lib/redic.rb,
lib/redic/client.rb
Defined Under Namespace
Classes: Client
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #buffer ⇒ Object
- #call(*args) ⇒ Object
- #call!(*args) ⇒ Object
- #clear ⇒ Object
- #commit ⇒ Object
- #configure(url, timeout = 10_000_000) ⇒ Object
-
#initialize(url = "redis://127.0.0.1:6379", timeout = 10_000_000) ⇒ Redic
constructor
A new instance of Redic.
- #queue(*args) ⇒ Object
- #quit ⇒ Object
- #reset ⇒ Object
- #timeout ⇒ Object
- #timeout=(timeout) ⇒ Object
Constructor Details
#initialize(url = "redis://127.0.0.1:6379", timeout = 10_000_000) ⇒ Redic
Returns a new instance of Redic.
8 9 10 11 12 |
# File 'lib/redic.rb', line 8 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 (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'lib/redic.rb', line 6 def client @client end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
5 6 7 |
# File 'lib/redic.rb', line 5 def url @url end |
Instance Method Details
#buffer ⇒ Object
14 15 16 |
# File 'lib/redic.rb', line 14 def buffer @buffer[Thread.current.object_id] end |
#call(*args) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/redic.rb', line 33 def call(*args) @client.connect do @client.write(args) @client.read end end |
#call!(*args) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/redic.rb', line 40 def call!(*args) reply = call(*args) if RuntimeError === reply raise reply end return reply end |
#clear ⇒ Object
22 23 24 |
# File 'lib/redic.rb', line 22 def clear @buffer.clear end |
#commit ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/redic.rb', line 54 def commit @client.connect do buffer.map do |args| @client.write(args) end end ensure reset end |
#configure(url, timeout = 10_000_000) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/redic.rb', line 26 def configure(url, timeout = 10_000_000) if @url != url @url = url @client.configure(url, timeout) end end |
#queue(*args) ⇒ Object
50 51 52 |
# File 'lib/redic.rb', line 50 def queue(*args) buffer << args end |
#quit ⇒ Object
72 73 74 |
# File 'lib/redic.rb', line 72 def quit @client.quit end |
#reset ⇒ Object
18 19 20 |
# File 'lib/redic.rb', line 18 def reset @buffer.delete(Thread.current.object_id) end |
#timeout ⇒ Object
64 65 66 |
# File 'lib/redic.rb', line 64 def timeout @client.timeout end |
#timeout=(timeout) ⇒ Object
68 69 70 |
# File 'lib/redic.rb', line 68 def timeout=(timeout) @client.timeout = timeout end |