modis 4.2.0 → 4.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +2 -1
- data/.github_changelog_generator +1 -1
- data/CHANGELOG.md +23 -2
- data/Gemfile.lock +9 -9
- data/lib/modis/configuration.rb +3 -3
- data/lib/modis/deprecator.rb +7 -0
- data/lib/modis/finder.rb +2 -2
- data/lib/modis/index.rb +1 -1
- data/lib/modis/model.rb +2 -0
- data/lib/modis/persistence.rb +4 -4
- data/lib/modis/transaction.rb +1 -1
- data/lib/modis/version.rb +1 -1
- data/lib/modis.rb +44 -12
- data/spec/multi_redis_spec.rb +56 -0
- data/spec/spec_helper.rb +4 -7
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4490e45322b9ae24bb78a01190616971ff18fd0ee14030493a2cb76f1496d8ac
|
4
|
+
data.tar.gz: 135acda908b954b448aff439a4fd6663f06297da29b7bc8ce936c2f153696e05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 656b9746bb1381ae3eee2cec837e3a1adebcd505eea7cb3289f660d8bfa17371e4defabb567898000b4e1a5a49775205deff1081a00299422e125360a3a186b2
|
7
|
+
data.tar.gz: 49c2d453ca3079306ee51fc9d97bda1330d10871a205a57b22ca70260dc746b8d8c589fc66750bb09b8af7aa6421faf8fa1e3fb79ae2035411c32033fd328bb3
|
data/.github/workflows/test.yml
CHANGED
@@ -26,6 +26,7 @@ jobs:
|
|
26
26
|
- 6379:6379
|
27
27
|
|
28
28
|
strategy:
|
29
|
+
fail-fast: false
|
29
30
|
matrix:
|
30
31
|
gemfile: ['rails_5.2', 'rails_6.0', 'rails_6.1', 'rails_7.0']
|
31
32
|
|
@@ -55,7 +56,7 @@ jobs:
|
|
55
56
|
BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
|
56
57
|
|
57
58
|
steps:
|
58
|
-
- uses: actions/checkout@
|
59
|
+
- uses: actions/checkout@v4
|
59
60
|
|
60
61
|
- name: Set up Ruby
|
61
62
|
uses: ruby/setup-ruby@v1
|
data/.github_changelog_generator
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,29 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
## [v4.1
|
3
|
+
## [v4.3.1](https://github.com/rpush/modis/tree/v4.3.1) (2024-08-01)
|
4
4
|
|
5
|
-
[Full Changelog](https://github.com/rpush/modis/compare/v4.
|
5
|
+
[Full Changelog](https://github.com/rpush/modis/compare/v4.3.0...v4.3.1)
|
6
|
+
|
7
|
+
**Closed issues:**
|
8
|
+
|
9
|
+
- Release 4.3.0 breaks the Rpush initialization [\#50](https://github.com/rpush/modis/issues/50)
|
10
|
+
|
11
|
+
**Merged pull requests:**
|
12
|
+
|
13
|
+
- Restore backwards compatibility broken in 4.3.0 [\#51](https://github.com/rpush/modis/pull/51) ([benlangfeld](https://github.com/benlangfeld))
|
14
|
+
|
15
|
+
## [v4.3.0](https://github.com/rpush/modis/tree/v4.3.0) (2024-07-31)
|
16
|
+
|
17
|
+
[Full Changelog](https://github.com/rpush/modis/compare/v4.2.0...v4.3.0)
|
18
|
+
|
19
|
+
**Merged pull requests:**
|
20
|
+
|
21
|
+
- Add support for multiple redis connections [\#49](https://github.com/rpush/modis/pull/49) ([SxDx](https://github.com/SxDx))
|
22
|
+
- Fix deprecation warning [\#48](https://github.com/rpush/modis/pull/48) ([SxDx](https://github.com/SxDx))
|
23
|
+
|
24
|
+
## [v4.2.0](https://github.com/rpush/modis/tree/v4.2.0) (2023-08-01)
|
25
|
+
|
26
|
+
[Full Changelog](https://github.com/rpush/modis/compare/v4.1.0...v4.2.0)
|
6
27
|
|
7
28
|
**Merged pull requests:**
|
8
29
|
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
modis (4.
|
4
|
+
modis (4.3.1)
|
5
5
|
activemodel (>= 5.2)
|
6
6
|
activesupport (>= 5.2)
|
7
7
|
connection_pool (>= 2)
|
@@ -48,8 +48,8 @@ GEM
|
|
48
48
|
parallel
|
49
49
|
codeclimate-test-reporter (1.0.7)
|
50
50
|
simplecov
|
51
|
-
concurrent-ruby (1.2.
|
52
|
-
connection_pool (2.
|
51
|
+
concurrent-ruby (1.2.2)
|
52
|
+
connection_pool (2.4.1)
|
53
53
|
console (1.16.2)
|
54
54
|
fiber-local
|
55
55
|
diff-lcs (1.4.4)
|
@@ -71,12 +71,12 @@ GEM
|
|
71
71
|
rainbow (>= 2.2.1)
|
72
72
|
rake (>= 10.0)
|
73
73
|
hiredis (0.6.3)
|
74
|
-
i18n (1.
|
74
|
+
i18n (1.14.1)
|
75
75
|
concurrent-ruby (~> 1.0)
|
76
76
|
io-event (1.1.6)
|
77
77
|
jaro_winkler (1.5.4)
|
78
|
-
minitest (5.
|
79
|
-
msgpack (1.
|
78
|
+
minitest (5.19.0)
|
79
|
+
msgpack (1.7.2)
|
80
80
|
multi_json (1.15.0)
|
81
81
|
octokit (4.25.1)
|
82
82
|
faraday (>= 1, < 3)
|
@@ -94,9 +94,9 @@ GEM
|
|
94
94
|
public_suffix (5.0.1)
|
95
95
|
rainbow (3.0.0)
|
96
96
|
rake (13.0.1)
|
97
|
-
redis (5.0
|
98
|
-
redis-client (>= 0.
|
99
|
-
redis-client (0.
|
97
|
+
redis (5.2.0)
|
98
|
+
redis-client (>= 0.22.0)
|
99
|
+
redis-client (0.22.2)
|
100
100
|
connection_pool
|
101
101
|
rexml (3.2.5)
|
102
102
|
rspec (3.9.0)
|
data/lib/modis/configuration.rb
CHANGED
data/lib/modis/finder.rb
CHANGED
@@ -18,7 +18,7 @@ module Modis
|
|
18
18
|
"because you disabled all index. See :enable_all_index for more."
|
19
19
|
end
|
20
20
|
|
21
|
-
records = Modis.with_connection do |redis|
|
21
|
+
records = Modis.with_connection(modis_connection) do |redis|
|
22
22
|
ids = redis.smembers(key_for(:all))
|
23
23
|
redis.pipelined do |pipeline|
|
24
24
|
ids.map { |id| record_for(pipeline, id) }
|
@@ -41,7 +41,7 @@ module Modis
|
|
41
41
|
def find_all(ids)
|
42
42
|
raise RecordNotFound, "Couldn't find #{name} without an ID" if ids.empty?
|
43
43
|
|
44
|
-
records = Modis.with_connection do |redis|
|
44
|
+
records = Modis.with_connection(modis_connection) do |redis|
|
45
45
|
if ids.count == 1
|
46
46
|
ids.map { |id| record_for(redis, id) }
|
47
47
|
else
|
data/lib/modis/index.rb
CHANGED
data/lib/modis/model.rb
CHANGED
data/lib/modis/persistence.rb
CHANGED
@@ -150,7 +150,7 @@ module Modis
|
|
150
150
|
end
|
151
151
|
|
152
152
|
def reload
|
153
|
-
new_attributes = Modis.with_connection { |redis| self.class.attributes_for(redis, id) }
|
153
|
+
new_attributes = Modis.with_connection(modis_connection) { |redis| self.class.attributes_for(redis, id) }
|
154
154
|
initialize(new_attributes)
|
155
155
|
self
|
156
156
|
end
|
@@ -166,7 +166,7 @@ module Modis
|
|
166
166
|
end
|
167
167
|
|
168
168
|
alias update_attributes update
|
169
|
-
deprecate update_attributes: 'please, use update instead'
|
169
|
+
deprecate update_attributes: 'please, use update instead', deprecator: Modis.deprecator
|
170
170
|
|
171
171
|
def update!(attrs)
|
172
172
|
assign_attributes(attrs)
|
@@ -174,7 +174,7 @@ module Modis
|
|
174
174
|
end
|
175
175
|
|
176
176
|
alias update_attributes! update!
|
177
|
-
deprecate update_attributes!: 'please, use update! instead'
|
177
|
+
deprecate update_attributes!: 'please, use update! instead', deprecator: Modis.deprecator
|
178
178
|
|
179
179
|
private
|
180
180
|
|
@@ -253,7 +253,7 @@ module Modis
|
|
253
253
|
|
254
254
|
def set_id
|
255
255
|
namespace = self.class.sti_child? ? self.class.sti_base_absolute_namespace : self.class.absolute_namespace
|
256
|
-
Modis.with_connection do |redis|
|
256
|
+
Modis.with_connection(modis_connection) do |redis|
|
257
257
|
self.id = redis.incr("#{namespace}_id_seq")
|
258
258
|
end
|
259
259
|
end
|
data/lib/modis/transaction.rb
CHANGED
@@ -8,7 +8,7 @@ module Modis
|
|
8
8
|
|
9
9
|
module ClassMethods
|
10
10
|
def transaction
|
11
|
-
Modis.with_connection { |redis| redis.multi { |transaction| yield(transaction) } }
|
11
|
+
Modis.with_connection(modis_connection) { |redis| redis.multi { |transaction| yield(transaction) } }
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
data/lib/modis/version.rb
CHANGED
data/lib/modis.rb
CHANGED
@@ -7,6 +7,7 @@ require 'active_support/all'
|
|
7
7
|
require 'msgpack'
|
8
8
|
|
9
9
|
require 'modis/version'
|
10
|
+
require 'modis/deprecator'
|
10
11
|
require 'modis/configuration'
|
11
12
|
require 'modis/attribute'
|
12
13
|
require 'modis/errors'
|
@@ -17,14 +18,37 @@ require 'modis/index'
|
|
17
18
|
require 'modis/model'
|
18
19
|
|
19
20
|
module Modis
|
20
|
-
@mutex = Mutex.new
|
21
|
-
|
22
21
|
class << self
|
23
|
-
attr_writer :
|
24
|
-
:
|
22
|
+
attr_writer :connection_pool_size, :connection_pool_timeout,
|
23
|
+
:connection_pools
|
24
|
+
|
25
|
+
def mutex
|
26
|
+
@mutex ||= Mutex.new
|
27
|
+
end
|
25
28
|
|
26
29
|
def redis_options
|
27
|
-
@redis_options ||= {}
|
30
|
+
@redis_options ||= { default: {} }
|
31
|
+
end
|
32
|
+
|
33
|
+
def redis_options=(options)
|
34
|
+
if options.is_a?(Hash) && options.values.first.is_a?(Hash)
|
35
|
+
@redis_options = options.transform_values(&:dup)
|
36
|
+
else
|
37
|
+
redis_options[:default] = options
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def reset!
|
42
|
+
connection_pools.each do |key, _|
|
43
|
+
with_connection(key) do |connection|
|
44
|
+
keys = connection.keys "#{config.namespace}:*"
|
45
|
+
connection.del(*keys) unless keys.empty?
|
46
|
+
end
|
47
|
+
end
|
48
|
+
instance_variables.each do |var|
|
49
|
+
instance_variable_set(var, nil)
|
50
|
+
remove_instance_variable(var)
|
51
|
+
end
|
28
52
|
end
|
29
53
|
|
30
54
|
def connection_pool_size
|
@@ -35,17 +59,25 @@ module Modis
|
|
35
59
|
@connection_pool_timeout ||= 5
|
36
60
|
end
|
37
61
|
|
38
|
-
def
|
39
|
-
|
62
|
+
def connection_pools
|
63
|
+
@connection_pools ||= {}
|
64
|
+
end
|
40
65
|
|
41
|
-
|
42
|
-
|
43
|
-
|
66
|
+
def connection_pool(pool_name = :default)
|
67
|
+
connection_pools[pool_name] ||= begin
|
68
|
+
mutex.synchronize do
|
69
|
+
ConnectionPool.new(
|
70
|
+
size: connection_pool_size,
|
71
|
+
timeout: connection_pool_timeout
|
72
|
+
) do
|
73
|
+
Redis.new(redis_options[pool_name])
|
74
|
+
end
|
75
|
+
end
|
44
76
|
end
|
45
77
|
end
|
46
78
|
|
47
|
-
def with_connection
|
48
|
-
connection_pool.with { |connection| yield(connection) }
|
79
|
+
def with_connection(pool_name = :default)
|
80
|
+
connection_pool(pool_name).with { |connection| yield(connection) }
|
49
81
|
end
|
50
82
|
end
|
51
83
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module MultiRedisSpec
|
6
|
+
class DefaultUserModel
|
7
|
+
include Modis::Model
|
8
|
+
|
9
|
+
attribute :name, :string
|
10
|
+
end
|
11
|
+
|
12
|
+
class CustomUserModel
|
13
|
+
include Modis::Model
|
14
|
+
self.modis_connection = :custom
|
15
|
+
|
16
|
+
attribute :name, :string
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'Multiple redis support' do
|
21
|
+
before do
|
22
|
+
Modis.redis_options = {
|
23
|
+
default: { url: 'redis://localhost:6379/0' },
|
24
|
+
custom: { url: 'redis://localhost:6379/1' }
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'uses the default redis connection' do
|
29
|
+
expect(Modis).to receive(:with_connection).with(:default).at_least(3).times.and_call_original
|
30
|
+
user = MultiRedisSpec::DefaultUserModel.create!(name: 'Ian')
|
31
|
+
|
32
|
+
expect(Modis).to receive(:with_connection).with(:default).at_least(3).times.and_call_original
|
33
|
+
MultiRedisSpec::DefaultUserModel.find(user.id)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'uses the specified redis connection when set up' do
|
37
|
+
expect(Modis).to receive(:with_connection).with(:custom).at_least(3).times.and_call_original
|
38
|
+
user = MultiRedisSpec::CustomUserModel.create!(name: 'Tanya')
|
39
|
+
|
40
|
+
expect(Modis).to receive(:with_connection).with(:custom).at_least(3).times.and_call_original
|
41
|
+
MultiRedisSpec::CustomUserModel.find(user.id)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe 'backwards compatibility' do
|
46
|
+
before do
|
47
|
+
Modis.redis_options = {
|
48
|
+
url: 'redis://localhost:6379/0'
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'uses the default redis connection' do
|
53
|
+
expect(Modis).to receive(:with_connection).with(:default).at_least(3).times.and_call_original
|
54
|
+
MultiRedisSpec::DefaultUserModel.create!(name: 'Ian')
|
55
|
+
end
|
56
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -14,15 +14,12 @@ require 'modis'
|
|
14
14
|
|
15
15
|
Redis.raise_deprecations = true if Gem.loaded_specs['redis'].version >= Gem::Version.new('4.6.0')
|
16
16
|
|
17
|
-
Modis.configure do |config|
|
18
|
-
config.namespace = 'modis'
|
19
|
-
end
|
20
|
-
|
21
17
|
RSpec.configure do |config|
|
22
18
|
config.after :each do
|
23
|
-
Modis.
|
24
|
-
|
25
|
-
|
19
|
+
RSpec::Mocks.space.proxy_for(Modis).reset
|
20
|
+
Modis.reset!
|
21
|
+
Modis.configure do |modis_config|
|
22
|
+
modis_config.namespace = 'modis'
|
26
23
|
end
|
27
24
|
end
|
28
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: modis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ian Leitch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -236,6 +236,7 @@ files:
|
|
236
236
|
- lib/modis.rb
|
237
237
|
- lib/modis/attribute.rb
|
238
238
|
- lib/modis/configuration.rb
|
239
|
+
- lib/modis/deprecator.rb
|
239
240
|
- lib/modis/errors.rb
|
240
241
|
- lib/modis/finder.rb
|
241
242
|
- lib/modis/index.rb
|
@@ -249,6 +250,7 @@ files:
|
|
249
250
|
- spec/errors_spec.rb
|
250
251
|
- spec/finder_spec.rb
|
251
252
|
- spec/index_spec.rb
|
253
|
+
- spec/multi_redis_spec.rb
|
252
254
|
- spec/persistence_spec.rb
|
253
255
|
- spec/spec_helper.rb
|
254
256
|
- spec/support/simplecov_helper.rb
|
@@ -283,6 +285,7 @@ test_files:
|
|
283
285
|
- spec/errors_spec.rb
|
284
286
|
- spec/finder_spec.rb
|
285
287
|
- spec/index_spec.rb
|
288
|
+
- spec/multi_redis_spec.rb
|
286
289
|
- spec/persistence_spec.rb
|
287
290
|
- spec/spec_helper.rb
|
288
291
|
- spec/support/simplecov_helper.rb
|