bigrails-redis 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -4
- data/lib/big_rails/redis/registry.rb +29 -18
- data/lib/big_rails/redis/version.rb +1 -1
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4fad4c4ad81fa365e20f3d168ea4ddd8043b121d88e7d46ccc875e139e7049c
|
4
|
+
data.tar.gz: ac86f0f454a81a3b040562c98dc74036c0b96f714b501dfd65a8df224870071f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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)
|
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
|
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
|
@@ -1,13 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "redis"
|
4
|
-
|
5
3
|
module BigRails
|
6
4
|
module Redis
|
7
5
|
class Registry
|
8
6
|
class UnknownConnection < StandardError
|
9
7
|
end
|
10
8
|
|
9
|
+
class VerificationError < StandardError
|
10
|
+
end
|
11
|
+
|
11
12
|
attr_accessor :builder
|
12
13
|
|
13
14
|
def initialize
|
@@ -38,11 +39,29 @@ module BigRails
|
|
38
39
|
configurations.keys.map { |name| self.for(name) }.each(&block)
|
39
40
|
end
|
40
41
|
|
41
|
-
def
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
46
65
|
end
|
47
66
|
|
48
67
|
true
|
@@ -61,18 +80,10 @@ module BigRails
|
|
61
80
|
end
|
62
81
|
|
63
82
|
def build_wrapped_connection(connection)
|
64
|
-
if connection.is_a?(::
|
65
|
-
connection
|
66
|
-
else
|
83
|
+
if connection.is_a?(::ConnectionPool)
|
67
84
|
::ConnectionPool.wrap(pool: connection)
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
def verify_connection(connection)
|
72
|
-
connection.with do |conn|
|
73
|
-
connected = conn.connected?
|
74
|
-
conn.ping
|
75
|
-
conn.quit unless connected
|
85
|
+
else
|
86
|
+
connection
|
76
87
|
end
|
77
88
|
end
|
78
89
|
|
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.
|
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-
|
11
|
+
date: 2022-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '6'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: redis
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '4.0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '4.0'
|
41
27
|
description:
|
42
28
|
email:
|
43
29
|
- ngan@users.noreply.github.com
|