bigrails-redis 0.1.0 → 0.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a759e01aab33407d58cedf4e5920130bc302fb72bdf1f31d9946a6315bade497
4
- data.tar.gz: bce916691075cb892b279bc14aa152ffd4dd436470d4204199f19f0b9d0c18ba
3
+ metadata.gz: c4fad4c4ad81fa365e20f3d168ea4ddd8043b121d88e7d46ccc875e139e7049c
4
+ data.tar.gz: ac86f0f454a81a3b040562c98dc74036c0b96f714b501dfd65a8df224870071f
5
5
  SHA512:
6
- metadata.gz: 5f9d4a1d5c7d237ecd5ef4dfafc4dcb60a000a417992fc133097b96858b0c092e8707584757c5f6d42b7d204431b2dace0857013e9e19299d7e56da8b72d5916
7
- data.tar.gz: 67b9273fbbcc1f4ccbcd1883499c6acf841ef02aa477b742cbc03e4ac19e358f9859c61e5cfcf7bf4a0cb356ce20b4209bf26799759dea11eef44829d8fd5d1f
6
+ metadata.gz: d130159d4ae34ac9c432dd554a7222fe0f2eb118f71ae1c6bc427a29cab4a1e5ed5b7f83c0410fe99a8977e685105567fba5387b9f04a8ac45ee67f6228a75b5
7
+ data.tar.gz: fe6b41f256a94205d9913a8faa00234b9ab105ce520875b3bccc6929274081788158da37a128efa0d91a38cba307c661a9e357d0fe7a8d596244db77c4d51799
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # BigRails::Redis [![Ruby](https://github.com/BigRails/bigrails-redis/actions/workflows/main.yml/badge.svg)](https://github.com/BigRails/bigrails-redis/actions/workflows/main.yml)
2
2
 
3
- A simple Redis connection manager for Rails applications with distributed and [ConnectionPool](https://github.com/mperham/connection_pool) support.
3
+ A simple Redis connection manager for Rails applications with the need to manage multiple redis connections. It supports distributed and [ConnectionPool](https://github.com/mperham/connection_pool) out of the box.
4
4
 
5
5
  ## Installation
6
6
 
@@ -89,14 +89,22 @@ If you request a wrapped connection for a non-pooled connection, it'll just retu
89
89
 
90
90
  ### Verifying Connections
91
91
 
92
- This library also allows you to verify connections on demand. If you want, perform the verification in a startup health check to make sure all your connections are valid. It will perform a simple [`PING` command](https://redis.io/commands/PING). An error will be raised if the connection bad.
92
+ This library also allows you to verify connections on demand. If you want, perform the verification in a startup health check to make sure all your connections are valid. It will perform a simple [`PING` command](https://redis.io/commands/PING) and clsoe the connection if it was originally closed. This is to help reduce the number of connections you actually need open. An error will be raised if the connection is bad.
93
93
 
94
94
  ```ruby
95
95
  # Verify all connections:
96
96
  Rails.application.redis.verify!
97
97
 
98
- # Verify a single connection:
99
- Rails.application.redis.verify!(:foobar)
98
+ # Verify specific connections:
99
+ Rails.application.redis.verify!(:foobar, :sidekiq)
100
+ ```
101
+
102
+ ### Disconnect Connections
103
+
104
+ You can disconnect all connections with a single call. This is useful for "before fork" hooks.
105
+
106
+ ```ruby
107
+ Rails.application.redis.disconnect
100
108
  ```
101
109
 
102
110
  ## Development
@@ -6,6 +6,9 @@ module BigRails
6
6
  class UnknownConnection < StandardError
7
7
  end
8
8
 
9
+ class VerificationError < StandardError
10
+ end
11
+
9
12
  attr_accessor :builder
10
13
 
11
14
  def initialize
@@ -33,14 +36,32 @@ module BigRails
33
36
  end
34
37
 
35
38
  def each(&block)
36
- configurations.keys.map { self.for(name) }.each(&block)
39
+ configurations.keys.map { |name| self.for(name) }.each(&block)
37
40
  end
38
41
 
39
- def verify!(name = nil)
40
- if name
41
- verify_connection(self.for(name))
42
- else
43
- each { |connection| verify_connection(connection) }
42
+ def disconnect
43
+ each do |connection|
44
+ if connection.is_a?(::ConnectionPool)
45
+ connection.reload { |conn| conn.quit }
46
+ else
47
+ connection.quit
48
+ end
49
+ end
50
+ end
51
+
52
+ def verify!(*names)
53
+ names.map! { |name| validate_name(name) }
54
+ names = configurations.keys if names.empty?
55
+ names.each do |name|
56
+ self.for(name).with do |connection|
57
+ next if connection.connected?
58
+
59
+ begin
60
+ connection.quit
61
+ rescue
62
+ raise VerificationError, "verification for '#{name}' failed"
63
+ end
64
+ end
44
65
  end
45
66
 
46
67
  true
@@ -59,16 +80,10 @@ module BigRails
59
80
  end
60
81
 
61
82
  def build_wrapped_connection(connection)
62
- if connection.is_a?(::Redis)
63
- connection
64
- else
83
+ if connection.is_a?(::ConnectionPool)
65
84
  ::ConnectionPool.wrap(pool: connection)
66
- end
67
- end
68
-
69
- def verify_connection(connection)
70
- connection.with do |redis|
71
- redis.ping == "PONG"
85
+ else
86
+ connection
72
87
  end
73
88
  end
74
89
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module BigRails
4
4
  module Redis
5
- VERSION = "0.1.0"
5
+ VERSION = "0.4.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bigrails-redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ngan Pham
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-18 00:00:00.000000000 Z
11
+ date: 2022-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails