Skip to content
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

Update the redis .multi code to remove the warnings in the logs #23

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# v2.4.2
* Update to `set` to use .multi correctly - the yield block now takes a parameter and calls that with the commands to execute which will then correctly be called in a multi block to redis

# 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
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
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
Loading