redis-store 1.1.7 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of redis-store might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/README.md +1 -1
- data/lib/redis/distributed_store.rb +4 -0
- data/lib/redis/store/interface.rb +1 -1
- data/lib/redis/store/marshalling.rb +3 -3
- data/lib/redis/store/namespace.rb +32 -20
- data/lib/redis/store/ttl.rb +1 -1
- data/lib/redis/store/version.rb +1 -1
- data/lib/redis/store.rb +1 -1
- data/test/redis/store/marshalling_test.rb +18 -0
- data/test/redis/store/namespace_test.rb +14 -1
- data/test/redis/store/ttl_test.rb +9 -1
- data/test/redis/store/version_test.rb +1 -1
- data/test/redis/store_test.rb +22 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fdc1ba61b75205e6f17d1bb790c3324d98335abb
|
4
|
+
data.tar.gz: 95cf5013e84b74ef20e9041c971cce5773411ec3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42f21ac1f963af2a5e96a145672ec97d670dc7bfe94dba63eeda69a1bd37567effb5f2d60a09d4f0871f9ded839318de092b88221189e955dd91191adb20c260
|
7
|
+
data.tar.gz: 488d11620f6f0c2a8ea615825056c199e0267386d374d9d91891c648fe1420739858c7f75cb3c1afafebabe22fa2ffdb99c7c77b33bd46def781a68709c6f15b
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -21,7 +21,7 @@ Download and install Redis from [the download page](http://redis.io//download) a
|
|
21
21
|
## Running tests
|
22
22
|
|
23
23
|
```ruby
|
24
|
-
git clone git://github.com/
|
24
|
+
git clone git://github.com/redis-store/redis-store.git
|
25
25
|
cd redis-store
|
26
26
|
gem install bundler
|
27
27
|
bundle exec rake
|
@@ -2,15 +2,15 @@ class Redis
|
|
2
2
|
class Store < self
|
3
3
|
module Marshalling
|
4
4
|
def set(key, value, options = nil)
|
5
|
-
_marshal(value, options) { |
|
5
|
+
_marshal(value, options) { |v| super encode(key), encode(v), options }
|
6
6
|
end
|
7
7
|
|
8
8
|
def setnx(key, value, options = nil)
|
9
|
-
_marshal(value, options) { |
|
9
|
+
_marshal(value, options) { |v| super encode(key), encode(v), options }
|
10
10
|
end
|
11
11
|
|
12
12
|
def setex(key, expiry, value, options = nil)
|
13
|
-
_marshal(value, options) { |
|
13
|
+
_marshal(value, options) { |v| super encode(key), expiry, encode(v), options }
|
14
14
|
end
|
15
15
|
|
16
16
|
def get(key, options = nil)
|
@@ -1,44 +1,46 @@
|
|
1
1
|
class Redis
|
2
2
|
class Store < self
|
3
3
|
module Namespace
|
4
|
+
FLUSHDB_BATCH_SIZE = 1000
|
5
|
+
|
4
6
|
def set(key, val, options = nil)
|
5
|
-
namespace(key) { |
|
7
|
+
namespace(key) { |k| super(k, val, options) }
|
6
8
|
end
|
7
9
|
|
8
10
|
def setex(key, ttl, val, options = nil)
|
9
|
-
namespace(key) { |
|
11
|
+
namespace(key) { |k| super(k, ttl, val, options) }
|
10
12
|
end
|
11
13
|
|
12
14
|
def setnx(key, val, options = nil)
|
13
|
-
namespace(key) { |
|
15
|
+
namespace(key) { |k| super(k, val, options) }
|
14
16
|
end
|
15
17
|
|
16
18
|
def ttl(key, options = nil)
|
17
|
-
namespace(key) { |
|
19
|
+
namespace(key) { |k| super(k) }
|
18
20
|
end
|
19
21
|
|
20
22
|
def get(key, options = nil)
|
21
|
-
namespace(key) { |
|
23
|
+
namespace(key) { |k| super(k, options) }
|
22
24
|
end
|
23
25
|
|
24
26
|
def exists(key)
|
25
|
-
namespace(key) { |
|
27
|
+
namespace(key) { |k| super(k) }
|
26
28
|
end
|
27
29
|
|
28
30
|
def incrby(key, increment)
|
29
|
-
namespace(key) { |
|
31
|
+
namespace(key) { |k| super(k, increment) }
|
30
32
|
end
|
31
33
|
|
32
34
|
def decrby(key, increment)
|
33
|
-
namespace(key) { |
|
35
|
+
namespace(key) { |k| super(k, increment) }
|
34
36
|
end
|
35
37
|
|
36
38
|
def keys(pattern = "*")
|
37
|
-
namespace(pattern) { |
|
39
|
+
namespace(pattern) { |p| super(p).map{|key| strip_namespace(key) } }
|
38
40
|
end
|
39
41
|
|
40
42
|
def del(*keys)
|
41
|
-
super
|
43
|
+
super(*keys.map {|key| interpolate(key) }) if keys.any?
|
42
44
|
end
|
43
45
|
|
44
46
|
def mget(*keys)
|
@@ -46,27 +48,35 @@ class Redis
|
|
46
48
|
if keys.any?
|
47
49
|
# Marshalling gets extended before Namespace does, so we need to pass options further
|
48
50
|
if singleton_class.ancestors.include? Marshalling
|
49
|
-
super
|
51
|
+
super(*keys.map {|key| interpolate(key) }, options)
|
50
52
|
else
|
51
|
-
super
|
53
|
+
super(*keys.map {|key| interpolate(key) })
|
52
54
|
end
|
53
55
|
end
|
54
56
|
end
|
55
|
-
|
57
|
+
|
56
58
|
def expire(key, ttl)
|
57
|
-
namespace(key) { |
|
58
|
-
end
|
59
|
-
|
60
|
-
def ttl(key)
|
61
|
-
namespace(key) { |key| super(key) }
|
59
|
+
namespace(key) { |k| super(k, ttl) }
|
62
60
|
end
|
63
61
|
|
64
62
|
def to_s
|
65
|
-
|
63
|
+
if namespace_str
|
64
|
+
"#{super} with namespace #{namespace_str}"
|
65
|
+
else
|
66
|
+
super
|
67
|
+
end
|
66
68
|
end
|
67
69
|
|
68
70
|
def flushdb
|
69
|
-
del
|
71
|
+
keys.each_slice(FLUSHDB_BATCH_SIZE) { |key_slice| del(*key_slice) }
|
72
|
+
end
|
73
|
+
|
74
|
+
def with_namespace(ns)
|
75
|
+
old_ns = @namespace
|
76
|
+
@namespace = ns
|
77
|
+
yield self
|
78
|
+
ensure
|
79
|
+
@namespace = old_ns
|
70
80
|
end
|
71
81
|
|
72
82
|
private
|
@@ -79,10 +89,12 @@ class Redis
|
|
79
89
|
end
|
80
90
|
|
81
91
|
def interpolate(key)
|
92
|
+
return key unless namespace_str
|
82
93
|
key.match(namespace_regexp) ? key : "#{namespace_str}:#{key}"
|
83
94
|
end
|
84
95
|
|
85
96
|
def strip_namespace(key)
|
97
|
+
return key unless namespace_str
|
86
98
|
key.gsub namespace_regexp, ""
|
87
99
|
end
|
88
100
|
|
data/lib/redis/store/ttl.rb
CHANGED
data/lib/redis/store/version.rb
CHANGED
data/lib/redis/store.rb
CHANGED
@@ -67,6 +67,24 @@ describe "Redis::Marshalling" do
|
|
67
67
|
@store.get("rabbit2").must_be_nil
|
68
68
|
end
|
69
69
|
|
70
|
+
it "marshals setex (over a distributed store)" do
|
71
|
+
@store = Redis::DistributedStore.new [
|
72
|
+
{:host => "localhost", :port => "6380", :db => 0},
|
73
|
+
{:host => "localhost", :port => "6381", :db => 0}
|
74
|
+
]
|
75
|
+
@store.setex "rabbit", 50, @white_rabbit
|
76
|
+
@store.get("rabbit").must_equal(@white_rabbit)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "doesn't marshal setex if raw option is true (over a distributed store)" do
|
80
|
+
@store = Redis::DistributedStore.new [
|
81
|
+
{:host => "localhost", :port => "6380", :db => 0},
|
82
|
+
{:host => "localhost", :port => "6381", :db => 0}
|
83
|
+
]
|
84
|
+
@store.setex "rabbit", 50, @white_rabbit, :raw => true
|
85
|
+
@store.get("rabbit", :raw => true).must_equal(%(#<OpenStruct color="white">))
|
86
|
+
end
|
87
|
+
|
70
88
|
it "doesn't unmarshal on multi get" do
|
71
89
|
@store.set "rabbit2", @white_rabbit
|
72
90
|
rabbit, rabbit2 = @store.mget "rabbit", "rabbit2"
|
@@ -7,7 +7,8 @@ describe "Redis::Store::Namespace" do
|
|
7
7
|
@client = @store.instance_variable_get(:@client)
|
8
8
|
@rabbit = "bunny"
|
9
9
|
@default_store = Redis::Store.new
|
10
|
-
@
|
10
|
+
@other_namespace = 'other'
|
11
|
+
@other_store = Redis::Store.new :namespace => @other_namespace
|
11
12
|
end
|
12
13
|
|
13
14
|
def teardown
|
@@ -41,6 +42,18 @@ describe "Redis::Store::Namespace" do
|
|
41
42
|
@default_store.get('abc').must_equal('cba')
|
42
43
|
end
|
43
44
|
|
45
|
+
it 'should allow to change namespace on the fly' do
|
46
|
+
@default_store.set 'abc', 'cba'
|
47
|
+
@other_store.set 'foo', 'bar'
|
48
|
+
|
49
|
+
@default_store.keys.sort.must_equal ['abc', 'other:foo']
|
50
|
+
|
51
|
+
@default_store.with_namespace(@other_namespace) do
|
52
|
+
@default_store.keys.must_equal ['foo']
|
53
|
+
@default_store.get('foo').must_equal('bar')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
44
57
|
it "should not try to delete missing namespaced keys" do
|
45
58
|
empty_store = Redis::Store.new :namespace => 'empty'
|
46
59
|
empty_store.flushdb
|
@@ -66,7 +66,7 @@ describe MockTtlStore do
|
|
66
66
|
describe 'without options' do
|
67
67
|
it 'must call super with key and value' do
|
68
68
|
redis.set(key, mock_value)
|
69
|
-
redis.has_set?(key, mock_value).must_equal true
|
69
|
+
redis.has_set?(key, mock_value, nil).must_equal true
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
@@ -76,6 +76,14 @@ describe MockTtlStore do
|
|
76
76
|
redis.has_setex?(key, options[:expire_after], mock_value, :raw => true).must_equal true
|
77
77
|
end
|
78
78
|
end
|
79
|
+
|
80
|
+
describe 'with nx and ex option' do
|
81
|
+
it 'must call super with key and value and options' do
|
82
|
+
set_options = {nx: true, ex: 3600}
|
83
|
+
redis.set(key, mock_value, set_options)
|
84
|
+
redis.has_set?(key, mock_value, set_options).must_equal true
|
85
|
+
end
|
86
|
+
end
|
79
87
|
end
|
80
88
|
|
81
89
|
describe '#setnx' do
|
data/test/redis/store_test.rb
CHANGED
@@ -30,6 +30,28 @@ describe Redis::Store do
|
|
30
30
|
@store.set('key', 'value', options)
|
31
31
|
end
|
32
32
|
end
|
33
|
+
|
34
|
+
describe 'with ex and nx' do
|
35
|
+
let(:key) { 'key' }
|
36
|
+
let(:mock_value) { 'value' }
|
37
|
+
let(:options) { { nx: true, ex: 3600 } }
|
38
|
+
|
39
|
+
it 'must pass on options' do
|
40
|
+
Marshal.expects(:dump).times(4)
|
41
|
+
|
42
|
+
# without options no ex or nx will be set
|
43
|
+
@store.del(key)
|
44
|
+
@store.set(key, mock_value, {}).must_equal 'OK'
|
45
|
+
@store.set(key, mock_value, {}).must_equal 'OK'
|
46
|
+
@store.ttl(key).must_equal -1
|
47
|
+
|
48
|
+
# with ex and nx options, the key can only be set once and a ttl will be set
|
49
|
+
@store.del(key)
|
50
|
+
@store.set(key, mock_value, options).must_equal true
|
51
|
+
@store.set(key, mock_value, options).must_equal false
|
52
|
+
@store.ttl(key).must_equal 3600
|
53
|
+
end
|
54
|
+
end
|
33
55
|
end
|
34
56
|
|
35
57
|
describe '#setnx' do
|
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.2.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: 2016-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -164,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
164
164
|
version: '0'
|
165
165
|
requirements: []
|
166
166
|
rubyforge_project: redis-store
|
167
|
-
rubygems_version: 2.
|
167
|
+
rubygems_version: 2.5.1
|
168
168
|
signing_key:
|
169
169
|
specification_version: 4
|
170
170
|
summary: Redis stores for Ruby frameworks
|