redis-store 1.9.2 → 1.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +7 -3
- data/.github/workflows/publish.yml +2 -2
- data/.gitignore +3 -0
- data/CHANGELOG.md +7 -0
- data/README.md +1 -1
- data/Rakefile +2 -1
- data/lib/redis/distributed_store.rb +2 -0
- data/lib/redis/store/factory.rb +9 -1
- data/lib/redis/store/version.rb +8 -1
- data/lib/redis/store.rb +27 -8
- data/redis-store.gemspec +1 -1
- data/test/redis/distributed_store_test.rb +1 -1
- data/test/redis/store/factory_test.rb +66 -14
- data/test/redis/store/namespace_test.rb +57 -44
- data/test/redis/store/serialization_test.rb +2 -2
- data/test/redis/store_test.rb +1 -1
- data/test/test_helper.rb +1 -2
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b56845874e768c8ec1357c19affb5e7cdb3914d4839cd18d0e443f03b0e843e8
|
4
|
+
data.tar.gz: ab3b3872974e7e6fef5992701227397dbc00e8a905d532ab031da57eb2a7ed83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96808f1f4a574c79e2e322825e1d7c0f89265ca06db21de1d277e6d519a5c4698b495b9f9c81c3d72811280d400de8b043f15c57bb7f1a02fdf08023b3dcd673
|
7
|
+
data.tar.gz: 5f6a9ca80e5c7166c003421a6942bed21996b8daa09f134e1646f47942ae086246655068b7f0108e8a710622ec96f4bf4649812d44c2c8538b484bb401a38d60
|
data/.github/workflows/ci.yml
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
name: CI
|
2
2
|
on:
|
3
|
+
pull_request:
|
3
4
|
push:
|
4
5
|
branches-ignore: [master]
|
5
6
|
tags-ignore: [v*]
|
@@ -18,6 +19,8 @@ jobs:
|
|
18
19
|
- "2.7"
|
19
20
|
- "3.0"
|
20
21
|
- "3.1"
|
22
|
+
- "3.2"
|
23
|
+
- "3.3"
|
21
24
|
# - 'head'
|
22
25
|
- "jruby"
|
23
26
|
# - 'jruby-head'
|
@@ -27,6 +30,7 @@ jobs:
|
|
27
30
|
- 4_0_x
|
28
31
|
- 4_1_x
|
29
32
|
- 4_x
|
33
|
+
- 5_x
|
30
34
|
env:
|
31
35
|
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/redis_${{ matrix.redis }}.gemfile
|
32
36
|
services:
|
@@ -43,7 +47,7 @@ jobs:
|
|
43
47
|
ports:
|
44
48
|
- 6381:6381
|
45
49
|
steps:
|
46
|
-
- uses: actions/checkout@
|
50
|
+
- uses: actions/checkout@v4
|
47
51
|
- uses: ruby/setup-ruby@v1
|
48
52
|
with:
|
49
53
|
ruby-version: ${{ matrix.ruby }}
|
@@ -52,11 +56,11 @@ jobs:
|
|
52
56
|
lint:
|
53
57
|
runs-on: ubuntu-latest
|
54
58
|
steps:
|
55
|
-
- uses: actions/checkout@
|
59
|
+
- uses: actions/checkout@v4
|
56
60
|
with:
|
57
61
|
fetch-depth: 0
|
58
62
|
- uses: ruby/setup-ruby@v1
|
59
63
|
with:
|
60
|
-
ruby-version: 3.
|
64
|
+
ruby-version: 3.3
|
61
65
|
bundler-cache: true
|
62
66
|
- run: bundle exec rake lint
|
@@ -11,10 +11,10 @@ jobs:
|
|
11
11
|
release:
|
12
12
|
runs-on: ubuntu-latest
|
13
13
|
steps:
|
14
|
-
- uses: actions/checkout@
|
14
|
+
- uses: actions/checkout@v4
|
15
15
|
- uses: ruby/setup-ruby@v1
|
16
16
|
with:
|
17
|
-
ruby-version: "3.
|
17
|
+
ruby-version: "3.3"
|
18
18
|
bundler-cache: true
|
19
19
|
- run: |
|
20
20
|
mkdir -p ~/.gem
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -46,7 +46,7 @@ s.add_dependency 'redis-store', '>= 1.4', '< 2'
|
|
46
46
|
## Status
|
47
47
|
|
48
48
|
[![Gem Version](https://badge.fury.io/rb/redis-store.svg)](http://badge.fury.io/rb/redis-store)
|
49
|
-
[![Build Status](https://
|
49
|
+
[![Build Status](https://github.com/redis-store/redis-store/actions/workflows/ci.yml/badge.svg)](https://github.com/redis-store/redis-store/actions/workflows/ci.yml)
|
50
50
|
[![Code Climate](https://codeclimate.com/github/redis-store/redis-store.svg)](https://codeclimate.com/github/redis-store/redis-store)
|
51
51
|
|
52
52
|
## Copyright
|
data/Rakefile
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'bundler/setup'
|
2
2
|
require 'rake'
|
3
3
|
require 'bundler/gem_tasks'
|
4
|
-
require 'redis-store/testing/tasks'
|
5
4
|
require 'appraisal'
|
6
5
|
require 'rubocop/rake_task'
|
7
6
|
|
@@ -11,4 +10,6 @@ if !ENV["APPRAISAL_INITIALIZED"] && !ENV["CI"]
|
|
11
10
|
task :default do
|
12
11
|
sh "appraisal install && rake appraisal default"
|
13
12
|
end
|
13
|
+
else
|
14
|
+
require 'redis-store/testing/tasks'
|
14
15
|
end
|
@@ -7,6 +7,8 @@ class Redis
|
|
7
7
|
|
8
8
|
def initialize(addresses, options = {})
|
9
9
|
_extend_namespace options
|
10
|
+
# `@tag` introduced in `redis-rb` 5.0
|
11
|
+
@tag = options[:tag] || /^\{(.+?)\}/
|
10
12
|
@ring = options[:ring] || Redis::HashRing.new([], options[:replicas] || Redis::HashRing::POINTS_PER_SERVER)
|
11
13
|
|
12
14
|
addresses.each do |address|
|
data/lib/redis/store/factory.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'cgi'
|
1
2
|
require 'uri'
|
2
3
|
|
3
4
|
class Redis
|
@@ -77,12 +78,19 @@ class Redis
|
|
77
78
|
:scheme => uri.scheme,
|
78
79
|
:host => uri.hostname,
|
79
80
|
:port => uri.port || DEFAULT_PORT,
|
80
|
-
:
|
81
|
+
:ssl => uri.scheme == 'rediss'
|
81
82
|
}
|
82
83
|
|
83
84
|
options[:db] = db.to_i if db
|
84
85
|
options[:namespace] = namespace if namespace
|
85
86
|
end
|
87
|
+
|
88
|
+
if uri.user && !uri.user.empty?
|
89
|
+
options[:username] = uri.user
|
90
|
+
end
|
91
|
+
|
92
|
+
options[:password] = CGI.unescape(uri.password.to_s) if uri.password
|
93
|
+
|
86
94
|
if uri.query
|
87
95
|
query = Hash[URI.decode_www_form(uri.query)]
|
88
96
|
query.each do |(key, value)|
|
data/lib/redis/store/version.rb
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
class Redis
|
2
2
|
class Store < self
|
3
|
-
VERSION = '1.
|
3
|
+
VERSION = '1.11.0'
|
4
|
+
|
5
|
+
def self.redis_client_defined?
|
6
|
+
# Doesn't work if declared as constant
|
7
|
+
# due to unpredictable gem loading order
|
8
|
+
# https://github.com/redis-rb/redis-client
|
9
|
+
defined?(::RedisClient::VERSION)
|
10
|
+
end
|
4
11
|
end
|
5
12
|
end
|
data/lib/redis/store.rb
CHANGED
@@ -14,9 +14,13 @@ class Redis
|
|
14
14
|
include Ttl, Interface, RedisVersion
|
15
15
|
|
16
16
|
def initialize(options = {})
|
17
|
-
|
17
|
+
orig_options = options.dup
|
18
18
|
|
19
|
-
|
19
|
+
_remove_unsupported_options(options)
|
20
|
+
# The options here is updated
|
21
|
+
super(options)
|
22
|
+
|
23
|
+
unless orig_options[:marshalling].nil?
|
20
24
|
puts %(
|
21
25
|
DEPRECATED: You are passing the :marshalling option, which has been
|
22
26
|
replaced with `serializer: Marshal` to support pluggable serialization
|
@@ -27,14 +31,15 @@ class Redis
|
|
27
31
|
)
|
28
32
|
end
|
29
33
|
|
30
|
-
@serializer =
|
34
|
+
@serializer = orig_options.key?(:serializer) ? orig_options.delete(:serializer) : Marshal
|
31
35
|
|
32
|
-
unless
|
33
|
-
|
36
|
+
unless orig_options[:marshalling].nil?
|
37
|
+
# `marshalling` only used here, might not be supported in `super`
|
38
|
+
@serializer = orig_options.delete(:marshalling) ? Marshal : nil
|
34
39
|
end
|
35
40
|
|
36
|
-
_extend_marshalling
|
37
|
-
_extend_namespace
|
41
|
+
_extend_marshalling
|
42
|
+
_extend_namespace orig_options
|
38
43
|
end
|
39
44
|
|
40
45
|
def reconnect
|
@@ -56,7 +61,21 @@ class Redis
|
|
56
61
|
end
|
57
62
|
|
58
63
|
private
|
59
|
-
def
|
64
|
+
def _remove_unsupported_options(options)
|
65
|
+
return unless self.class.redis_client_defined?
|
66
|
+
|
67
|
+
# Unsupported keywords should be removed to avoid errors
|
68
|
+
# https://github.com/redis-rb/redis-client/blob/v0.13.0/lib/redis_client/config.rb#L21
|
69
|
+
options.delete(:raw)
|
70
|
+
options.delete(:serializer)
|
71
|
+
options.delete(:marshalling)
|
72
|
+
options.delete(:namespace)
|
73
|
+
options.delete(:scheme)
|
74
|
+
# Redis ACL support added in https://github.com/redis/redis-rb/pull/967
|
75
|
+
options.delete(:username) unless Gem::Version.new(Redis::VERSION) >= Gem::Version.new("4.3.0")
|
76
|
+
end
|
77
|
+
|
78
|
+
def _extend_marshalling
|
60
79
|
extend Serialization unless @serializer.nil?
|
61
80
|
end
|
62
81
|
|
data/redis-store.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
|
21
21
|
s.add_development_dependency 'rake', '>= 12.3.3'
|
22
22
|
s.add_development_dependency 'bundler'
|
23
|
-
s.add_development_dependency 'mocha', '~>
|
23
|
+
s.add_development_dependency 'mocha', '~> 2.1.0'
|
24
24
|
s.add_development_dependency 'minitest', '~> 5'
|
25
25
|
s.add_development_dependency 'git', '~> 1.2'
|
26
26
|
s.add_development_dependency 'pry-nav', '~> 0.2.4'
|
@@ -17,7 +17,7 @@ describe "Redis::DistributedStore" do
|
|
17
17
|
|
18
18
|
it "accepts connection params" do
|
19
19
|
dmr = Redis::DistributedStore.new [ :host => "localhost", :port => "6380", :db => "1" ]
|
20
|
-
dmr.ring.nodes.size
|
20
|
+
_(dmr.ring.nodes.size).must_equal(1)
|
21
21
|
mr = dmr.ring.nodes.first
|
22
22
|
_(mr.to_s).must_equal("Redis Client connected to localhost:6380 against DB 1")
|
23
23
|
end
|
@@ -7,7 +7,8 @@ describe "Redis::Store::Factory" do
|
|
7
7
|
it "instantiates Redis::Store" do
|
8
8
|
store = Redis::Store::Factory.create
|
9
9
|
_(store).must_be_kind_of(Redis::Store)
|
10
|
-
|
10
|
+
# `redis.rb` use different default host values in v4 & v5
|
11
|
+
_(store.to_s).must_match(%r{^Redis Client connected to (127.0.0.1|localhost):6379 against DB 0$})
|
11
12
|
end
|
12
13
|
end
|
13
14
|
|
@@ -24,7 +25,9 @@ describe "Redis::Store::Factory" do
|
|
24
25
|
|
25
26
|
it "uses specified scheme" do
|
26
27
|
store = Redis::Store::Factory.create :scheme => "rediss"
|
27
|
-
|
28
|
+
client = store.instance_variable_get(:@client)
|
29
|
+
# `redis-client` does NOT have `scheme`
|
30
|
+
client.respond_to?(:scheme) && _(client.scheme).must_equal('rediss')
|
28
31
|
end
|
29
32
|
|
30
33
|
it "uses specified path" do
|
@@ -39,12 +42,14 @@ describe "Redis::Store::Factory" do
|
|
39
42
|
|
40
43
|
it "uses specified namespace" do
|
41
44
|
store = Redis::Store::Factory.create :namespace => "theplaylist"
|
42
|
-
|
45
|
+
# `redis.rb` use different default host values in v4 & v5
|
46
|
+
_(store.to_s).must_match(%r{^Redis Client connected to (127.0.0.1|localhost):6379 against DB 0 with namespace theplaylist$})
|
43
47
|
end
|
44
48
|
|
45
49
|
it "uses specified key_prefix as namespace" do
|
46
50
|
store = Redis::Store::Factory.create :key_prefix => "theplaylist"
|
47
|
-
|
51
|
+
# `redis.rb` use different default host values in v4 & v5
|
52
|
+
_(store.to_s).must_match(%r{^Redis Client connected to (127.0.0.1|localhost):6379 against DB 0 with namespace theplaylist$})
|
48
53
|
end
|
49
54
|
|
50
55
|
it "uses specified password" do
|
@@ -65,19 +70,22 @@ describe "Redis::Store::Factory" do
|
|
65
70
|
it "disables serialization" do
|
66
71
|
store = Redis::Store::Factory.create :serializer => nil
|
67
72
|
_(store.instance_variable_get(:@serializer)).must_be_nil
|
68
|
-
|
73
|
+
# `raw` would be removed when `redis-client` is used
|
74
|
+
defined?(::RedisClient) || _(store.instance_variable_get(:@options)[:raw]).must_equal(true)
|
69
75
|
end
|
70
76
|
|
71
77
|
it "configures pluggable serialization backend" do
|
72
78
|
store = Redis::Store::Factory.create :serializer => JSON
|
73
79
|
_(store.instance_variable_get(:@serializer)).must_equal(JSON)
|
74
|
-
|
80
|
+
# `raw` would be removed when `redis-client` is used
|
81
|
+
defined?(::RedisClient) || _(store.instance_variable_get(:@options)[:raw]).must_equal(false)
|
75
82
|
end
|
76
83
|
|
77
84
|
describe "defaults" do
|
78
85
|
it "defaults to localhost if no host specified" do
|
79
86
|
store = Redis::Store::Factory.create
|
80
|
-
|
87
|
+
# `redis.rb` use different default host values in v4 & v5
|
88
|
+
_(store.instance_variable_get(:@client).host).must_match(%r{^127.0.0.1|localhost$})
|
81
89
|
end
|
82
90
|
|
83
91
|
it "defaults to 6379 if no port specified" do
|
@@ -87,7 +95,9 @@ describe "Redis::Store::Factory" do
|
|
87
95
|
|
88
96
|
it "defaults to redis:// if no scheme specified" do
|
89
97
|
store = Redis::Store::Factory.create
|
90
|
-
|
98
|
+
client = store.instance_variable_get(:@client)
|
99
|
+
# `redis-client` does NOT have `scheme`
|
100
|
+
client.respond_to?(:scheme) && _(client.scheme).must_equal('redis')
|
91
101
|
end
|
92
102
|
end
|
93
103
|
|
@@ -103,13 +113,15 @@ describe "Redis::Store::Factory" do
|
|
103
113
|
it "disables marshalling and provides deprecation warning" do
|
104
114
|
store = Redis::Store::Factory.create :marshalling => false
|
105
115
|
_(store.instance_variable_get(:@serializer)).must_be_nil
|
106
|
-
|
116
|
+
# `raw` would be removed when `redis-client` is used
|
117
|
+
defined?(::RedisClient) || _(store.instance_variable_get(:@options)[:raw]).must_equal(true)
|
107
118
|
end
|
108
119
|
|
109
120
|
it "enables marshalling but provides warning to use :serializer instead" do
|
110
121
|
store = Redis::Store::Factory.create :marshalling => true
|
111
122
|
_(store.instance_variable_get(:@serializer)).must_equal(Marshal)
|
112
|
-
|
123
|
+
# `raw` would be removed when `redis-client` is used
|
124
|
+
defined?(::RedisClient) || _(store.instance_variable_get(:@options)[:raw]).must_equal(false)
|
113
125
|
end
|
114
126
|
|
115
127
|
after do
|
@@ -135,6 +147,13 @@ describe "Redis::Store::Factory" do
|
|
135
147
|
it "uses specified host" do
|
136
148
|
store = Redis::Store::Factory.create "redis://127.0.0.1"
|
137
149
|
_(store.to_s).must_equal("Redis Client connected to 127.0.0.1:6379 against DB 0")
|
150
|
+
client = store.instance_variable_get(:@client)
|
151
|
+
|
152
|
+
if Gem::Version.new(Redis::VERSION) >= Gem::Version.new('5.0.0')
|
153
|
+
assert_equal(false, client.instance_variable_get(:@config).instance_variable_get(:@ssl))
|
154
|
+
else
|
155
|
+
assert_equal(false, client.options[:ssl])
|
156
|
+
end
|
138
157
|
end
|
139
158
|
|
140
159
|
it "uses specified port" do
|
@@ -144,12 +163,23 @@ describe "Redis::Store::Factory" do
|
|
144
163
|
|
145
164
|
it "uses specified scheme" do
|
146
165
|
store = Redis::Store::Factory.create "rediss://127.0.0.1:6380"
|
147
|
-
|
166
|
+
client = store.instance_variable_get(:@client)
|
167
|
+
# `redis-client` does NOT have `scheme`
|
168
|
+
client.respond_to?(:scheme) && _(client.scheme).must_equal('rediss')
|
169
|
+
|
170
|
+
if Gem::Version.new(Redis::VERSION) >= Gem::Version.new('5.0.0')
|
171
|
+
# binding.irb
|
172
|
+
assert_equal(true, client.instance_variable_get(:@config).instance_variable_get(:@ssl))
|
173
|
+
else
|
174
|
+
assert_equal(true, client.options[:ssl])
|
175
|
+
end
|
148
176
|
end
|
149
177
|
|
150
178
|
it "correctly defaults to redis:// when relative scheme specified" do
|
151
179
|
store = Redis::Store::Factory.create "//127.0.0.1:6379"
|
152
|
-
|
180
|
+
client = store.instance_variable_get(:@client)
|
181
|
+
# `redis-client` does NOT have `scheme`
|
182
|
+
client.respond_to?(:scheme) && _(client.scheme).must_equal('redis')
|
153
183
|
end
|
154
184
|
|
155
185
|
it "uses specified path" do
|
@@ -182,6 +212,28 @@ describe "Redis::Store::Factory" do
|
|
182
212
|
_(store.instance_variable_get(:@client).password).must_equal("secret")
|
183
213
|
end
|
184
214
|
|
215
|
+
if Gem::Version.new(Redis::VERSION) >= Gem::Version.new("4.3.0")
|
216
|
+
it "uses specified path with username and password" do
|
217
|
+
store = Redis::Store::Factory.create "unix://test-user:secret@/var/run/redis.sock"
|
218
|
+
_(store.instance_variable_get(:@client).username).must_equal("test-user")
|
219
|
+
_(store.instance_variable_get(:@client).password).must_equal("secret")
|
220
|
+
end
|
221
|
+
|
222
|
+
it "uses specified username and password" do
|
223
|
+
store = Redis::Store::Factory.create "redis://test-user:secret@127.0.0.1:6379/0/theplaylist"
|
224
|
+
_(store.instance_variable_get(:@client).username).must_equal("test-user")
|
225
|
+
_(store.instance_variable_get(:@client).password).must_equal("secret")
|
226
|
+
end
|
227
|
+
|
228
|
+
it "uses a default username" do
|
229
|
+
store = Redis::Store::Factory.create "redis://:secret@127.0.0.1:6379/0/theplaylist"
|
230
|
+
username = Gem::Version.new(Redis::VERSION) >= Gem::Version.new("5.0") ? "default" : nil
|
231
|
+
|
232
|
+
_(store.instance_variable_get(:@client).username).must_equal(username)
|
233
|
+
_(store.instance_variable_get(:@client).password).must_equal("secret")
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
185
237
|
it 'uses specified password with special characters' do
|
186
238
|
store = Redis::Store::Factory.create 'redis://:pwd%40123@127.0.0.1:6379/0/theplaylist'
|
187
239
|
_(store.instance_variable_get(:@client).password).must_equal('pwd@123')
|
@@ -215,7 +267,7 @@ describe "Redis::Store::Factory" do
|
|
215
267
|
|
216
268
|
describe 'when given host Hash and options Hash' do
|
217
269
|
it 'instantiates Redis::Store and merges options' do
|
218
|
-
|
270
|
+
Redis::Store::Factory.create(
|
219
271
|
{ :host => '127.0.0.1', :port => '6379' },
|
220
272
|
{ :namespace => 'theplaylist' }
|
221
273
|
)
|
@@ -249,7 +301,7 @@ describe "Redis::Store::Factory" do
|
|
249
301
|
end
|
250
302
|
|
251
303
|
it 'instantiates Redis::Store and sets namespace from String' do
|
252
|
-
store = Redis::Store::Factory.create "redis://127.0.0.1:6379/0/theplaylist"
|
304
|
+
store = Redis::Store::Factory.create "redis://127.0.0.1:6379/0/theplaylist"
|
253
305
|
_(store.to_s).must_equal("Redis Client connected to 127.0.0.1:6379 against DB 0 with namespace theplaylist")
|
254
306
|
end
|
255
307
|
end
|
@@ -25,7 +25,9 @@ describe "Redis::Store::Namespace" do
|
|
25
25
|
it "only decorates instances that need to be namespaced" do
|
26
26
|
store = Redis::Store.new
|
27
27
|
client = store.instance_variable_get(:@client)
|
28
|
-
|
28
|
+
# `call_v` used since redis-rb 5.0
|
29
|
+
client_call_method_name = client.respond_to?(:call_v) ? :call_v : :call
|
30
|
+
client.expects(client_call_method_name).with([:get, "rabbit"])
|
29
31
|
store.get("rabbit")
|
30
32
|
end
|
31
33
|
|
@@ -46,7 +48,8 @@ describe "Redis::Store::Namespace" do
|
|
46
48
|
@default_store.set 'abc', 'cba'
|
47
49
|
@other_store.set 'foo', 'bar'
|
48
50
|
|
49
|
-
_(@default_store.keys
|
51
|
+
_(@default_store.keys).must_include('abc')
|
52
|
+
_(@default_store.keys).must_include('other:foo')
|
50
53
|
|
51
54
|
@default_store.with_namespace(@other_namespace) do
|
52
55
|
_(@default_store.keys).must_equal ['foo']
|
@@ -92,29 +95,33 @@ describe "Redis::Store::Namespace" do
|
|
92
95
|
describe 'method calls' do
|
93
96
|
let(:store) { Redis::Store.new :namespace => @namespace, :serializer => nil }
|
94
97
|
let(:client) { store.instance_variable_get(:@client) }
|
98
|
+
let(:client_call_method_name) do
|
99
|
+
# `call_v` used since redis-rb 5.0
|
100
|
+
client.respond_to?(:call_v) ? :call_v : :call
|
101
|
+
end
|
95
102
|
|
96
103
|
it "should namespace get" do
|
97
|
-
client.expects(
|
104
|
+
client.expects(client_call_method_name).with([:get, "#{@namespace}:rabbit"]).once
|
98
105
|
store.get("rabbit")
|
99
106
|
end
|
100
107
|
|
101
108
|
it "should namespace set" do
|
102
|
-
client.expects(
|
109
|
+
client.expects(client_call_method_name).with([:set, "#{@namespace}:rabbit", @rabbit])
|
103
110
|
store.set "rabbit", @rabbit
|
104
111
|
end
|
105
112
|
|
106
113
|
it "should namespace setnx" do
|
107
|
-
client.expects(
|
114
|
+
client.expects(client_call_method_name).with([:setnx, "#{@namespace}:rabbit", @rabbit])
|
108
115
|
store.setnx "rabbit", @rabbit
|
109
116
|
end
|
110
117
|
|
111
118
|
it "should namespace del with single key" do
|
112
|
-
client.expects(
|
119
|
+
client.expects(client_call_method_name).with([:del, "#{@namespace}:rabbit"])
|
113
120
|
store.del "rabbit"
|
114
121
|
end
|
115
122
|
|
116
123
|
it "should namespace del with multiple keys" do
|
117
|
-
client.expects(
|
124
|
+
client.expects(client_call_method_name).with([:del, "#{@namespace}:rabbit", "#{@namespace}:white_rabbit"])
|
118
125
|
store.del "rabbit", "white_rabbit"
|
119
126
|
end
|
120
127
|
|
@@ -135,29 +142,35 @@ describe "Redis::Store::Namespace" do
|
|
135
142
|
end
|
136
143
|
|
137
144
|
it "should namespace exists" do
|
138
|
-
client.expects(
|
145
|
+
client.expects(client_call_method_name).with([:exists, "#{@namespace}:rabbit"])
|
139
146
|
store.exists "rabbit"
|
140
147
|
end
|
141
148
|
|
142
149
|
it "should namespace incrby" do
|
143
|
-
client.expects(
|
150
|
+
client.expects(client_call_method_name).with([:incrby, "#{@namespace}:counter", 1])
|
144
151
|
store.incrby "counter", 1
|
145
152
|
end
|
146
153
|
|
147
154
|
it "should namespace decrby" do
|
148
|
-
client.expects(
|
155
|
+
client.expects(client_call_method_name).with([:decrby, "#{@namespace}:counter", 1])
|
149
156
|
store.decrby "counter", 1
|
150
157
|
end
|
151
158
|
|
152
159
|
it "should namespace mget" do
|
153
|
-
client.expects(
|
160
|
+
client.expects(client_call_method_name).with([:mget, "#{@namespace}:rabbit", "#{@namespace}:white_rabbit"]).returns(%w[ foo bar ])
|
154
161
|
store.mget "rabbit", "white_rabbit" do |result|
|
155
162
|
_(result).must_equal(%w[ foo bar ])
|
156
163
|
end
|
157
164
|
end
|
158
165
|
|
159
166
|
it "should namespace mapped_mget" do
|
160
|
-
client.
|
167
|
+
if client.respond_to?(:process, true)
|
168
|
+
# Redis < 5.0 uses `#process`
|
169
|
+
client.expects(:process).with([[:mget, "#{@namespace}:rabbit", "#{@namespace}:white_rabbit"]]).returns(%w[ foo bar ])
|
170
|
+
else
|
171
|
+
# Redis 5.x calls `#ensure_connected` (private)
|
172
|
+
client.send(:ensure_connected).expects(:call).returns(%w[ foo bar ])
|
173
|
+
end
|
161
174
|
result = store.mapped_mget "rabbit", "white_rabbit"
|
162
175
|
_(result.keys).must_equal %w[ rabbit white_rabbit ]
|
163
176
|
_(result["rabbit"]).must_equal "foo"
|
@@ -165,108 +178,108 @@ describe "Redis::Store::Namespace" do
|
|
165
178
|
end
|
166
179
|
|
167
180
|
it "should namespace expire" do
|
168
|
-
client.expects(
|
181
|
+
client.expects(client_call_method_name).with([:expire, "#{@namespace}:rabbit", 60]).once
|
169
182
|
store.expire("rabbit", 60)
|
170
183
|
end
|
171
184
|
|
172
185
|
it "should namespace ttl" do
|
173
|
-
client.expects(
|
186
|
+
client.expects(client_call_method_name).with([:ttl, "#{@namespace}:rabbit"]).once
|
174
187
|
store.ttl("rabbit")
|
175
188
|
end
|
176
189
|
|
177
190
|
it "should namespace watch" do
|
178
|
-
client.expects(
|
191
|
+
client.expects(client_call_method_name).with([:watch, "#{@namespace}:rabbit"]).once
|
179
192
|
store.watch("rabbit")
|
180
193
|
end
|
181
194
|
|
182
195
|
it "wraps flushdb with appropriate KEYS * calls" do
|
183
|
-
client.expects(
|
184
|
-
client.expects(
|
185
|
-
client.expects(
|
196
|
+
client.expects(client_call_method_name).with([:flushdb]).never
|
197
|
+
client.expects(client_call_method_name).with([:keys, "#{@namespace}:*"]).once.returns(["rabbit"])
|
198
|
+
client.expects(client_call_method_name).with([:del, "#{@namespace}:rabbit"]).once
|
186
199
|
store.flushdb
|
187
200
|
end
|
188
201
|
|
189
202
|
it "skips flushdb wrapping if the namespace is nil" do
|
190
|
-
client.expects(
|
191
|
-
client.expects(
|
203
|
+
client.expects(client_call_method_name).with([:flushdb])
|
204
|
+
client.expects(client_call_method_name).with([:keys]).never
|
192
205
|
store.with_namespace(nil) do
|
193
206
|
store.flushdb
|
194
207
|
end
|
195
208
|
end
|
196
209
|
|
197
210
|
it "should namespace hdel" do
|
198
|
-
client.expects(
|
211
|
+
client.expects(client_call_method_name).with([:hdel, "#{@namespace}:rabbit", "key1", "key2"]).once
|
199
212
|
store.hdel("rabbit", "key1", "key2")
|
200
213
|
end
|
201
214
|
|
202
215
|
it "should namespace hget" do
|
203
|
-
client.expects(
|
216
|
+
client.expects(client_call_method_name).with([:hget, "#{@namespace}:rabbit", "key"]).once
|
204
217
|
store.hget("rabbit", "key")
|
205
218
|
end
|
206
219
|
|
207
220
|
it "should namespace hgetall" do
|
208
|
-
client.expects(
|
221
|
+
client.expects(client_call_method_name).with([:hgetall, "#{@namespace}:rabbit"]).once
|
209
222
|
store.hgetall("rabbit")
|
210
223
|
end
|
211
224
|
|
212
225
|
it "should namespace hexists" do
|
213
|
-
client.expects(
|
214
|
-
|
226
|
+
client.expects(client_call_method_name).with([:hexists, "#{@namespace}:rabbit", "key"]).once
|
227
|
+
store.hexists("rabbit", "key")
|
215
228
|
end
|
216
229
|
|
217
230
|
it "should namespace hincrby" do
|
218
|
-
client.expects(
|
231
|
+
client.expects(client_call_method_name).with([:hincrby, "#{@namespace}:rabbit", "key", 1]).once
|
219
232
|
store.hincrby("rabbit", "key", 1)
|
220
233
|
end
|
221
234
|
|
222
235
|
it "should namespace hincrbyfloat" do
|
223
|
-
client.expects(
|
224
|
-
store.
|
236
|
+
client.expects(client_call_method_name).with([:hincrbyfloat, "#{@namespace}:rabbit", "key", 1.5]).once
|
237
|
+
store.hincrbyfloat("rabbit", "key", 1.5)
|
225
238
|
end
|
226
239
|
|
227
240
|
it "should namespace hkeys" do
|
228
|
-
client.expects(
|
241
|
+
client.expects(client_call_method_name).with([:hkeys, "#{@namespace}:rabbit"])
|
229
242
|
store.hkeys("rabbit")
|
230
243
|
end
|
231
244
|
|
232
245
|
it "should namespace hlen" do
|
233
|
-
client.expects(
|
246
|
+
client.expects(client_call_method_name).with([:hlen, "#{@namespace}:rabbit"])
|
234
247
|
store.hlen("rabbit")
|
235
248
|
end
|
236
249
|
|
237
250
|
it "should namespace hmget" do
|
238
|
-
client.expects(
|
251
|
+
client.expects(client_call_method_name).with([:hmget, "#{@namespace}:rabbit", "key1", "key2"])
|
239
252
|
store.hmget("rabbit", "key1", "key2")
|
240
253
|
end
|
241
254
|
|
242
255
|
it "should namespace hmset" do
|
243
|
-
client.expects(
|
256
|
+
client.expects(client_call_method_name).with([:hmset, "#{@namespace}:rabbit", "key", @rabbit])
|
244
257
|
store.hmset("rabbit", "key", @rabbit)
|
245
258
|
end
|
246
259
|
|
247
260
|
it "should namespace hset" do
|
248
|
-
client.expects(
|
261
|
+
client.expects(client_call_method_name).with([:hset, "#{@namespace}:rabbit", "key", @rabbit])
|
249
262
|
store.hset("rabbit", "key", @rabbit)
|
250
263
|
end
|
251
264
|
|
252
265
|
it "should namespace hsetnx" do
|
253
|
-
client.expects(
|
266
|
+
client.expects(client_call_method_name).with([:hsetnx, "#{@namespace}:rabbit", "key", @rabbit])
|
254
267
|
store.hsetnx("rabbit", "key", @rabbit)
|
255
268
|
end
|
256
269
|
|
257
270
|
it "should namespace hvals" do
|
258
|
-
client.expects(
|
271
|
+
client.expects(client_call_method_name).with([:hvals, "#{@namespace}:rabbit"])
|
259
272
|
store.hvals("rabbit")
|
260
273
|
end
|
261
274
|
|
262
275
|
it "should namespace hscan" do
|
263
|
-
client.expects(
|
276
|
+
client.expects(client_call_method_name).with([:hscan, "#{@namespace}:rabbit", 0])
|
264
277
|
store.hscan("rabbit", 0)
|
265
278
|
end
|
266
279
|
|
267
280
|
it "should namespace hscan_each with block" do
|
268
|
-
client.
|
269
|
-
client.expects(
|
281
|
+
client.public_send(client_call_method_name, [:hset, "#{@namespace}:rabbit", "key1", @rabbit])
|
282
|
+
client.expects(client_call_method_name).with([:hscan, "#{@namespace}:rabbit", 0]).returns(["0", ["key1"]])
|
270
283
|
results = []
|
271
284
|
store.hscan_each("rabbit") do |key|
|
272
285
|
results << key
|
@@ -275,29 +288,29 @@ describe "Redis::Store::Namespace" do
|
|
275
288
|
end
|
276
289
|
|
277
290
|
it "should namespace hscan_each without block" do
|
278
|
-
client.
|
279
|
-
client.expects(
|
291
|
+
client.public_send(client_call_method_name, [:hset, "#{@namespace}:rabbit", "key1", @rabbit])
|
292
|
+
client.expects(client_call_method_name).with([:hscan, "#{@namespace}:rabbit", 0]).returns(["0", ["key1"]])
|
280
293
|
results = store.hscan_each("rabbit").to_a
|
281
294
|
_(results).must_equal(["key1"])
|
282
295
|
end
|
283
296
|
|
284
297
|
it "should namespace zincrby" do
|
285
|
-
client.expects(
|
298
|
+
client.expects(client_call_method_name).with([:zincrby, "#{@namespace}:rabbit", 1.0, "member"])
|
286
299
|
store.zincrby("rabbit", 1.0, "member")
|
287
300
|
end
|
288
301
|
|
289
302
|
it "should namespace zscore" do
|
290
|
-
client.expects(
|
303
|
+
client.expects(client_call_method_name).with([:zscore, "#{@namespace}:rabbit", "member"])
|
291
304
|
store.zscore("rabbit", "member")
|
292
305
|
end
|
293
306
|
|
294
307
|
it "should namespace zadd" do
|
295
|
-
client.expects(
|
308
|
+
client.expects(client_call_method_name).with([:zadd, "#{@namespace}:rabbit", 1.0, "member"])
|
296
309
|
store.zadd("rabbit", 1.0, "member")
|
297
310
|
end
|
298
311
|
|
299
312
|
it "should namespace zrem" do
|
300
|
-
client.expects(
|
313
|
+
client.expects(client_call_method_name).with([:zrem, "#{@namespace}:rabbit", "member"])
|
301
314
|
store.zrem("rabbit", "member")
|
302
315
|
end
|
303
316
|
end
|
@@ -29,7 +29,7 @@ describe "Redis::Serialization" do
|
|
29
29
|
_(@store.get("rabbit2")).must_equal(@rabbit)
|
30
30
|
end
|
31
31
|
|
32
|
-
if RUBY_VERSION.match
|
32
|
+
if RUBY_VERSION.match(/1\.9/)
|
33
33
|
it "doesn't unmarshal on get if raw option is true" do
|
34
34
|
_(@store.get("rabbit", :raw => true)).must_equal("\x04\bU:\x0FOpenStruct{\x06:\tnameI\"\nbunny\x06:\x06EF")
|
35
35
|
end
|
@@ -117,7 +117,7 @@ describe "Redis::Serialization" do
|
|
117
117
|
_(result["rabbit2"]).must_equal @white_rabbit
|
118
118
|
end
|
119
119
|
|
120
|
-
if RUBY_VERSION.match
|
120
|
+
if RUBY_VERSION.match(/1\.9/)
|
121
121
|
it "doesn't unmarshal on multi get if raw option is true" do
|
122
122
|
@store.set "rabbit2", @white_rabbit
|
123
123
|
@store.mget "rabbit", "rabbit2", :raw => true do |rabbit, rabbit2|
|
data/test/redis/store_test.rb
CHANGED
@@ -43,7 +43,7 @@ describe Redis::Store do
|
|
43
43
|
@store.del(key)
|
44
44
|
_(@store.set(key, mock_value, {})).must_equal 'OK'
|
45
45
|
_(@store.set(key, mock_value, {})).must_equal 'OK'
|
46
|
-
_(@store.ttl(key)).must_equal
|
46
|
+
_(@store.ttl(key)).must_equal(-1)
|
47
47
|
|
48
48
|
# with ex and nx options, the key can only be set once and a ttl will be set
|
49
49
|
@store.del(key)
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Guidi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -64,14 +64,14 @@ dependencies:
|
|
64
64
|
requirements:
|
65
65
|
- - "~>"
|
66
66
|
- !ruby/object:Gem::Version
|
67
|
-
version:
|
67
|
+
version: 2.1.0
|
68
68
|
type: :development
|
69
69
|
prerelease: false
|
70
70
|
version_requirements: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
72
|
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
|
-
version:
|
74
|
+
version: 2.1.0
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
76
|
name: minitest
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -237,7 +237,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
237
237
|
- !ruby/object:Gem::Version
|
238
238
|
version: '0'
|
239
239
|
requirements: []
|
240
|
-
rubygems_version: 3.
|
240
|
+
rubygems_version: 3.5.11
|
241
241
|
signing_key:
|
242
242
|
specification_version: 4
|
243
243
|
summary: Redis stores for Ruby frameworks
|