Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ gemspec

group :development do
gem 'appraisal', '~> 2.2.0'
gem 'bundler', '1.16.6'
gem 'rake', '~> 12.3.1'
end

Expand Down
12 changes: 10 additions & 2 deletions lib/redis/script_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,23 @@ 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
# level client from :client to :_client.
#
# 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
Expand Down
2 changes: 1 addition & 1 deletion lib/redis/script_manager/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Redis
class ScriptManager
VERSION = '0.0.6'.freeze
VERSION = '0.0.7'.freeze
end
end
14 changes: 2 additions & 12 deletions redis-script_manager.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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', '< 2.7.0'] # tested to 2.6.3
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
35 changes: 21 additions & 14 deletions test/redis/script_manager_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down