Skip to content

Resolve "Pipelining commands on a Redis instance..." warnings #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 6, 2025
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/rspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.4
ruby-version: 2.7
bundler-cache: true

- name: Run tests
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@

# v2.4.2

* ENG-2688 - Resolve "Pipelining commands on a Redis instance is deprecated and will be removed in Redis 5.0.0." warnings
* Update git workflow ruby-version to 2.7 to match .dockerfile

# v2.2.0

* Alias `#get`, `#set`, and `#remove` to `#read`, `#write`, and `#delete`, so that `RedisCacheStore` and `OptionalRedisCacheStore` can be used anywhere that expects a `#read`, `#write`, `#delete` API e.g. `faraday-http-cache`.
Expand Down
7 changes: 3 additions & 4 deletions lib/cache_store_redis/redis_cache_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,9 @@ def set(key, value, expires_in = DEFAULT_TTL)
expire_value = expiry_int.positive? ? expiry_int : Integer(DEFAULT_TTL)

with_client do |client|
client.multi do
client.set(k, v)

client.expire(k, expire_value)
client.multi do |pipeline|
pipeline.set(k, v)
pipeline.expire(k, expire_value)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/cache_store_redis/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module CacheStoreRedis
VERSION = '2.4.1'
VERSION = '2.4.2'.freeze
end
21 changes: 13 additions & 8 deletions spec/cache_store_redis_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,33 @@
context 'expires_in' do
let(:key) { SecureRandom.uuid }
let(:value) { 'SomeValue' }
let(:mock_redis) { instance_double('Redis::MultiConnection') }

before do
allow(Redis::MultiConnection).to receive(:new).and_return(mock_redis)
end

it 'will always set a default TTL if one is not provided' do
expect_any_instance_of(Redis).to receive(:set).with("test:#{key}", "\"#{value}\"")
expect_any_instance_of(Redis).to receive(:expire).with("test:#{key}", 3_600)
expect(mock_redis).to receive(:set).with("test:#{key}", "\"#{value}\"")
expect(mock_redis).to receive(:expire).with("test:#{key}", 3_600)
subject.public_send(method_name, key, value)
end

it 'will always set a default TTL if an invalid one is provided' do
expect_any_instance_of(Redis).to receive(:set).with("test:#{key}", "\"#{value}\"")
expect_any_instance_of(Redis).to receive(:expire).with("test:#{key}", 3_600)
expect(mock_redis).to receive(:set).with("test:#{key}", "\"#{value}\"")
expect(mock_redis).to receive(:expire).with("test:#{key}", 3_600)
subject.public_send(method_name, key, value, -200)
end

it 'will always set a default TTL if an invalid one is provided' do
expect_any_instance_of(Redis).to receive(:set).with("test:#{key}", "\"#{value}\"")
expect_any_instance_of(Redis).to receive(:expire).with("test:#{key}", 3_600)
expect(mock_redis).to receive(:set).with("test:#{key}", "\"#{value}\"")
expect(mock_redis).to receive(:expire).with("test:#{key}", 3_600)
subject.public_send(method_name, key, value, 0.456)
end

it 'will always force the TTL to be an integer' do
expect_any_instance_of(Redis).to receive(:set).with("test:#{key}", "\"#{value}\"")
expect_any_instance_of(Redis).to receive(:expire).with("test:#{key}", 20)
expect(mock_redis).to receive(:set).with("test:#{key}", "\"#{value}\"")
expect(mock_redis).to receive(:expire).with("test:#{key}", 20)
subject.public_send(method_name, key, value, 20.123)
end
end
Expand Down