Skip to content

Commit

Permalink
Update the redis .multi code to remove the warnings in the logs
Browse files Browse the repository at this point in the history
  • Loading branch information
LauraCollins-Sage committed Oct 17, 2024
1 parent 3940ebe commit ff458c2
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 16 deletions.
13 changes: 10 additions & 3 deletions .github/workflows/rspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ jobs:
test:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
ruby-version: ['3.2', '3.1', '3.0']

services:
redis:
image: redis:alpine
Expand All @@ -18,10 +23,12 @@ jobs:
- 6379:6379

steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
- uses: actions/checkout@v4

- name: Set up Ruby ${{ matrix.ruby-version }}
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.4
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true

- name: Run tests
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ruby:2.7-buster
FROM ruby:3.2

ARG BUNDLE_SAGEONEGEMS__JFROG__IO

Expand Down
2 changes: 2 additions & 0 deletions cache_store_redis.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Gem::Specification.new do |spec|
spec.homepage = 'https://github.com/sage/cache_store'
spec.license = 'MIT'

spec.required_ruby_version = '>= 3.0'

spec.files = Dir.glob("{bin,lib}/**/**/**")
spec.bindir = 'exe'
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
Expand Down
6 changes: 3 additions & 3 deletions lib/cache_store_redis/redis_cache_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ 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.multi do |transaction|
transaction.set(k, v)

client.expire(k, expire_value)
transaction.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'
end
16 changes: 8 additions & 8 deletions spec/cache_store_redis_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@
let(:value) { 'SomeValue' }

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_any_instance_of(Redis::MultiConnection).to receive(:set).with("test:#{key}", "\"#{value}\"")
expect_any_instance_of(Redis::MultiConnection).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_any_instance_of(Redis::MultiConnection).to receive(:set).with("test:#{key}", "\"#{value}\"")
expect_any_instance_of(Redis::MultiConnection).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_any_instance_of(Redis::MultiConnection).to receive(:set).with("test:#{key}", "\"#{value}\"")
expect_any_instance_of(Redis::MultiConnection).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_any_instance_of(Redis::MultiConnection).to receive(:set).with("test:#{key}", "\"#{value}\"")
expect_any_instance_of(Redis::MultiConnection).to receive(:expire).with("test:#{key}", 20)
subject.public_send(method_name, key, value, 20.123)
end
end
Expand Down

0 comments on commit ff458c2

Please sign in to comment.