From de2d6127425508b0784f3f8b35b80f2a2b56dd0c Mon Sep 17 00:00:00 2001 From: Vlad Pisanov Date: Tue, 14 Mar 2023 08:08:11 -0400 Subject: [PATCH 1/2] Bump supported Ruby version --- redis-script_manager.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/redis-script_manager.gemspec b/redis-script_manager.gemspec index 1b87f22..679f14a 100644 --- a/redis-script_manager.gemspec +++ b/redis-script_manager.gemspec @@ -23,7 +23,7 @@ Gem::Specification.new do |spec| # # Also, the redis gem from 4.0.0 does not support rubies < 2.2.2. # - spec.required_ruby_version = ['>= 2.2.2', '< 2.7.0'] # tested to 2.6.3 + spec.required_ruby_version = ['>= 2.2.2', '< 4'] # tested to 3.3.1 spec.add_runtime_dependency 'redis', '>= 3.0.0', '< 5.0.0' # tested to 4.1.1 From 4fdbeedb991322f0dbd4cd1a4ffb3e58bfd6c493 Mon Sep 17 00:00:00 2001 From: Vlad Pisanov Date: Fri, 4 Apr 2025 04:34:15 -0400 Subject: [PATCH 2/2] Bump redis gem support to v5 --- Gemfile | 1 - lib/redis/script_manager.rb | 12 ++++++++-- lib/redis/script_manager/version.rb | 2 +- redis-script_manager.gemspec | 14 ++---------- test/redis/script_manager_test.rb | 35 +++++++++++++++++------------ 5 files changed, 34 insertions(+), 30 deletions(-) diff --git a/Gemfile b/Gemfile index fe636ae..87871a5 100644 --- a/Gemfile +++ b/Gemfile @@ -14,7 +14,6 @@ gemspec group :development do gem 'appraisal', '~> 2.2.0' - gem 'bundler', '1.16.6' gem 'rake', '~> 12.3.1' end diff --git a/lib/redis/script_manager.rb b/lib/redis/script_manager.rb index ae84717..c38442d 100644 --- a/lib/redis/script_manager.rb +++ b/lib/redis/script_manager.rb @@ -181,6 +181,10 @@ def self.eval_gently(redis,lua,keys=[],args=[]) # @return true if redis is currently in a pipeline, false otherwise # def self.in_pipeline?(redis) + # TODO: after full migration to redis gem v5, simplify the checks + if defined?(Redis::PipelinedConnection) && redis.is_a?(Redis::PipelinedConnection) + return true + end # # redis-rb 4.0 added support for the redis-server command # CLIENT, and in so doing re-named the accessor for the lower @@ -188,8 +192,12 @@ def self.in_pipeline?(redis) # # htps://github.com/redis/redis-rb/blob/master/CHANGELOG.md#40 # - client = redis.respond_to?(:_client) ? redis._client : redis.client - client.is_a?(Redis::Pipeline) # thanks @marshall + if defined?(Redis::Pipeline) + client = redis.respond_to?(:_client) ? redis._client : redis.client + return client.is_a?(Redis::Pipeline) # thanks @marshall + end + + false end @preloaded_shas = Set[] # [redis.object_id,sha(lua)] which have been loaded diff --git a/lib/redis/script_manager/version.rb b/lib/redis/script_manager/version.rb index 279a3e1..2f2c0f4 100644 --- a/lib/redis/script_manager/version.rb +++ b/lib/redis/script_manager/version.rb @@ -1,5 +1,5 @@ class Redis class ScriptManager - VERSION = '0.0.6'.freeze + VERSION = '0.0.7'.freeze end end diff --git a/redis-script_manager.gemspec b/redis-script_manager.gemspec index 679f14a..7311668 100644 --- a/redis-script_manager.gemspec +++ b/redis-script_manager.gemspec @@ -18,17 +18,7 @@ Gem::Specification.new do |spec| end spec.require_paths = ['lib'] - # We use 'foo: bar' syntax liberally, not the older ':foo => bar'. - # Possibly other Ruby 2-isms as well. - # - # Also, the redis gem from 4.0.0 does not support rubies < 2.2.2. - # - spec.required_ruby_version = ['>= 2.2.2', '< 4'] # tested to 3.3.1 + spec.required_ruby_version = ['>= 2.2.2', '< 4'] # tested to 3.3.2 - spec.add_runtime_dependency 'redis', '>= 3.0.0', '< 5.0.0' # tested to 4.1.1 - - # Development dependencies are captured in Gemfile, per the pattern: - # - # https://github.com/jollygoodcode/jollygoodcode.github.io/issues/21 - # + spec.add_runtime_dependency 'redis', '>= 4', '< 6' # tested to 5.4.0 end diff --git a/test/redis/script_manager_test.rb b/test/redis/script_manager_test.rb index 46fdb23..cf213c5 100644 --- a/test/redis/script_manager_test.rb +++ b/test/redis/script_manager_test.rb @@ -557,8 +557,14 @@ def test_preload_cache_size def test_in_pipeline? return if !redis assert_equal false, Redis::ScriptManager.in_pipeline?(redis) - redis.pipelined do - assert_equal true, Redis::ScriptManager.in_pipeline?(redis) + # TODO: drop this after migration to redis gem v5 + if Redis::VERSION < '5' + redis.pipelined do + assert_equal true, Redis::ScriptManager.in_pipeline?(redis) + end + end + redis.pipelined do |pipeline| + assert_equal true, Redis::ScriptManager.in_pipeline?(pipeline) end assert_equal false, Redis::ScriptManager.in_pipeline?(redis) end @@ -596,12 +602,12 @@ def test_implications_of_pipelined l_lua_b = "return '#{l_str_b}'" # not cached, will evalsha s_got_b = nil l_got_b = nil - redis.pipelined do - s_got_b = Redis::ScriptManager.eval_gently(redis,s_lua_b,['k']) + redis.pipelined do |pipeline| + s_got_b = Redis::ScriptManager.eval_gently(pipeline,s_lua_b,['k']) end assert_equal s_str_b, s_got_b.value - redis.pipelined do - l_got_b = Redis::ScriptManager.eval_gently(redis,l_lua_b,['k']) + redis.pipelined do |pipeline| + l_got_b = Redis::ScriptManager.eval_gently(pipeline,l_lua_b,['k']) end # # In TDD style, this final assert fails if the in_pipeline check @@ -648,16 +654,17 @@ def test_implications_of_do_preload l_lua_b = "return '#{l_str_b}'" # not cached, will evalsha s_got_b = nil l_got_b = nil - redis.pipelined do # triple up to see cache_hit and cache_miss - s_got_b = Redis::ScriptManager.eval_gently(redis,s_lua_b,['k']) - s_got_b = Redis::ScriptManager.eval_gently(redis,s_lua_b,['k']) - s_got_b = Redis::ScriptManager.eval_gently(redis,s_lua_b,['k']) + + redis.pipelined do |pipeline| # triple up to see cache_hit and cache_miss + s_got_b = Redis::ScriptManager.eval_gently(pipeline,s_lua_b,['k']) + s_got_b = Redis::ScriptManager.eval_gently(pipeline,s_lua_b,['k']) + s_got_b = Redis::ScriptManager.eval_gently(pipeline,s_lua_b,['k']) end assert_equal s_str_b, s_got_b.value - redis.pipelined do # triple up to see cache_hit and cache_miss - l_got_b = Redis::ScriptManager.eval_gently(redis,l_lua_b,['k']) - l_got_b = Redis::ScriptManager.eval_gently(redis,l_lua_b,['k']) - l_got_b = Redis::ScriptManager.eval_gently(redis,l_lua_b,['k']) + redis.pipelined do |pipeline| # triple up to see cache_hit and cache_miss + l_got_b = Redis::ScriptManager.eval_gently(pipeline,l_lua_b,['k']) + l_got_b = Redis::ScriptManager.eval_gently(pipeline,l_lua_b,['k']) + l_got_b = Redis::ScriptManager.eval_gently(pipeline,l_lua_b,['k']) end # # In TDD style, this final assert fails if the in_pipeline check