threadsafe-hiredis 0.5.7 → 0.5.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/hiredis/version.rb +1 -1
- data/lib/threadsafe_connection_driver.rb +63 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71bd5bde3b2f1f10fcd5fabf26c39ea32e5f76e9
|
4
|
+
data.tar.gz: 40f92c27e7e809b185bd708519997bd5ec860391
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 980a0dda2b7ec7b36f7c0c7cabdb41221f993be09e1bb40ef131e9de36bc1c9ef504a60f7d16657921492ffaff92ab04358b34860d78a2677680c457a6317e4f
|
7
|
+
data.tar.gz: 309541fe522438b0375a953bd79ad0cf68b14f809a47205cc043ab14e67a236af5a013e69f47ecae453bb9ed606a1d802d004205888d18ea91286052d57f02f8
|
data/lib/hiredis/version.rb
CHANGED
@@ -0,0 +1,63 @@
|
|
1
|
+
require "redis/connection/registry"
|
2
|
+
require "redis/errors"
|
3
|
+
require "hiredis/connection"
|
4
|
+
require "timeout"
|
5
|
+
|
6
|
+
class Redis
|
7
|
+
module Connection
|
8
|
+
class ThreadsafeHiredis
|
9
|
+
|
10
|
+
def self.connect(config)
|
11
|
+
connection = ::Hiredis::ThreadSafeConnection.new
|
12
|
+
|
13
|
+
if config[:scheme] == "unix"
|
14
|
+
connection.connect_unix(config[:path], Integer(config[:timeout] * 1_000_000))
|
15
|
+
else
|
16
|
+
connection.connect(config[:host], config[:port], Integer(config[:timeout] * 1_000_000))
|
17
|
+
end
|
18
|
+
|
19
|
+
instance = new(connection)
|
20
|
+
instance.timeout = config[:timeout]
|
21
|
+
instance
|
22
|
+
rescue Errno::ETIMEDOUT
|
23
|
+
raise TimeoutError
|
24
|
+
end
|
25
|
+
|
26
|
+
def initialize(connection)
|
27
|
+
@connection = connection
|
28
|
+
end
|
29
|
+
|
30
|
+
def connected?
|
31
|
+
@connection && @connection.connected?
|
32
|
+
end
|
33
|
+
|
34
|
+
def timeout=(timeout)
|
35
|
+
# Hiredis works with microsecond timeouts
|
36
|
+
@connection.timeout = Integer(timeout * 1_000_000)
|
37
|
+
end
|
38
|
+
|
39
|
+
def disconnect
|
40
|
+
@connection.disconnect
|
41
|
+
@connection = nil
|
42
|
+
end
|
43
|
+
|
44
|
+
def write(command)
|
45
|
+
@connection.write(command.flatten(1))
|
46
|
+
rescue Errno::EAGAIN
|
47
|
+
raise TimeoutError
|
48
|
+
end
|
49
|
+
|
50
|
+
def read
|
51
|
+
reply = @connection.read
|
52
|
+
reply = CommandError.new(reply.message) if reply.is_a?(RuntimeError)
|
53
|
+
reply
|
54
|
+
rescue Errno::EAGAIN
|
55
|
+
raise TimeoutError
|
56
|
+
rescue RuntimeError => err
|
57
|
+
raise ProtocolError.new(err.message)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
Redis::Connection.drivers << Redis::Connection::ThreadsafeHiredis
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: threadsafe-hiredis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pieter Noordhuis
|
@@ -66,6 +66,7 @@ files:
|
|
66
66
|
- lib/hiredis/ruby/reader.rb
|
67
67
|
- lib/hiredis/thread_safe_connection.rb
|
68
68
|
- lib/hiredis/version.rb
|
69
|
+
- lib/threadsafe_connection_driver.rb
|
69
70
|
- vendor/hiredis/COPYING
|
70
71
|
- vendor/hiredis/Makefile
|
71
72
|
- vendor/hiredis/async.c
|