redis-store 1.1.4 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of redis-store might be problematic. Click here for more details.

data/README.md CHANGED
@@ -1,20 +1,42 @@
1
1
  # Redis stores for Ruby frameworks
2
2
 
3
- __Redis Store__ provides a full set of stores (*Cache*, *I18n*, *Session*, *HTTP Cache*) for all the modern Ruby frameworks like: __Ruby on Rails__, __Sinatra__, __Rack__, __Rack::Cache__ and __I18n__. It natively supports object marshalling, timeouts, single or multiple nodes and namespaces.
3
+ __Redis Store__ provides a full set of stores (*Cache*, *I18n*, *Session*, *HTTP Cache*) for modern Ruby frameworks like: __Ruby on Rails__, __Sinatra__, __Rack__, __Rack::Cache__ and __I18n__. It supports object marshalling, timeouts, single or multiple nodes, and namespaces.
4
4
 
5
- See the main [redis-store readme](https://github.com/jodosha/redis-store) for general guidelines.
5
+ Please check the *README* file of each gem for usage and installation guidelines.
6
6
 
7
- If you are using redis-store with Rails, consider using the [redis-rails gem](https://github.com/jodosha/redis-store/tree/master/redis-rails) instead.
7
+ ## Redis Installation
8
+
9
+ ### Option 1: Homebrew
10
+
11
+ MacOS X users should use [Homebrew](https://github.com/mxcl/homebrew) to install Redis:
12
+
13
+ ```shell
14
+ brew install redis
15
+ ```
16
+
17
+ ### Option 2: From Source
18
+
19
+ Download and install Redis from [the download page](http://redis.io//download) and follow the instructions.
8
20
 
9
21
  ## Running tests
10
22
 
11
- gem install bundler
12
- git clone git://github.com/jodosha/redis-store.git
13
- cd redis-store/redis-store
14
- ruby ci/run.rb
23
+ ```ruby
24
+ git clone git://github.com/jodosha/redis-store.git
25
+ cd redis-store
26
+ gem install bundler
27
+ bundle exec rake
28
+ ```
15
29
 
16
30
  If you are on **Snow Leopard** you have to run `env ARCHFLAGS="-arch x86_64" ruby ci/run.rb`
17
31
 
32
+ ## Contributors
33
+
34
+ * Matt Horan ([@mhoran](https://github.com/mhoran))
35
+
36
+ ## Status
37
+
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)
39
+
18
40
  ## Copyright
19
41
 
20
- (c) 2009 - 2011 Luca Guidi - [http://lucaguidi.com](http://lucaguidi.com), released under the MIT license
42
+ 2009 - 2013 Luca Guidi - [http://lucaguidi.com](http://lucaguidi.com), released under the MIT license
data/Rakefile CHANGED
@@ -1,7 +1,4 @@
1
- require 'bundler'
2
- Bundler.setup
1
+ require 'bundler/setup'
3
2
  require 'rake'
4
3
  require 'bundler/gem_tasks'
5
-
6
- load 'tasks/redis.tasks.rb'
7
- task :default => 'redis:test:suite'
4
+ require 'redis-store/testing/tasks'
@@ -47,7 +47,9 @@ class Redis
47
47
 
48
48
  def self.normalize_key_names(options)
49
49
  options = options.dup
50
- options[:namespace] ||= options.delete(:key_prefix) # RailsSessionStore
50
+ if options.key?(:key_prefix) && !options.key?(:namespace)
51
+ options[:namespace] = options.delete(:key_prefix) # RailsSessionStore
52
+ end
51
53
  options
52
54
  end
53
55
 
@@ -18,7 +18,7 @@ class Redis
18
18
  end
19
19
 
20
20
  def mget(*keys)
21
- options = keys.flatten.pop if keys.flatten.last.is_a?(Hash)
21
+ options = keys.pop if keys.last.is_a?(Hash)
22
22
  super(*keys).map do |result|
23
23
  _unmarshal result, options
24
24
  end
@@ -5,10 +5,18 @@ class Redis
5
5
  namespace(key) { |key| super(key, val, options) }
6
6
  end
7
7
 
8
+ def setex(key, ttl, val, options = nil)
9
+ namespace(key) { |key| super(key, ttl, val, options) }
10
+ end
11
+
8
12
  def setnx(key, val, options = nil)
9
13
  namespace(key) { |key| super(key, val, options) }
10
14
  end
11
15
 
16
+ def ttl(key, options = nil)
17
+ namespace(key) { |key| super(key) }
18
+ end
19
+
12
20
  def get(key, options = nil)
13
21
  namespace(key) { |key| super(key, options) }
14
22
  end
@@ -34,11 +42,27 @@ class Redis
34
42
  end
35
43
 
36
44
  def mget(*keys)
37
- super *keys.map {|key| interpolate(key) } if keys.any?
45
+ options = keys.pop if keys.last.is_a? Hash
46
+ 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
50
+ else
51
+ super *keys.map {|key| interpolate(key) }
52
+ end
53
+ end
54
+ end
55
+
56
+ def expire(key, ttl)
57
+ namespace(key) { |key| super(key, ttl) }
58
+ end
59
+
60
+ def ttl(key)
61
+ namespace(key) { |key| super(key) }
38
62
  end
39
63
 
40
64
  def to_s
41
- "#{super} with namespace #{@namespace}"
65
+ "#{super} with namespace #{namespace_str}"
42
66
  end
43
67
 
44
68
  def flushdb
@@ -50,8 +74,12 @@ class Redis
50
74
  yield interpolate(key)
51
75
  end
52
76
 
77
+ def namespace_str
78
+ @namespace.is_a?(Proc) ? @namespace.call : @namespace
79
+ end
80
+
53
81
  def interpolate(key)
54
- key.match(namespace_regexp) ? key : "#{@namespace}:#{key}"
82
+ key.match(namespace_regexp) ? key : "#{namespace_str}:#{key}"
55
83
  end
56
84
 
57
85
  def strip_namespace(key)
@@ -59,7 +87,8 @@ class Redis
59
87
  end
60
88
 
61
89
  def namespace_regexp
62
- @namespace_regexp ||= %r{^#{@namespace}\:}
90
+ @namespace_regexps ||= {}
91
+ @namespace_regexps[namespace_str] ||= %r{^#{namespace_str}\:}
63
92
  end
64
93
  end
65
94
  end
@@ -1,5 +1,5 @@
1
1
  class Redis
2
2
  class Store < self
3
- VERSION = '1.1.4'
3
+ VERSION = '1.1.5'
4
4
  end
5
5
  end
data/redis-store.gemspec CHANGED
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
17
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
+ s.license = 'MIT'
20
21
 
21
22
  s.add_dependency 'redis', '>= 2.2'
22
23
 
@@ -25,5 +26,6 @@ Gem::Specification.new do |s|
25
26
  s.add_development_dependency 'mocha', '~> 0.14.0'
26
27
  s.add_development_dependency 'minitest', '~> 5'
27
28
  s.add_development_dependency 'git', '~> 1.2'
29
+ s.add_development_dependency 'redis-store-testing'
28
30
  end
29
31
 
@@ -129,6 +129,11 @@ describe "Redis::Store::Factory" do
129
129
  "Redis Client connected to 127.0.0.1:6380 against DB 0 with namespace theplaylist",
130
130
  ])
131
131
  end
132
+
133
+ it 'instantiates Redis::Store and sets namespace from String' do
134
+ store = Redis::Store::Factory.create "redis://127.0.0.1:6379/0/theplaylist", { :expire_after => 5 }
135
+ store.to_s.must_equal("Redis Client connected to 127.0.0.1:6379 against DB 0 with namespace theplaylist")
136
+ end
132
137
  end
133
138
  end
134
139
  end
@@ -10,6 +10,7 @@ describe "Redis::Marshalling" do
10
10
  end
11
11
 
12
12
  def teardown
13
+ @store.flushdb
13
14
  @store.quit
14
15
  end
15
16
 
@@ -124,4 +125,4 @@ describe "Redis::Marshalling" do
124
125
  @store.get(utf8_key, :raw => true).bytes.to_a.must_equal(ascii_string.bytes.to_a)
125
126
  end
126
127
  end if defined?(Encoding)
127
- end
128
+ end
@@ -6,10 +6,19 @@ describe "Redis::Store::Namespace" do
6
6
  @store = Redis::Store.new :namespace => @namespace, :marshalling => false # TODO remove mashalling option
7
7
  @client = @store.instance_variable_get(:@client)
8
8
  @rabbit = "bunny"
9
+ @default_store = Redis::Store.new
10
+ @other_store = Redis::Store.new :namespace => 'other'
9
11
  end
10
12
 
11
13
  def teardown
14
+ @store.flushdb
12
15
  @store.quit
16
+
17
+ @default_store.flushdb
18
+ @default_store.quit
19
+
20
+ @other_store.flushdb
21
+ @other_store.quit
13
22
  end
14
23
 
15
24
  it "only decorates instances that need to be namespaced" do
@@ -24,14 +33,12 @@ describe "Redis::Store::Namespace" do
24
33
  end
25
34
 
26
35
  it "should only delete namespaced keys" do
27
- other_store = Redis::Store.new
28
-
29
- other_store.set 'abc', 'cba'
36
+ @default_store.set 'abc', 'cba'
30
37
  @store.set 'def', 'fed'
31
38
 
32
39
  @store.flushdb
33
40
  @store.get('def').must_equal(nil)
34
- other_store.get('abc').must_equal('cba')
41
+ @default_store.get('abc').must_equal('cba')
35
42
  end
36
43
 
37
44
  it "should not try to delete missing namespaced keys" do
@@ -40,64 +47,97 @@ describe "Redis::Store::Namespace" do
40
47
  empty_store.keys.must_be_empty
41
48
  end
42
49
 
43
- it "namespaces get"
44
- it "namespaces set"
45
- it "namespaces setnx"
46
- it "namespaces del with single key"
47
- it "namespaces del with multiple keys"
48
- it "namespaces keys"
49
- it "namespaces exists"
50
- it "namespaces incrby"
51
- it "namespaces decrby"
52
- it "namespaces mget"
53
-
54
- # it "should namespace get" do
55
- # @client.expects(:call).with([:get, "#{@namespace}:rabbit"]).once
56
- # @store.get("rabbit")
57
- # end
58
- #
59
- # it "should namespace set" do
60
- # @client.should_receive(:call).with([:set, "#{@namespace}:rabbit", @rabbit])
61
- # @store.set "rabbit", @rabbit
62
- # end
63
- #
64
- # it "should namespace setnx" do
65
- # @client.should_receive(:call).with([:setnx, "#{@namespace}:rabbit", @rabbit])
66
- # @store.setnx "rabbit", @rabbit
67
- # end
68
- #
69
- # it "should namespace del with single key" do
70
- # @client.should_receive(:call).with([:del, "#{@namespace}:rabbit"])
71
- # @store.del "rabbit"
72
- # end
73
- #
74
- # it "should namespace del with multiple keys" do
75
- # @client.should_receive(:call).with([:del, "#{@namespace}:rabbit", "#{@namespace}:white_rabbit"])
76
- # @store.del "rabbit", "white_rabbit"
77
- # end
78
- #
79
- # it "should namespace keys" do
80
- # @store.set "rabbit", @rabbit
81
- # @store.keys("rabb*").should == [ "rabbit" ]
82
- # end
83
- #
84
- # it "should namespace exists" do
85
- # @client.should_receive(:call).with([:exists, "#{@namespace}:rabbit"])
86
- # @store.exists "rabbit"
87
- # end
88
- #
89
- # it "should namespace incrby" do
90
- # @client.should_receive(:call).with([:incrby, "#{@namespace}:counter", 1])
91
- # @store.incrby "counter", 1
92
- # end
93
- #
94
- # it "should namespace decrby" do
95
- # @client.should_receive(:call).with([:decrby, "#{@namespace}:counter", 1])
96
- # @store.decrby "counter", 1
97
- # end
98
- #
99
- # it "should namespace mget" do
100
- # @client.should_receive(:call).with([:mget, "#{@namespace}:rabbit", "#{@namespace}:white_rabbit"])
101
- # @store.mget "rabbit", "white_rabbit"
102
- # end
50
+ it "should work with dynamic namespace" do
51
+ $ns = "ns1"
52
+ dyn_store = Redis::Store.new :namespace => -> { $ns }
53
+ dyn_store.set 'key', 'x'
54
+ $ns = "ns2"
55
+ dyn_store.set 'key', 'y'
56
+ $ns = "ns3"
57
+ dyn_store.set 'key', 'z'
58
+ dyn_store.flushdb
59
+ r3 = dyn_store.get 'key'
60
+ $ns = "ns2"
61
+ r2 = dyn_store.get 'key'
62
+ $ns = "ns1"
63
+ r1 = dyn_store.get 'key'
64
+ r1.must_equal('x') && r2.must_equal('y') && r3.must_equal(nil)
65
+ end
66
+
67
+ it "namespaces setex and ttl" do
68
+ @store.flushdb
69
+ @other_store.flushdb
70
+
71
+ @store.setex('foo', 30, 'bar')
72
+ @store.ttl('foo').must_be_close_to(30)
73
+ @store.get('foo').must_equal('bar')
74
+
75
+ @other_store.ttl('foo').must_equal(-2)
76
+ @other_store.get('foo').must_be_nil
77
+ end
78
+
79
+ describe 'method calls' do
80
+ let(:store){Redis::Store.new :namespace => @namespace, :marshalling => false}
81
+ let(:client){store.instance_variable_get(:@client)}
82
+
83
+ it "should namespace get" do
84
+ client.expects(:call).with([:get, "#{@namespace}:rabbit"]).once
85
+ store.get("rabbit")
86
+ end
87
+
88
+ it "should namespace set" do
89
+ client.expects(:call).with([:set, "#{@namespace}:rabbit", @rabbit])
90
+ store.set "rabbit", @rabbit
91
+ end
92
+
93
+ it "should namespace setnx" do
94
+ client.expects(:call).with([:setnx, "#{@namespace}:rabbit", @rabbit])
95
+ store.setnx "rabbit", @rabbit
96
+ end
97
+
98
+ it "should namespace del with single key" do
99
+ client.expects(:call).with([:del, "#{@namespace}:rabbit"])
100
+ store.del "rabbit"
101
+ end
102
+
103
+ it "should namespace del with multiple keys" do
104
+ client.expects(:call).with([:del, "#{@namespace}:rabbit", "#{@namespace}:white_rabbit"])
105
+ store.del "rabbit", "white_rabbit"
106
+ end
107
+
108
+ it "should namespace keys" do
109
+ store.set "rabbit", @rabbit
110
+ store.keys("rabb*").must_equal [ "rabbit" ]
111
+ end
112
+
113
+ it "should namespace exists" do
114
+ client.expects(:call).with([:exists, "#{@namespace}:rabbit"])
115
+ store.exists "rabbit"
116
+ end
117
+
118
+ it "should namespace incrby" do
119
+ client.expects(:call).with([:incrby, "#{@namespace}:counter", 1])
120
+ store.incrby "counter", 1
121
+ end
122
+
123
+ it "should namespace decrby" do
124
+ client.expects(:call).with([:decrby, "#{@namespace}:counter", 1])
125
+ store.decrby "counter", 1
126
+ end
127
+
128
+ it "should namespace mget" do
129
+ client.expects(:call).with([:mget, "#{@namespace}:rabbit", "#{@namespace}:white_rabbit"])
130
+ store.mget "rabbit", "white_rabbit"
131
+ end
132
+
133
+ it "should namespace expire" do
134
+ client.expects(:call).with([:expire, "#{@namespace}:rabbit", 60]).once
135
+ store.expire("rabbit",60)
136
+ end
137
+
138
+ it "should namespace ttl" do
139
+ client.expects(:call).with([:ttl, "#{@namespace}:rabbit"]).once
140
+ store.ttl("rabbit")
141
+ end
142
+ end
103
143
  end
@@ -1,11 +1,16 @@
1
1
  require 'test_helper'
2
2
 
3
3
  describe Redis::Store do
4
- before do
4
+ def setup
5
5
  @store = Redis::Store.new
6
6
  @client = @store.instance_variable_get(:@client)
7
7
  end
8
8
 
9
+ def teardown
10
+ @store.flushdb
11
+ @store.quit
12
+ end
13
+
9
14
  it "returns useful informations about the server" do
10
15
  @store.to_s.must_equal("Redis Client connected to #{@client.host}:#{@client.port} against DB #{@client.db}")
11
16
  end
metadata CHANGED
@@ -1,99 +1,113 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-store
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luca Guidi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-20 00:00:00.000000000 Z
11
+ date: 2015-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '2.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '10'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '1.3'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.3'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: mocha
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: 0.14.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 0.14.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: minitest
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '5'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '5'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: git
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ~>
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
89
  version: '1.2'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ~>
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '1.2'
97
+ - !ruby/object:Gem::Dependency
98
+ name: redis-store-testing
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description: Namespaced Rack::Session, Rack::Cache, I18n and cache Redis stores for
98
112
  Ruby web frameworks.
99
113
  email:
@@ -102,6 +116,9 @@ executables: []
102
116
  extensions: []
103
117
  extra_rdoc_files: []
104
118
  files:
119
+ - ".gitignore"
120
+ - ".travis.yml"
121
+ - CHANGELOG
105
122
  - Gemfile
106
123
  - MIT-LICENSE
107
124
  - README.md
@@ -115,11 +132,7 @@ files:
115
132
  - lib/redis/store/namespace.rb
116
133
  - lib/redis/store/ttl.rb
117
134
  - lib/redis/store/version.rb
118
- - lib/tasks/redis.tasks.rb
119
135
  - redis-store.gemspec
120
- - test/config/node-one.conf
121
- - test/config/node-two.conf
122
- - test/config/redis.conf
123
136
  - test/redis/distributed_store_test.rb
124
137
  - test/redis/store/factory_test.rb
125
138
  - test/redis/store/interface_test.rb
@@ -130,7 +143,8 @@ files:
130
143
  - test/redis/store_test.rb
131
144
  - test/test_helper.rb
132
145
  homepage: http://redis-store.org/redis-store
133
- licenses: []
146
+ licenses:
147
+ - MIT
134
148
  metadata: {}
135
149
  post_install_message:
136
150
  rdoc_options: []
@@ -138,24 +152,21 @@ require_paths:
138
152
  - lib
139
153
  required_ruby_version: !ruby/object:Gem::Requirement
140
154
  requirements:
141
- - - '>='
155
+ - - ">="
142
156
  - !ruby/object:Gem::Version
143
157
  version: '0'
144
158
  required_rubygems_version: !ruby/object:Gem::Requirement
145
159
  requirements:
146
- - - '>='
160
+ - - ">="
147
161
  - !ruby/object:Gem::Version
148
162
  version: '0'
149
163
  requirements: []
150
164
  rubyforge_project: redis-store
151
- rubygems_version: 2.0.3
165
+ rubygems_version: 2.4.6
152
166
  signing_key:
153
167
  specification_version: 4
154
168
  summary: Redis stores for Ruby frameworks
155
169
  test_files:
156
- - test/config/node-one.conf
157
- - test/config/node-two.conf
158
- - test/config/redis.conf
159
170
  - test/redis/distributed_store_test.rb
160
171
  - test/redis/store/factory_test.rb
161
172
  - test/redis/store/interface_test.rb