emb 0.2.0 → 0.2.1

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +23 -0
  3. data/lib/emb/client.rb +30 -9
  4. data/lib/emb.rb +2 -0
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: da3d0c2517e4def78e7d887bd480cf3db14d2c83ba66eff0853ddf075fc1b785
4
- data.tar.gz: 586bd53ce50bd1d1b427aaa82811676e193009155991dbe20f3496bf45816c7b
3
+ metadata.gz: 424790b9a9b835dd7febbdfa1df2e5f8b6a2a9b89290b5e653467fcc09e4f68f
4
+ data.tar.gz: d21f28bb4c79deaefa9bab91247f41ff5e84f869b422727939ab1f07a940eb34
5
5
  SHA512:
6
- metadata.gz: 55aebcfa8f1ccdeca346309bd91d20e8527988593d1e76a4996d002e692ff2bfabf04119e65fa360c05ec04c3b8fa39f34166b72f1e3651eba071b97f024fc16
7
- data.tar.gz: 2921b88b9cdb672f3ddcb54fba2ceb441772fc5791890487a30f17483abca57dd0a4e04f69534bdc0f33f5df1e20c0bb680394ef2a7822ddbe3164915914e82c
6
+ metadata.gz: eacbde1ca9ccf217bd53cb9028f8a5192427754abcee678373d38f16b08ce4ae00b5b905909cb0d7ef0f07fa04b39c0ad112c820c6f4fd6d3c98ba06708af854
7
+ data.tar.gz: 8605fe8eaede9567d6506f5247ef85dfcb32b9c1c1fa719d00ce2446233b0518cbd336e6f496c8449ac41ab33545776b05d1febe2bf3d5a576aafa47afa60d9c
data/README.md CHANGED
@@ -69,6 +69,29 @@ Manual authentication is also possible but not recommended for pooled connection
69
69
  Emb.send_command("AUTH", "hunter2") # only authenticates one connection
70
70
  ```
71
71
 
72
+ ### Redis client options
73
+
74
+ Any `RedisClient` option can be forwarded through `Emb.setup` or `Emb.new`:
75
+
76
+ ```ruby
77
+ Emb.setup(
78
+ url: "redis://localhost:6379",
79
+ pool: 10,
80
+ connect_timeout: 2,
81
+ read_timeout: 10,
82
+ write_timeout: 5,
83
+ reconnect_attempts: 5,
84
+ ssl: true,
85
+ ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_PEER },
86
+ driver: :hiredis,
87
+ inherit_socket: true
88
+ )
89
+ ```
90
+
91
+ See the [redis-client documentation](https://github.com/redis-rb/redis-client) for
92
+ all available options. Only `pool` is handled by the gem — everything else passes
93
+ through to `RedisClient.new`.
94
+
72
95
  ## Instance-based clients
73
96
 
74
97
  Create independent clients to connect to multiple servers or use different configurations:
data/lib/emb/client.rb CHANGED
@@ -9,17 +9,15 @@ module Emb
9
9
  class Client
10
10
  attr_reader :pool
11
11
 
12
- def initialize(url: nil, host: nil, port: nil, pool: DEFAULTS[:pool])
13
- url ||= ENV['EMB_URL']
14
- host ||= DEFAULTS[:host]
15
- port ||= DEFAULTS[:port]
12
+ def initialize(pool: DEFAULTS[:pool], **redis_options)
13
+ url = extract_url!(redis_options)
14
+ redis_options[:host] ||= DEFAULTS[:host] unless url
15
+ redis_options[:port] ||= DEFAULTS[:port] unless url
16
+ redis_options[:protocol] ||= 2
17
+ redis_options[:reconnect_attempts] ||= 3
16
18
 
17
19
  @pool = ConnectionPool.new(size: pool) do
18
- if url
19
- RedisClient.new(url: url, protocol: 2, reconnect_attempts: 3)
20
- else
21
- RedisClient.new(host: host, port: port, protocol: 2, reconnect_attempts: 3)
22
- end
20
+ RedisClient.new(url: url, **redis_options)
23
21
  end
24
22
 
25
23
  @registry = {}
@@ -65,6 +63,22 @@ module Emb
65
63
 
66
64
  def ping = send_command('PING')
67
65
 
66
+ def ready
67
+ send_command('EMB.READY')
68
+
69
+ "ready"
70
+ rescue RedisClient::CommandError => e
71
+ e.message
72
+ end
73
+
74
+ def ready?
75
+ ready
76
+
77
+ true
78
+ rescue RedisClient::CommandError
79
+ false
80
+ end
81
+
68
82
  def reset_registry!
69
83
  @registry = {}
70
84
  end
@@ -74,5 +88,12 @@ module Emb
74
88
  yield mp
75
89
  mp.run
76
90
  end
91
+
92
+ private
93
+
94
+ def extract_url!(opts)
95
+ url = opts.delete(:url)
96
+ url.nil? ? ENV.fetch('EMB_URL', nil) : url
97
+ end
77
98
  end
78
99
  end
data/lib/emb.rb CHANGED
@@ -21,6 +21,8 @@ module Emb
21
21
  def stats = default_client.stats
22
22
  def help = default_client.help
23
23
  def ping = default_client.ping
24
+ def ready = default_client.ready
25
+ def ready? = default_client.ready?
24
26
  def multi(&) = default_client.multi(&)
25
27
  def reset_registry! = default_client.reset_registry!
26
28
  def debug? = @debug
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - elcuervo