diff --git a/lib/sidekiq/grouping/redis.rb b/lib/sidekiq/grouping/redis.rb index 39753b3..5d02e71 100644 --- a/lib/sidekiq/grouping/redis.rb +++ b/lib/sidekiq/grouping/redis.rb @@ -110,6 +110,12 @@ def ns(key = nil) "batching:#{key}" end + def server_version + Sidekiq.redis do |conn| + conn.info["redis_version"] + end + end + # # The optimized LUA SCRIPT works from Redis greater than or equal to 6.2. # Check Redis version in use and return the suitable PLUCK_SCRIPT @@ -117,10 +123,7 @@ def ns(key = nil) # @return [] # def pluck_script - redis_version = Sidekiq.redis do |conn| - conn.info(:server)["redis_version"] - end - if Gem::Version.new(redis_version) >= Gem::Version.new("6.2.0") + if server_version >= "6.2.0" PLUCK_SCRIPT_GTE_6_2_0 else PLUCK_SCRIPT_LT_6_2_0 diff --git a/spec/modules/redis_spec.rb b/spec/modules/redis_spec.rb index 48a3295..2c0204a 100644 --- a/spec/modules/redis_spec.rb +++ b/spec/modules/redis_spec.rb @@ -43,25 +43,19 @@ end describe "#pluck_script" do - context "when Redis version is" do + context "when Redis server version is" do it ">= 6.2.0, selects the corresponding pluck script" do - allow_any_instance_of(RedisClient).to receive(:call) - .with(:info, anything) - .and_return( - { "redis_version" => "6.2.0" } - ) - expect(redis_service.pluck_script).to eq( + allow_any_instance_of(described_class).to receive(:server_version) + .and_return("6.2.0") + expect(redis_service.send(:pluck_script)).to eq( described_class::PLUCK_SCRIPT_GTE_6_2_0 ) end it "< 6.2.0, selects the corresponding pluck script" do - allow_any_instance_of(RedisClient).to receive(:call) - .with(:info, anything) - .and_return( - { "redis_version" => "6.0.0" } - ) - expect(redis_service.pluck_script).to eq( + allow_any_instance_of(described_class).to receive(:server_version) + .and_return("6.0.0") + expect(redis_service.send(:pluck_script)).to eq( described_class::PLUCK_SCRIPT_LT_6_2_0 ) end