modis 4.1.0 → 4.3.0

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
  SHA256:
3
- metadata.gz: d3cc18ebd9e13700435d34434b57d52b10eea6b6af111458db728c58ef132d7f
4
- data.tar.gz: 77010b2ca7a9edf776064a2d94f0c1e311af46263f9419b169afb157f78c4c48
3
+ metadata.gz: 9a9d3d05277e2ddf26b7c14547b3e03f37cb6fbb771ba9b2a6b61acce6485bd9
4
+ data.tar.gz: 031d2f34a15d5f077b5b01c2e4286b73285ed2171f4029577c2d812a22f6da6d
5
5
  SHA512:
6
- metadata.gz: dec75991005c6e245aff2f49150c76fafac0c65cc4523a4de814938e8de3e39b8baed59e5338e4759a9978ac1967c765be90aecdd1b5cc99a050b96bd0561512
7
- data.tar.gz: acff0628d95b28918f1329e1cd325031561da7635ae73619e822902f794b33a0314e104db801b8bd22cdec2e588a01fb2cbe97d1bec81316255df911b13f73ca
6
+ metadata.gz: 9b76390c567d8ba5495c226cb7425372797fe9b3d5e2d2a07a8f891bed7e5aa4f3c66d84f54c6cac7814f07f156e958687a62da8179c4d1922da2efb065412c1
7
+ data.tar.gz: dba384ff8ad647615016ed340c21e72088d45b1186b91e96f28c579b73ff7d45cd2616b10c70d42fcb17e1f4cfe4889074c0eb8a6ab41b0e92082d83d663c026
@@ -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@v2
59
+ - uses: actions/checkout@v4
59
60
 
60
61
  - name: Set up Ruby
61
62
  uses: ruby/setup-ruby@v1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # Changelog
2
2
 
3
+ ## [v4.1.0](https://github.com/rpush/modis/tree/v4.1.0) (2024-07-31)
4
+
5
+ [Full Changelog](https://github.com/rpush/modis/compare/v4.2.0...v4.1.0)
6
+
7
+ **Merged pull requests:**
8
+
9
+ - Add support for multiple redis connections [\#49](https://github.com/rpush/modis/pull/49) ([SxDx](https://github.com/SxDx))
10
+ - Fix deprecation warning [\#48](https://github.com/rpush/modis/pull/48) ([SxDx](https://github.com/SxDx))
11
+
12
+ ## [v4.2.0](https://github.com/rpush/modis/tree/v4.2.0) (2023-08-01)
13
+
14
+ [Full Changelog](https://github.com/rpush/modis/compare/v4.1.0...v4.2.0)
15
+
16
+ **Merged pull requests:**
17
+
18
+ - Support redis gem v5.x [\#45](https://github.com/rpush/modis/pull/45) ([benlangfeld](https://github.com/benlangfeld))
19
+
3
20
  ## [v4.1.0](https://github.com/rpush/modis/tree/v4.1.0) (2023-02-01)
4
21
 
5
22
  [Full Changelog](https://github.com/rpush/modis/compare/v4.0.1...v4.1.0)
@@ -10,6 +27,7 @@
10
27
 
11
28
  **Merged pull requests:**
12
29
 
30
+ - Prep v4.1.0 release [\#46](https://github.com/rpush/modis/pull/46) ([benlangfeld](https://github.com/benlangfeld))
13
31
  - Upgrades to latest activesupport [\#44](https://github.com/rpush/modis/pull/44) ([benlangfeld](https://github.com/benlangfeld))
14
32
  - Switch from Travis CI to GH actions [\#42](https://github.com/rpush/modis/pull/42) ([benlangfeld](https://github.com/benlangfeld))
15
33
  - Flexible encoding [\#41](https://github.com/rpush/modis/pull/41) ([benlangfeld](https://github.com/benlangfeld))
data/Gemfile.lock CHANGED
@@ -1,12 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- modis (4.1.0)
4
+ modis (4.3.0)
5
5
  activemodel (>= 5.2)
6
6
  activesupport (>= 5.2)
7
7
  connection_pool (>= 2)
8
8
  msgpack (>= 0.5)
9
- redis (>= 3.0, < 5.0)
9
+ redis (>= 3.0)
10
10
 
11
11
  GEM
12
12
  remote: https://rubygems.org/
@@ -48,8 +48,8 @@ GEM
48
48
  parallel
49
49
  codeclimate-test-reporter (1.0.7)
50
50
  simplecov
51
- concurrent-ruby (1.2.0)
52
- connection_pool (2.3.0)
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.12.0)
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.17.0)
79
- msgpack (1.6.0)
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,7 +94,10 @@ GEM
94
94
  public_suffix (5.0.1)
95
95
  rainbow (3.0.0)
96
96
  rake (13.0.1)
97
- redis (4.8.0)
97
+ redis (5.2.0)
98
+ redis-client (>= 0.22.0)
99
+ redis-client (0.22.2)
100
+ connection_pool
98
101
  rexml (3.2.5)
99
102
  rspec (3.9.0)
100
103
  rspec-core (~> 3.9.0)
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Modis
4
+ def self.deprecator
5
+ @deprecator ||= ActiveSupport::Deprecation.new('5.0', 'modis')
6
+ end
7
+ end
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
@@ -36,7 +36,7 @@ module Modis
36
36
  end
37
37
 
38
38
  def index_for(attribute, value)
39
- Modis.with_connection do |redis|
39
+ Modis.with_connection(modis_connection) do |redis|
40
40
  key = index_key(attribute, value)
41
41
  redis.smembers(key).map(&:to_i)
42
42
  end
data/lib/modis/model.rb CHANGED
@@ -21,6 +21,8 @@ module Modis
21
21
  include Modis::Index
22
22
 
23
23
  base.extend(ClassMethods)
24
+ base.class_attribute :modis_connection
25
+ base.modis_connection = :default
24
26
  end
25
27
  end
26
28
 
@@ -83,6 +83,7 @@ module Modis
83
83
 
84
84
  def deserialize(record)
85
85
  values = record.values
86
+ values.map! { |value| value.force_encoding(values.first.encoding) }
86
87
  header = msgpack_array_header(values.size, values.first.encoding)
87
88
  values = MessagePack.unpack(header + values.join)
88
89
  keys = record.keys
@@ -149,7 +150,7 @@ module Modis
149
150
  end
150
151
 
151
152
  def reload
152
- 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) }
153
154
  initialize(new_attributes)
154
155
  self
155
156
  end
@@ -165,7 +166,7 @@ module Modis
165
166
  end
166
167
 
167
168
  alias update_attributes update
168
- deprecate update_attributes: 'please, use update instead'
169
+ deprecate update_attributes: 'please, use update instead', deprecator: Modis.deprecator
169
170
 
170
171
  def update!(attrs)
171
172
  assign_attributes(attrs)
@@ -173,7 +174,7 @@ module Modis
173
174
  end
174
175
 
175
176
  alias update_attributes! update!
176
- deprecate update_attributes!: 'please, use update! instead'
177
+ deprecate update_attributes!: 'please, use update! instead', deprecator: Modis.deprecator
177
178
 
178
179
  private
179
180
 
@@ -252,7 +253,7 @@ module Modis
252
253
 
253
254
  def set_id
254
255
  namespace = self.class.sti_child? ? self.class.sti_base_absolute_namespace : self.class.absolute_namespace
255
- Modis.with_connection do |redis|
256
+ Modis.with_connection(modis_connection) do |redis|
256
257
  self.id = redis.incr("#{namespace}_id_seq")
257
258
  end
258
259
  end
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Modis
4
- VERSION = '4.1.0'
4
+ VERSION = '4.3.0'
5
5
  end
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'
@@ -18,13 +19,20 @@ require 'modis/model'
18
19
 
19
20
  module Modis
20
21
  @mutex = Mutex.new
21
-
22
22
  class << self
23
- attr_writer :redis_options, :connection_pool_size, :connection_pool_timeout,
24
- :connection_pool
23
+ attr_writer :connection_pool_size, :connection_pool_timeout,
24
+ :connection_pools
25
25
 
26
26
  def redis_options
27
- @redis_options ||= {}
27
+ @redis_options ||= { default: {} }
28
+ end
29
+
30
+ def redis_options=(options)
31
+ if options.is_a?(Hash) && options.values.first.is_a?(Hash)
32
+ @redis_options = options.transform_values(&:dup)
33
+ else
34
+ @redis_options[:default] = options
35
+ end
28
36
  end
29
37
 
30
38
  def connection_pool_size
@@ -35,17 +43,25 @@ module Modis
35
43
  @connection_pool_timeout ||= 5
36
44
  end
37
45
 
38
- def connection_pool
39
- return @connection_pool if @connection_pool
46
+ def connection_pools
47
+ @connection_pools ||= {}
48
+ end
40
49
 
41
- @mutex.synchronize do
42
- options = { size: connection_pool_size, timeout: connection_pool_timeout }
43
- @connection_pool = ConnectionPool.new(options) { Redis.new(redis_options) }
50
+ def connection_pool(pool_name = :default)
51
+ connection_pools[pool_name] ||= begin
52
+ @mutex.synchronize do
53
+ ConnectionPool.new(
54
+ size: connection_pool_size,
55
+ timeout: connection_pool_timeout
56
+ ) do
57
+ Redis.new(redis_options[pool_name])
58
+ end
59
+ end
44
60
  end
45
61
  end
46
62
 
47
- def with_connection
48
- connection_pool.with { |connection| yield(connection) }
63
+ def with_connection(pool_name = :default)
64
+ connection_pool(pool_name).with { |connection| yield(connection) }
49
65
  end
50
66
  end
51
67
  end
data/modis.gemspec CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |gem|
22
22
 
23
23
  gem.add_runtime_dependency 'activemodel', '>= 5.2'
24
24
  gem.add_runtime_dependency 'activesupport', '>= 5.2'
25
- gem.add_runtime_dependency 'redis', '>= 3.0', '< 5.0'
25
+ gem.add_runtime_dependency 'redis', '>= 3.0'
26
26
  gem.add_runtime_dependency 'connection_pool', '>= 2'
27
27
 
28
28
  if defined? JRUBY_VERSION
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MultiRedisSpec
4
+ class DefaultUserModel
5
+ include Modis::Model
6
+
7
+ attribute :name, :string
8
+ end
9
+
10
+ class CustomUserModel
11
+ include Modis::Model
12
+ self.modis_connection = :custom
13
+
14
+ attribute :name, :string
15
+ end
16
+ end
17
+
18
+ describe 'Multiple redis support' do
19
+ before do
20
+ Modis.redis_options = {
21
+ default: { url: 'redis://localhost:6379/0' },
22
+ custom: { url: 'redis://localhost:6379/1' }
23
+ }
24
+ end
25
+
26
+ it 'uses the default redis connection' do
27
+ expect(Modis).to receive(:with_connection).with(:default).at_least(3).times.and_call_original
28
+ user = MultiRedisSpec::DefaultUserModel.create!(name: 'Ian')
29
+
30
+ expect(Modis).to receive(:with_connection).with(:default).at_least(3).times.and_call_original
31
+ MultiRedisSpec::DefaultUserModel.find(user.id)
32
+ end
33
+
34
+ it 'uses the specified redis connection when set up' do
35
+ expect(Modis).to receive(:with_connection).with(:custom).at_least(3).times.and_call_original
36
+ user = MultiRedisSpec::CustomUserModel.create!(name: 'Tanya')
37
+
38
+ expect(Modis).to receive(:with_connection).with(:custom).at_least(3).times.and_call_original
39
+ MultiRedisSpec::CustomUserModel.find(user.id)
40
+ end
41
+ end
42
+
43
+ describe 'backwards compatibility' do
44
+ before do
45
+ Modis.redis_options = {
46
+ url: 'redis://localhost:6379/0'
47
+ }
48
+ end
49
+
50
+ it 'uses the default redis connection' do
51
+ expect(Modis).to receive(:with_connection).with(:default).at_least(3).times.and_call_original
52
+ MultiRedisSpec::DefaultUserModel.create!(name: 'Ian')
53
+ end
54
+ end
data/spec/spec_helper.rb CHANGED
@@ -20,9 +20,12 @@ end
20
20
 
21
21
  RSpec.configure do |config|
22
22
  config.after :each do
23
- Modis.with_connection do |connection|
24
- keys = connection.keys "#{Modis.config.namespace}:*"
25
- connection.del(*keys) unless keys.empty?
23
+ RSpec::Mocks.space.proxy_for(Modis).reset
24
+ Modis.connection_pools.each do |key, _|
25
+ Modis.with_connection(key) do |connection|
26
+ keys = connection.keys "#{Modis.config.namespace}:*"
27
+ connection.del(*keys) unless keys.empty?
28
+ end
26
29
  end
27
30
  end
28
31
  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.1.0
4
+ version: 4.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian Leitch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-01 00:00:00.000000000 Z
11
+ date: 2024-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -45,9 +45,6 @@ dependencies:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '3.0'
48
- - - "<"
49
- - !ruby/object:Gem::Version
50
- version: '5.0'
51
48
  type: :runtime
52
49
  prerelease: false
53
50
  version_requirements: !ruby/object:Gem::Requirement
@@ -55,9 +52,6 @@ dependencies:
55
52
  - - ">="
56
53
  - !ruby/object:Gem::Version
57
54
  version: '3.0'
58
- - - "<"
59
- - !ruby/object:Gem::Version
60
- version: '5.0'
61
55
  - !ruby/object:Gem::Dependency
62
56
  name: connection_pool
63
57
  requirement: !ruby/object:Gem::Requirement
@@ -242,6 +236,7 @@ files:
242
236
  - lib/modis.rb
243
237
  - lib/modis/attribute.rb
244
238
  - lib/modis/configuration.rb
239
+ - lib/modis/deprecator.rb
245
240
  - lib/modis/errors.rb
246
241
  - lib/modis/finder.rb
247
242
  - lib/modis/index.rb
@@ -255,6 +250,7 @@ files:
255
250
  - spec/errors_spec.rb
256
251
  - spec/finder_spec.rb
257
252
  - spec/index_spec.rb
253
+ - spec/multi_redis_spec.rb
258
254
  - spec/persistence_spec.rb
259
255
  - spec/spec_helper.rb
260
256
  - spec/support/simplecov_helper.rb
@@ -289,6 +285,7 @@ test_files:
289
285
  - spec/errors_spec.rb
290
286
  - spec/finder_spec.rb
291
287
  - spec/index_spec.rb
288
+ - spec/multi_redis_spec.rb
292
289
  - spec/persistence_spec.rb
293
290
  - spec/spec_helper.rb
294
291
  - spec/support/simplecov_helper.rb