threadsafe-hiredis 0.5.7 → 0.5.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7dd904f006ffd47a3bfea2ebb472e5f538b8e3d6
4
- data.tar.gz: 0ca92a6fa641d13207ded75ae5fd74d98f433bbc
3
+ metadata.gz: 71bd5bde3b2f1f10fcd5fabf26c39ea32e5f76e9
4
+ data.tar.gz: 40f92c27e7e809b185bd708519997bd5ec860391
5
5
  SHA512:
6
- metadata.gz: 4ec5a8cce6ebb314c0570b8adfc21ca05fb7cd3f87736495a6b834a5f5bb4b18545db5319d260869353db200a66f679f584e14e33e0698646c88ae38390b6f06
7
- data.tar.gz: cb7724e830a918329f5e92006e825e37238670a5685ed12724782933b6bdb8fd0bd8f58808230e0ba8494c94f24356e5b6c14b4da8ca9e3482de296d4632eced
6
+ metadata.gz: 980a0dda2b7ec7b36f7c0c7cabdb41221f993be09e1bb40ef131e9de36bc1c9ef504a60f7d16657921492ffaff92ab04358b34860d78a2677680c457a6317e4f
7
+ data.tar.gz: 309541fe522438b0375a953bd79ad0cf68b14f809a47205cc043ab14e67a236af5a013e69f47ecae453bb9ed606a1d802d004205888d18ea91286052d57f02f8
@@ -1,3 +1,3 @@
1
1
  module Hiredis
2
- VERSION = "0.5.7"
2
+ VERSION = "0.5.8"
3
3
  end
@@ -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.7
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