redis-store 1.1.7 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c34d0f4a72ee0603e5b2ef2b95808baac398b667
4
- data.tar.gz: e4805c9cd1bfd2cffc6504e36bddf00c80b0ce45
3
+ metadata.gz: fcf8af10e3ba000726fa40f3633c0bd725f3c1f1
4
+ data.tar.gz: c51a300a95250fb34af534d1d3f427122baf919a
5
5
  SHA512:
6
- metadata.gz: 85aa71788df20715c5878ee1b13c047c5904a2b57fb30f4d69e9235dd61692b8f01671ac112f789f9ea6730a8db3cc188226c036188691a563df0e48964a6f90
7
- data.tar.gz: 9bebac3bac2a0ee4dc94db6f08325ce707a65ca289f36ad049769ed0cbc0ea6c6eba0f8ce8c0786560242f7b6ba683567743738c1d7897669b3909fffe854368
6
+ metadata.gz: f7f5e7c2b314d06103bc76a14cb203bf23815d9b98c2d828d9dad75b7fcaf59761f171daca30ca5e6d780d8bf83107fbd78a8796cdd5215fba0e5f88b8c30133
7
+ data.tar.gz: e849f9d018d464eb359d0bb17c10e1adbecae028e64eb7e99b81d995373d58f25a35980513eaf9c5177e9a47fa1b426e131b59f546e5acb2e421854cee6f440c
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  Gemfile.lock
2
2
  *.gem
3
3
  tmp/
4
+ stdout
data/.travis.yml CHANGED
@@ -1,4 +1,6 @@
1
1
  language: ruby
2
+ sudo: false
3
+ cache: bundler
2
4
  before_install: gem install bundler
3
5
  script: 'bundle exec rake'
4
6
  rvm:
@@ -6,8 +8,8 @@ rvm:
6
8
  - 2.0.0
7
9
  - 2.1
8
10
  - 2.2
11
+ - 2.3.0
9
12
  - ruby-head
10
- - rbx-19mode
11
13
  - jruby-19mode
12
14
  - jruby-head
13
15
  bundler_args: '--path vendor/bundle'
data/CHANGELOG CHANGED
@@ -1,3 +1,56 @@
1
+ # Changelog
2
+
3
+ ## 1.3.0
4
+
5
+ Breaking Changes
6
+
7
+ * None
8
+
9
+ Added
10
+
11
+ * Add support for marshalling mset
12
+
13
+ Fixed
14
+
15
+ * Set :raw => true if marshalling
16
+ * Forward new Hash, not nil, when options are unset
17
+
18
+ ## 1.2.0
19
+
20
+ Breaking Changes
21
+
22
+ * None
23
+
24
+ Added
25
+
26
+ * Allow changing namespaces on the fly
27
+ * Begin testing against ruby 2.3.0
28
+
29
+ Fixed
30
+
31
+ * Use batched deletes for flushdb with a namespace
32
+ * pass set command options to redis
33
+ * bump rbx 2
34
+ * fix setex marshalling for distributed store
35
+ * changes to new url
36
+ * :warning: shadowing outer local variable - key, pattern, value
37
+ * :warning: `*' interpreted as argument prefix
38
+ * Removed duplicated method ttl
39
+
40
+ ## 1.1.7
41
+
42
+ Breaking Changes
43
+
44
+ * None
45
+
46
+ Added
47
+
48
+ * Added redis_version and supports_redis_version? methods to Store and DistributedStore
49
+
50
+ Fixed
51
+
52
+ * Handle minor and patch version correctly as they may be multiple digits
53
+
1
54
  *1.1.6 (July 16, 2015)*
2
55
 
3
56
  https://github.com/redis-store/redis-store/compare/v1.1.5...v1.1.6
@@ -95,7 +148,7 @@ https://github.com/redis-store/redis-store/compare/v1.1.4...v1.1.5
95
148
  - redis-i18n 0.6.0.rc2
96
149
  - redis-rack-cache 1.1.rc3
97
150
  - redis-rails 3.1.3.rc4
98
- - redis-sinatra 1.3.1.rc2
151
+ - redis-sinatra 1.3.1.rc2
99
152
  * Remove redis-actionpack dependency on redis-rack-cache [Matt Horan]
100
153
 
101
154
  *1.1.0 [rc2] (February 3, 2012)*
@@ -144,7 +197,7 @@ https://github.com/redis-store/redis-store/compare/v1.1.4...v1.1.5
144
197
  * Use strict dependencies.
145
198
  * READMEs and Licenses
146
199
  * redis-actionpack now depends on redis-rack-cache
147
- * Redis::Factory.convert_to_redis_client_options => Redis::Factory.resolve.
200
+ * Redis::Factory.convert_to_redis_client_options => Redis::Factory.resolve.
148
201
  * Don't use autoload
149
202
  * Make redis-rack-cache tests to pass again
150
203
  * Target Rack::Cache 1.1 for redis-rack-cache
@@ -172,7 +225,7 @@ https://github.com/redis-store/redis-store/compare/v1.1.4...v1.1.5
172
225
  * Moved Rake test tasks into lib/tasks/redis.tasks.rb, in order to DRY Rake
173
226
  * Testing: Use relative paths when referring to pid files
174
227
  * Autoload modules
175
- * Moved Rake test tasks under lib/ in order to make them accessible to all
228
+ * Moved Rake test tasks under lib/ in order to make them accessible to all
176
229
  * Let the Redis::DistributedStore test to pass
177
230
  * Let Redis Rake tasks to work again
178
231
  * Run tests without dtach
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/jodosha/redis-store.git
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
@@ -31,12 +31,24 @@ If you are on **Snow Leopard** you have to run `env ARCHFLAGS="-arch x86_64" rub
31
31
 
32
32
  ## Contributors
33
33
 
34
- * Matt Horan ([@mhoran](https://github.com/mhoran))
34
+ https://github.com/redis-store/redis-store/graphs/contributors
35
+
36
+ ## Versioning
37
+
38
+ The **redis-store** family of gems uses [Semantic Versioning](http://semver.org), meaning gems depending on **redis-store**
39
+ can be reliably inclusive of any version between the current and the next major. We recommend the following dependency
40
+ in your library's gemspec:
41
+
42
+ ```ruby
43
+ s.add_dependency 'redis-store', '>= 1.4', '< 2'
44
+ ```
35
45
 
36
46
  ## Status
37
47
 
38
- [![Gem Version](https://badge.fury.io/rb/redis-store.png)](http://badge.fury.io/rb/redis-store) [![Build Status](https://secure.travis-ci.org/redis-store/redis-store.png?branch=master)](http://travis-ci.org/jodosha/redis-store?branch=master) [![Code Climate](https://codeclimate.com/github/jodosha/redis-store.png)](https://codeclimate.com/github/redis-store/redis-store)
48
+ [![Gem Version](https://badge.fury.io/rb/redis-store.png)](http://badge.fury.io/rb/redis-store)
49
+ [![Build Status](https://secure.travis-ci.org/redis-store/redis-store.png?branch=master)](http://travis-ci.org/redis-store/redis-store?branch=master)
50
+ [![Code Climate](https://codeclimate.com/github/redis-store/redis-store.png)](https://codeclimate.com/github/redis-store/redis-store)
39
51
 
40
52
  ## Copyright
41
53
 
42
- 2009 - 2013 Luca Guidi - [http://lucaguidi.com](http://lucaguidi.com), released under the MIT license
54
+ 2009 - 2013 Luca Guidi - [http://lucaguidi.com](http://lucaguidi.com), released under the MIT license.
@@ -46,6 +46,10 @@ class Redis
46
46
  end
47
47
  end
48
48
 
49
+ def setex(key, expiry, value, options = nil)
50
+ node_for(key).setex(key, expiry, value, options)
51
+ end
52
+
49
53
  private
50
54
  def _extend_namespace(options)
51
55
  @namespace = options[:namespace]
@@ -50,6 +50,14 @@ class Redis
50
50
  if options.key?(:key_prefix) && !options.key?(:namespace)
51
51
  options[:namespace] = options.delete(:key_prefix) # RailsSessionStore
52
52
  end
53
+ options[:raw] = case
54
+ when options.key?(:serializer)
55
+ options[:serializer].nil?
56
+ when options.key?(:marshalling)
57
+ !options[:marshalling]
58
+ else
59
+ false
60
+ end
53
61
  options
54
62
  end
55
63
 
@@ -70,7 +78,7 @@ class Redis
70
78
  options = {
71
79
  :host => uri.hostname,
72
80
  :port => uri.port || DEFAULT_PORT,
73
- :password => uri.password
81
+ :password => uri.password.nil? ? nil : CGI::unescape(uri.password.to_s)
74
82
  }
75
83
 
76
84
  options[:db] = db.to_i if db
@@ -6,7 +6,7 @@ class Redis
6
6
  end
7
7
 
8
8
  def set(key, value, options = nil)
9
- super(key, value)
9
+ super(key, value, options || {})
10
10
  end
11
11
 
12
12
  def setnx(key, value, options = nil)
@@ -1,72 +1,82 @@
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) { |key| super(key, val, options) }
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) { |key| super(key, ttl, val, options) }
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) { |key| super(key, val, options) }
15
+ namespace(key) { |k| super(k, val, options) }
14
16
  end
15
17
 
16
18
  def ttl(key, options = nil)
17
- namespace(key) { |key| super(key) }
19
+ namespace(key) { |k| super(k) }
18
20
  end
19
21
 
20
22
  def get(key, options = nil)
21
- namespace(key) { |key| super(key, options) }
23
+ namespace(key) { |k| super(k, options) }
22
24
  end
23
25
 
24
26
  def exists(key)
25
- namespace(key) { |key| super(key) }
27
+ namespace(key) { |k| super(k) }
26
28
  end
27
29
 
28
30
  def incrby(key, increment)
29
- namespace(key) { |key| super(key, increment) }
31
+ namespace(key) { |k| super(k, increment) }
30
32
  end
31
33
 
32
34
  def decrby(key, increment)
33
- namespace(key) { |key| super(key, increment) }
35
+ namespace(key) { |k| super(k, increment) }
34
36
  end
35
37
 
36
38
  def keys(pattern = "*")
37
- namespace(pattern) { |pattern| super(pattern).map{|key| strip_namespace(key) } }
39
+ namespace(pattern) { |p| super(p).map{|key| strip_namespace(key) } }
38
40
  end
39
41
 
40
42
  def del(*keys)
41
- super *keys.map {|key| interpolate(key) } if keys.any?
43
+ super(*keys.map {|key| interpolate(key) }) if keys.any?
42
44
  end
43
45
 
44
46
  def mget(*keys)
45
- options = keys.pop if keys.last.is_a? Hash
47
+ options = (keys.pop if keys.last.is_a? Hash) || {}
46
48
  if keys.any?
47
- # Marshalling gets extended before Namespace does, so we need to pass options further
48
- if singleton_class.ancestors.include? Marshalling
49
- super *keys.map {|key| interpolate(key) }, options
49
+ # Serialization gets extended before Namespace does, so we need to pass options further
50
+ if singleton_class.ancestors.include? Serialization
51
+ super(*keys.map {|key| interpolate(key) }, options)
50
52
  else
51
- super *keys.map {|key| interpolate(key) }
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) { |key| super(key, ttl) }
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
- "#{super} with namespace #{namespace_str}"
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 *keys
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
 
@@ -1,16 +1,16 @@
1
1
  class Redis
2
2
  class Store < self
3
- module Marshalling
3
+ module Serialization
4
4
  def set(key, value, options = nil)
5
- _marshal(value, options) { |value| super encode(key), encode(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) { |value| super encode(key), encode(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) { |value| super encode(key), expiry, encode(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)
@@ -24,13 +24,23 @@ class Redis
24
24
  end
25
25
  end
26
26
 
27
+ def mset(*args)
28
+ options = args.pop if args.length.odd?
29
+ updates = []
30
+ args.each_slice(2) do |(key, value)|
31
+ updates << encode(key)
32
+ _marshal(value, options) { |v| updates << encode(v) }
33
+ end
34
+ super(*updates)
35
+ end
36
+
27
37
  private
28
38
  def _marshal(val, options)
29
- yield marshal?(options) ? Marshal.dump(val) : val
39
+ yield marshal?(options) ? @serializer.dump(val) : val
30
40
  end
31
41
 
32
42
  def _unmarshal(val, options)
33
- unmarshal?(val, options) ? Marshal.load(val) : val
43
+ unmarshal?(val, options) ? @serializer.load(val) : val
34
44
  end
35
45
 
36
46
  def marshal?(options)
@@ -5,7 +5,7 @@ class Redis
5
5
  if ttl = expires_in(options)
6
6
  setex(key, ttl.to_i, value, :raw => true)
7
7
  else
8
- super(key, value)
8
+ super(key, value, options)
9
9
  end
10
10
  end
11
11
 
@@ -1,5 +1,5 @@
1
1
  class Redis
2
2
  class Store < self
3
- VERSION = '1.1.7'
3
+ VERSION = '1.4.0'
4
4
  end
5
5
  end
data/lib/redis/store.rb CHANGED
@@ -1,3 +1,10 @@
1
+ require 'redis'
2
+ require 'redis/store/factory'
3
+ require 'redis/distributed_store'
4
+ require 'redis/store/namespace'
5
+ require 'redis/store/serialization'
6
+ require 'redis/store/version'
7
+ require 'redis/store/redis_version'
1
8
  require 'redis/store/ttl'
2
9
  require 'redis/store/interface'
3
10
  require 'redis/store/redis_version'
@@ -8,6 +15,24 @@ class Redis
8
15
 
9
16
  def initialize(options = { })
10
17
  super
18
+
19
+ unless options[:marshalling].nil?
20
+ puts %(
21
+ DEPRECATED: You are passing the :marshalling option, which has been
22
+ replaced with `serializer: Marshal` to support pluggable serialization
23
+ backends. To disable serialization (much like disabling marshalling),
24
+ pass `serializer: nil` in your configuration.
25
+
26
+ The :marshalling option will be removed for redis-store 2.0.
27
+ )
28
+ end
29
+
30
+ @serializer = options.key?(:serializer) ? options[:serializer] : Marshal
31
+
32
+ unless options[:marshalling].nil?
33
+ @serializer = options[:marshalling] ? Marshal : nil
34
+ end
35
+
11
36
  _extend_marshalling options
12
37
  _extend_namespace options
13
38
  end
@@ -23,13 +48,12 @@ class Redis
23
48
 
24
49
  private
25
50
  def _extend_marshalling(options)
26
- @marshalling = !(options[:marshalling] === false) # HACK - TODO delegate to Factory
27
- extend Marshalling if @marshalling
51
+ extend Serialization unless @serializer.nil?
28
52
  end
29
53
 
30
54
  def _extend_namespace(options)
31
55
  @namespace = options[:namespace]
32
- extend Namespace if @namespace
56
+ extend Namespace
33
57
  end
34
58
  end
35
59
  end
data/lib/redis-store.rb CHANGED
@@ -1,13 +1 @@
1
- require 'redis'
2
1
  require 'redis/store'
3
- require 'redis/store/factory'
4
- require 'redis/distributed_store'
5
- require 'redis/store/namespace'
6
- require 'redis/store/marshalling'
7
- require 'redis/store/version'
8
- require 'redis/store/redis_version'
9
-
10
- class Redis
11
- class Store < self
12
- end
13
- end
data/redis-store.gemspec CHANGED
@@ -19,13 +19,14 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ["lib"]
20
20
  s.license = 'MIT'
21
21
 
22
- s.add_dependency 'redis', '>= 2.2'
22
+ s.add_dependency 'redis', '>= 2.2', '< 4'
23
23
 
24
24
  s.add_development_dependency 'rake', '~> 10'
25
25
  s.add_development_dependency 'bundler', '~> 1.3'
26
26
  s.add_development_dependency 'mocha', '~> 0.14.0'
27
27
  s.add_development_dependency 'minitest', '~> 5'
28
28
  s.add_development_dependency 'git', '~> 1.2'
29
+ s.add_development_dependency 'pry-nav', '~> 0.2.4'
30
+ s.add_development_dependency 'pry', '~> 0.10.4'
29
31
  s.add_development_dependency 'redis-store-testing'
30
- end
31
-
32
+ end
@@ -1,4 +1,5 @@
1
1
  require 'test_helper'
2
+ require 'json'
2
3
 
3
4
  describe "Redis::Store::Factory" do
4
5
  describe ".create" do
@@ -41,9 +42,53 @@ describe "Redis::Store::Factory" do
41
42
  store.instance_variable_get(:@client).password.must_equal("secret")
42
43
  end
43
44
 
44
- it "allows/disable marshalling" do
45
- store = Redis::Store::Factory.create :marshalling => false
46
- store.instance_variable_get(:@marshalling).must_equal(false)
45
+ it 'uses empty password' do
46
+ store = Redis::Store::Factory.create :password => ''
47
+ store.instance_variable_get(:@client).password.must_equal('')
48
+ end
49
+
50
+ it 'uses nil password' do
51
+ store = Redis::Store::Factory.create :password => nil
52
+ assert_nil(store.instance_variable_get(:@client).password)
53
+ end
54
+
55
+ it "disables serialization" do
56
+ store = Redis::Store::Factory.create :serializer => nil
57
+ store.instance_variable_get(:@serializer).must_be_nil
58
+ store.instance_variable_get(:@options)[:raw].must_equal(true)
59
+ end
60
+
61
+ it "configures pluggable serialization backend" do
62
+ store = Redis::Store::Factory.create :serializer => JSON
63
+ store.instance_variable_get(:@serializer).must_equal(JSON)
64
+ store.instance_variable_get(:@options)[:raw].must_equal(false)
65
+ end
66
+
67
+ describe 'with stdout disabled' do
68
+ before do
69
+ @original_stderr = $stderr
70
+ @original_stdout = $stdout
71
+
72
+ $stderr = Tempfile.new('stderr')
73
+ $stdout = Tempfile.new('stdout')
74
+ end
75
+
76
+ it "disables marshalling and provides deprecation warning" do
77
+ store = Redis::Store::Factory.create :marshalling => false
78
+ store.instance_variable_get(:@serializer).must_be_nil
79
+ store.instance_variable_get(:@options)[:raw].must_equal(true)
80
+ end
81
+
82
+ it "enables marshalling but provides warning to use :serializer instead" do
83
+ store = Redis::Store::Factory.create :marshalling => true
84
+ store.instance_variable_get(:@serializer).must_equal(Marshal)
85
+ store.instance_variable_get(:@options)[:raw].must_equal(false)
86
+ end
87
+
88
+ after do
89
+ $stderr = @original_stderr
90
+ $stdout = @original_stdout
91
+ end
47
92
  end
48
93
 
49
94
  it "should instantiate a Redis::DistributedStore store" do
@@ -85,6 +130,21 @@ describe "Redis::Store::Factory" do
85
130
  store.instance_variable_get(:@client).password.must_equal("secret")
86
131
  end
87
132
 
133
+ it 'uses specified password with special characters' do
134
+ store = Redis::Store::Factory.create 'redis://:pwd%40123@127.0.0.1:6379/0/theplaylist'
135
+ store.instance_variable_get(:@client).password.must_equal('pwd@123')
136
+ end
137
+
138
+ it 'uses empty password' do
139
+ store = Redis::Store::Factory.create 'redis://:@127.0.0.1:6379/0/theplaylist'
140
+ store.instance_variable_get(:@client).password.must_equal('')
141
+ end
142
+
143
+ it 'uses nil password' do
144
+ store = Redis::Store::Factory.create 'redis://127.0.0.1:6379/0/theplaylist'
145
+ assert_nil(store.instance_variable_get(:@client).password)
146
+ end
147
+
88
148
  it "correctly uses specified ipv6 host" do
89
149
  store = Redis::Store::Factory.create "redis://[::1]:6380"
90
150
  store.to_s.must_equal("Redis Client connected to [::1]:6380 against DB 0")
@@ -3,11 +3,12 @@ require 'test_helper'
3
3
  describe "Redis::Store::Namespace" do
4
4
  def setup
5
5
  @namespace = "theplaylist"
6
- @store = Redis::Store.new :namespace => @namespace, :marshalling => false # TODO remove mashalling option
6
+ @store = Redis::Store.new :namespace => @namespace, :serializer => nil
7
7
  @client = @store.instance_variable_get(:@client)
8
8
  @rabbit = "bunny"
9
9
  @default_store = Redis::Store.new
10
- @other_store = Redis::Store.new :namespace => 'other'
10
+ @other_namespace = 'other'
11
+ @other_store = Redis::Store.new :namespace => @other_namespace
11
12
  end
12
13
 
13
14
  def teardown
@@ -37,10 +38,22 @@ describe "Redis::Store::Namespace" do
37
38
  @store.set 'def', 'fed'
38
39
 
39
40
  @store.flushdb
40
- @store.get('def').must_equal(nil)
41
+ @store.get('def').must_be_nil
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
@@ -61,7 +74,7 @@ describe "Redis::Store::Namespace" do
61
74
  r2 = dyn_store.get 'key'
62
75
  $ns = "ns1"
63
76
  r1 = dyn_store.get 'key'
64
- r1.must_equal('x') && r2.must_equal('y') && r3.must_equal(nil)
77
+ r1.must_equal('x') && r2.must_equal('y') && r3.must_be_nil
65
78
  end
66
79
 
67
80
  it "namespaces setex and ttl" do
@@ -77,7 +90,7 @@ describe "Redis::Store::Namespace" do
77
90
  end
78
91
 
79
92
  describe 'method calls' do
80
- let(:store){Redis::Store.new :namespace => @namespace, :marshalling => false}
93
+ let(:store){Redis::Store.new :namespace => @namespace, :serializer => nil}
81
94
  let(:client){store.instance_variable_get(:@client)}
82
95
 
83
96
  it "should namespace get" do
@@ -1,8 +1,8 @@
1
1
  require 'test_helper'
2
2
 
3
- describe "Redis::Marshalling" do
3
+ describe "Redis::Serialization" do
4
4
  def setup
5
- @store = Redis::Store.new :marshalling => true
5
+ @store = Redis::Store.new serializer: Marshal
6
6
  @rabbit = OpenStruct.new :name => "bunny"
7
7
  @white_rabbit = OpenStruct.new :color => "white"
8
8
  @store.set "rabbit", @rabbit
@@ -23,6 +23,12 @@ describe "Redis::Marshalling" do
23
23
  @store.get("rabbit").must_equal(@white_rabbit)
24
24
  end
25
25
 
26
+ it "marshals on multi set" do
27
+ @store.mset("rabbit", @white_rabbit, "rabbit2", @rabbit)
28
+ @store.get("rabbit").must_equal(@white_rabbit)
29
+ @store.get("rabbit2").must_equal(@rabbit)
30
+ end
31
+
26
32
  if RUBY_VERSION.match /1\.9/
27
33
  it "doesn't unmarshal on get if raw option is true" do
28
34
  @store.get("rabbit", :raw => true).must_equal("\x04\bU:\x0FOpenStruct{\x06:\tnameI\"\nbunny\x06:\x06EF")
@@ -38,6 +44,12 @@ describe "Redis::Marshalling" do
38
44
  @store.get("rabbit", :raw => true).must_equal(%(#<OpenStruct color="white">))
39
45
  end
40
46
 
47
+ it "doesn't marshal multi set if raw option is true" do
48
+ @store.mset("rabbit", @white_rabbit, "rabbit2", @rabbit, :raw => true)
49
+ @store.get("rabbit", :raw => true).must_equal(%(#<OpenStruct color="white">))
50
+ @store.get("rabbit2", :raw => true).must_equal(%(#<OpenStruct name="bunny">))
51
+ end
52
+
41
53
  it "doesn't unmarshal if get returns an empty string" do
42
54
  @store.set "empty_string", ""
43
55
  @store.get("empty_string").must_equal("")
@@ -67,9 +79,29 @@ describe "Redis::Marshalling" do
67
79
  @store.get("rabbit2").must_be_nil
68
80
  end
69
81
 
82
+ it "marshals setex (over a distributed store)" do
83
+ @store = Redis::DistributedStore.new [
84
+ {:host => "localhost", :port => "6380", :db => 0},
85
+ {:host => "localhost", :port => "6381", :db => 0}
86
+ ]
87
+ @store.setex "rabbit", 50, @white_rabbit
88
+ @store.get("rabbit").must_equal(@white_rabbit)
89
+ end
90
+
91
+ it "doesn't marshal setex if raw option is true (over a distributed store)" do
92
+ @store = Redis::DistributedStore.new [
93
+ {:host => "localhost", :port => "6380", :db => 0},
94
+ {:host => "localhost", :port => "6381", :db => 0}
95
+ ]
96
+ @store.setex "rabbit", 50, @white_rabbit, :raw => true
97
+ @store.get("rabbit", :raw => true).must_equal(%(#<OpenStruct color="white">))
98
+ end
99
+
70
100
  it "doesn't unmarshal on multi get" do
71
101
  @store.set "rabbit2", @white_rabbit
72
- rabbit, rabbit2 = @store.mget "rabbit", "rabbit2"
102
+ rabbits = @store.mget "rabbit", "rabbit2"
103
+ rabbit, rabbit2 = rabbits
104
+ rabbits.length.must_equal(2)
73
105
  rabbit.must_equal(@rabbit)
74
106
  rabbit2.must_equal(@white_rabbit)
75
107
  end
@@ -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
@@ -2,6 +2,6 @@ require 'test_helper'
2
2
 
3
3
  describe Redis::Store::VERSION do
4
4
  it 'returns current version' do
5
- Redis::Store::VERSION.must_equal '1.1.6'
5
+ Redis::Store::VERSION.wont_equal nil
6
6
  end
7
7
  end
@@ -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
data/test/test_helper.rb CHANGED
@@ -3,6 +3,7 @@ require 'minitest/autorun'
3
3
  require 'mocha/setup'
4
4
  require 'redis'
5
5
  require 'redis-store'
6
+ require 'pry'
6
7
 
7
8
  $DEBUG = ENV["DEBUG"] === "true"
8
9
 
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.1.7
4
+ version: 1.4.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: 2015-10-28 00:00:00.000000000 Z
11
+ date: 2017-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -17,6 +17,9 @@ dependencies:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '2.2'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '4'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -24,6 +27,9 @@ dependencies:
24
27
  - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '2.2'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '4'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: rake
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +100,34 @@ dependencies:
94
100
  - - "~>"
95
101
  - !ruby/object:Gem::Version
96
102
  version: '1.2'
103
+ - !ruby/object:Gem::Dependency
104
+ name: pry-nav
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: 0.2.4
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: 0.2.4
117
+ - !ruby/object:Gem::Dependency
118
+ name: pry
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: 0.10.4
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: 0.10.4
97
131
  - !ruby/object:Gem::Dependency
98
132
  name: redis-store-testing
99
133
  requirement: !ruby/object:Gem::Requirement
@@ -128,18 +162,18 @@ files:
128
162
  - lib/redis/store.rb
129
163
  - lib/redis/store/factory.rb
130
164
  - lib/redis/store/interface.rb
131
- - lib/redis/store/marshalling.rb
132
165
  - lib/redis/store/namespace.rb
133
166
  - lib/redis/store/redis_version.rb
167
+ - lib/redis/store/serialization.rb
134
168
  - lib/redis/store/ttl.rb
135
169
  - lib/redis/store/version.rb
136
170
  - redis-store.gemspec
137
171
  - test/redis/distributed_store_test.rb
138
172
  - test/redis/store/factory_test.rb
139
173
  - test/redis/store/interface_test.rb
140
- - test/redis/store/marshalling_test.rb
141
174
  - test/redis/store/namespace_test.rb
142
175
  - test/redis/store/redis_version_test.rb
176
+ - test/redis/store/serialization_test.rb
143
177
  - test/redis/store/ttl_test.rb
144
178
  - test/redis/store/version_test.rb
145
179
  - test/redis/store_test.rb
@@ -164,7 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
198
  version: '0'
165
199
  requirements: []
166
200
  rubyforge_project: redis-store
167
- rubygems_version: 2.4.5.1
201
+ rubygems_version: 2.6.11
168
202
  signing_key:
169
203
  specification_version: 4
170
204
  summary: Redis stores for Ruby frameworks
@@ -172,9 +206,9 @@ test_files:
172
206
  - test/redis/distributed_store_test.rb
173
207
  - test/redis/store/factory_test.rb
174
208
  - test/redis/store/interface_test.rb
175
- - test/redis/store/marshalling_test.rb
176
209
  - test/redis/store/namespace_test.rb
177
210
  - test/redis/store/redis_version_test.rb
211
+ - test/redis/store/serialization_test.rb
178
212
  - test/redis/store/ttl_test.rb
179
213
  - test/redis/store/version_test.rb
180
214
  - test/redis/store_test.rb