flipper-redis 1.3.3 → 1.3.5

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: a790000c8a290b42d4e92173ddc5e00632c7113b16ca47c4c257d26ee36005aa
4
- data.tar.gz: 6e6b7c2d513a8472e6bdc7cb99dff07daaf984751d7c7880bde92622663f95dc
3
+ metadata.gz: eff5e795ad93b545c0d17244c5dce9b9d1511faa60605586fe91e811f16e3ed3
4
+ data.tar.gz: 69b59f7b4ef2c9b61e93f7b6a909041b71edfbe6dbe9369dadb0bd0bcc4593dd
5
5
  SHA512:
6
- metadata.gz: ae7bf6f058f1a54ef97bbc2b3e86e03398d01c65df8f9752c5b0351d476e70d91754680df9223b15162c0dbd9c8cdfeb7ce5f4d40da6c6443915a2c8cecaf777
7
- data.tar.gz: 709339de3e5a6cb919a2ae8fbf63f882f16fc06b7339b4fe171aef7d70feb4961031af6269b6fede7877a0bd5d1b96962b3025cc2bd4285ea6abe87ee0d59cc4
6
+ metadata.gz: 3cdac88dec216e8ddbb4acd27cd8f9531c53ce383d87709e9fb42d9ddeed380610d1874f65e02f630c8534eef8e2625ef8064eba156a92656777fc80ec84edd8
7
+ data.tar.gz: e6aed049e4ad608df72fb1cb0f477347aa3b136e1b5b4b885477b1a7f63f0d65b2b8802200a223d0f3859ac0dc5890b741ddc2d8b3e5ca27ad74efdac777504f
@@ -1,8 +1,63 @@
1
1
  module Flipper
2
2
  module Adapters
3
3
  module RedisShared
4
+ private
5
+
6
+ # Safely executes a block with a Redis connection, handling compatibility
7
+ # issues between different Redis client versions and Rails versions.
8
+ #
9
+ # This method exists to fix a compatibility issue between Rails 7.1.* and
10
+ # Redis versions below 4.7.0. The issue occurs because:
11
+ #
12
+ # 1. In Redis versions below 4.7.0, the `with` method is not defined on
13
+ # the Redis client, so Flipper would fall back to `yield(@client)`
14
+ # 2. However, Rails 7.1.* introduced `Object#with` via ActiveSupport,
15
+ # which shadows the Redis client's `with` method
16
+ # 3. Rails 7.1.*'s `Object#with` doesn't pass `self` to the block parameter
17
+ # (this was fixed in Rails 7.2.0), causing the block parameter to be `nil`
18
+ #
19
+ # This method ensures that:
20
+ # - For Redis >= 4.7.0: Uses the Redis client's native `with` method
21
+ # - For ConnectionPool: Uses the ConnectionPool's `with` method
22
+ # - For Redis < 4.7.0: Falls back to `yield(@client)` to avoid the Rails
23
+ # ActiveSupport `Object#with` method
24
+ #
25
+ # @see https://github.com/redis/redis-rb/blob/master/CHANGELOG.md#470
26
+ # @see https://github.com/rails/rails/pull/46681
27
+ # @see https://github.com/rails/rails/pull/50470
4
28
  def with_connection(&block)
5
- @client.respond_to?(:with) ? @client.with(&block) : yield(@client)
29
+ if client_has_correct_with_method?
30
+ @client.with(&block)
31
+ else
32
+ yield(@client)
33
+ end
34
+ end
35
+
36
+ # Determines if the Redis client has a safe `with` method that can be used
37
+ # without conflicts with Rails ActiveSupport's `Object#with`.
38
+ #
39
+ # This method checks for:
40
+ # 1. ConnectionPool instances (which have their own `with` method)
41
+ # 2. Redis instances with version >= 4.7.0 (which have a proper `with` method)
42
+ #
43
+ # The method caches its result to avoid repeated checks.
44
+ #
45
+ # @return [Boolean] true if the client has a safe `with` method, false otherwise
46
+ def client_has_correct_with_method?
47
+ return @client_has_correct_with_method if defined?(@client_has_correct_with_method)
48
+
49
+ @client_has_correct_with_method = @client.respond_to?(:with) && (client_is_connection_pool? || client_is_redis_that_has_with?)
50
+ rescue
51
+ @client_has_correct_with_method = false
52
+ end
53
+
54
+ def client_is_connection_pool?
55
+ defined?(ConnectionPool) && @client.is_a?(ConnectionPool)
56
+ end
57
+
58
+ def client_is_redis_that_has_with?
59
+ @client.is_a?(::Redis) && defined?(::Redis::VERSION) &&
60
+ ::Gem::Version.new(::Redis::VERSION) >= ::Gem::Version.new('4.7.0')
6
61
  end
7
62
  end
8
63
  end
@@ -1,5 +1,5 @@
1
1
  module Flipper
2
- VERSION = '1.3.3'.freeze
2
+ VERSION = '1.3.5'.freeze
3
3
 
4
4
  REQUIRED_RUBY_VERSION = '2.6'.freeze
5
5
  NEXT_REQUIRED_RUBY_VERSION = '3.0'.freeze
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flipper-redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.3
4
+ version: 1.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-02-24 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: flipper
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: 1.3.3
18
+ version: 1.3.5
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
- version: 1.3.3
25
+ version: 1.3.5
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: redis
28
28
  requirement: !ruby/object:Gem::Requirement
@@ -50,7 +50,6 @@ extra_rdoc_files: []
50
50
  files:
51
51
  - examples/redis/basic.rb
52
52
  - examples/redis/internals.rb
53
- - examples/redis/namespaced.rb
54
53
  - flipper-redis.gemspec
55
54
  - lib/flipper-redis.rb
56
55
  - lib/flipper/adapters/redis.rb
@@ -69,7 +68,7 @@ metadata:
69
68
  homepage_uri: https://www.flippercloud.io
70
69
  source_code_uri: https://github.com/flippercloud/flipper
71
70
  bug_tracker_uri: https://github.com/flippercloud/flipper/issues
72
- changelog_uri: https://github.com/flippercloud/flipper/releases/tag/v1.3.3
71
+ changelog_uri: https://github.com/flippercloud/flipper/releases/tag/v1.3.5
73
72
  funding_uri: https://github.com/sponsors/flippercloud
74
73
  rdoc_options: []
75
74
  require_paths:
@@ -85,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
84
  - !ruby/object:Gem::Version
86
85
  version: '0'
87
86
  requirements: []
88
- rubygems_version: 3.6.5
87
+ rubygems_version: 3.6.9
89
88
  specification_version: 4
90
89
  summary: Redis feature flag adapter for Flipper
91
90
  test_files:
@@ -1,37 +0,0 @@
1
- require 'bundler/setup'
2
- require 'redis-namespace'
3
- require 'flipper/adapters/redis'
4
-
5
- options = {url: 'redis://127.0.0.1:6379'}
6
- if ENV['REDIS_URL']
7
- options[:url] = ENV['REDIS_URL']
8
- end
9
- client = Redis.new(options)
10
- namespaced_client = Redis::Namespace.new(:flipper_namespace, redis: client)
11
- adapter = Flipper::Adapters::Redis.new(namespaced_client)
12
- flipper = Flipper.new(adapter)
13
-
14
- # Register a few groups.
15
- Flipper.register(:admins) { |actor| actor.admin? }
16
- Flipper.register(:early_access) { |actor| actor.early_access? }
17
-
18
- # Create a user class that has flipper_id instance method.
19
- User = Struct.new(:flipper_id)
20
-
21
- flipper[:stats].enable
22
- flipper[:stats].enable_group :admins
23
- flipper[:stats].enable_group :early_access
24
- flipper[:stats].enable_actor User.new('25')
25
- flipper[:stats].enable_actor User.new('90')
26
- flipper[:stats].enable_actor User.new('180')
27
- flipper[:stats].enable_percentage_of_time 15
28
- flipper[:stats].enable_percentage_of_actors 45
29
-
30
- flipper[:search].enable
31
-
32
- print 'all keys: '
33
- pp client.keys
34
- # all keys: ["stats", "flipper_features", "search"]
35
- puts
36
-
37
- puts 'notice how all the keys are namespaced'