redis-store 1.0.0.1 → 1.1.0.rc

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.

Files changed (53) hide show
  1. data/Gemfile +2 -34
  2. data/README.md +17 -220
  3. data/Rakefile +7 -54
  4. data/lib/redis-store.rb +11 -44
  5. data/lib/redis/distributed_store.rb +8 -1
  6. data/lib/redis/factory.rb +17 -21
  7. data/lib/redis/store.rb +3 -8
  8. data/lib/redis/store/interface.rb +4 -0
  9. data/lib/redis/store/marshalling.rb +4 -0
  10. data/lib/redis/store/version.rb +1 -8
  11. data/lib/tasks/redis.tasks.rb +167 -0
  12. data/redis-store.gemspec +22 -97
  13. data/{spec → test}/config/node-one.conf +2 -2
  14. data/{spec → test}/config/node-two.conf +2 -2
  15. data/{spec → test}/config/redis.conf +3 -2
  16. data/{spec/redis/distributed_store_spec.rb → test/redis/distributed_store_test.rb} +13 -15
  17. data/test/redis/factory_test.rb +98 -0
  18. data/test/redis/store/interface_test.rb +27 -0
  19. data/test/redis/store/marshalling_test.rb +127 -0
  20. data/test/redis/store/namespace_test.rb +86 -0
  21. data/test/redis/store/version_test.rb +7 -0
  22. data/test/redis/store_test.rb +17 -0
  23. data/test/test_helper.rb +22 -0
  24. metadata +85 -97
  25. data/.travis.yml +0 -7
  26. data/CHANGELOG +0 -311
  27. data/VERSION +0 -1
  28. data/lib/action_controller/session/redis_session_store.rb +0 -81
  29. data/lib/active_support/cache/redis_store.rb +0 -254
  30. data/lib/cache/merb/redis_store.rb +0 -79
  31. data/lib/cache/sinatra/redis_store.rb +0 -131
  32. data/lib/i18n/backend/redis.rb +0 -67
  33. data/lib/rack/cache/redis_entitystore.rb +0 -48
  34. data/lib/rack/cache/redis_metastore.rb +0 -40
  35. data/lib/rack/session/merb.rb +0 -32
  36. data/lib/rack/session/redis.rb +0 -88
  37. data/spec/action_controller/session/redis_session_store_spec.rb +0 -126
  38. data/spec/active_support/cache/redis_store_spec.rb +0 -426
  39. data/spec/cache/merb/redis_store_spec.rb +0 -143
  40. data/spec/cache/sinatra/redis_store_spec.rb +0 -192
  41. data/spec/i18n/backend/redis_spec.rb +0 -72
  42. data/spec/rack/cache/entitystore/pony.jpg +0 -0
  43. data/spec/rack/cache/entitystore/redis_spec.rb +0 -124
  44. data/spec/rack/cache/metastore/redis_spec.rb +0 -259
  45. data/spec/rack/session/redis_spec.rb +0 -234
  46. data/spec/redis/factory_spec.rb +0 -110
  47. data/spec/redis/store/interface_spec.rb +0 -23
  48. data/spec/redis/store/marshalling_spec.rb +0 -119
  49. data/spec/redis/store/namespace_spec.rb +0 -76
  50. data/spec/redis/store/version_spec.rb +0 -7
  51. data/spec/redis/store_spec.rb +0 -13
  52. data/spec/spec_helper.rb +0 -43
  53. data/tasks/redis.tasks.rb +0 -235
data/Gemfile CHANGED
@@ -1,34 +1,2 @@
1
- source :gemcutter
2
- gem "redis", "~> 2.2.1"
3
-
4
- group :development do
5
- gem "jeweler"
6
- gem "git"
7
- end
8
-
9
- group :development, :test, :rails3 do
10
- gem "rack-cache"
11
- gem "merb", "1.1.0"
12
- gem "rspec", "1.3.0"
13
- gem "i18n"
14
-
15
- if RUBY_VERSION > '1.9'
16
- gem "methopara" # required by merb.
17
- else
18
- gem "ruby-debug" # linecache isn't compatible with 1.9.2 yet.
19
- end
20
- end
21
-
22
- if ENV["REDIS_STORE_ENV"] == "rails3"
23
- group :rails3 do
24
- gem "rack", "~> 1.2.1"
25
- gem "activesupport", "3.0.5"
26
- gem "actionpack", "3.0.5"
27
- end
28
- else
29
- group :test do
30
- gem "rack", "~> 1.1.0"
31
- gem "activesupport", "2.3.11"
32
- gem "actionpack", "2.3.11"
33
- end
34
- end
1
+ source 'http://rubygems.org'
2
+ gemspec
data/README.md CHANGED
@@ -1,238 +1,35 @@
1
- # Namespaced Rack::Session, Rack::Cache, I18n and cache Redis stores for Ruby web frameworks
1
+ # Redis stores for Ruby frameworks
2
2
 
3
- ## Installation
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.
4
4
 
5
- ### Redis, Option 1: Homebrew
5
+ This is the core for all the other gems, please check the *READMEs* to be informed about the usage.
6
+
7
+ ## Redis Installation
8
+
9
+ ### Option 1: Homebrew
6
10
 
7
11
  MacOS X users should use [Homebrew](https://github.com/mxcl/homebrew) to install Redis:
8
12
 
9
13
  brew install redis
10
14
 
11
- ### Redis, Option 2: From Source
15
+ ### Option 2: From Source
12
16
 
13
- Download and install Redis from [http://code.google.com/p/redis/](http://code.google.com/p/redis/)
17
+ Download and install Redis from [http://redis.io](http://redis.io/)
14
18
 
15
- wget http://redis.googlecode.com/files/redis-2.0.0.tar.gz
16
- tar -zxf redis-2.0.0.tar.gz
17
- mv redis-2.0.0 redis
19
+ wget http://redis.googlecode.com/files/redis-2.4.5.tar.gz
20
+ tar -zxf redis-2.4.5.tar.gz
21
+ mv redis-2.4.5 redis
18
22
  cd redis
19
23
  make
20
24
 
21
- ### Install the Gem
22
-
23
- Assuming you're using RVM or on Windows, install the gem with:
24
-
25
- gem install redis-store
26
-
27
- ## Options
28
- You can specify the Redis configuration details using a URI or a hash. By default the gem will attempt to connect to `localhost` port `6379` and the db `0`.
29
-
30
- ### Set by URI
31
-
32
- For example
33
-
34
- "redis://:secret@192.168.1.100:23682/13/theplaylist"
35
-
36
- Made up of the following:
37
-
38
- host: 192.168.1.100
39
- port: 23682
40
- db: 13
41
- namespace: theplaylist
42
- password: secret
43
-
44
- If you want to specify the `namespace` option, you have to pass the `db` param too.
45
- #### __Important__: `namespace` is only supported for single, non-distributed stores.
46
-
47
- ### Set by Hash
48
-
49
- { :host => 192.168.1.100, :port => 23682, :db => 13, :namespace => "theplaylist", :password => "secret" }
50
-
51
- #### __Important__: `namespace` is only supported for single, non-distributed stores.
52
-
53
- ## Cache store
54
-
55
- Provides a cache store for your Ruby web framework of choice.
56
-
57
- ### Rails 2.x
58
-
59
- config.gem "redis-store"
60
- config.cache_store = :redis_store
61
-
62
- ### Rails 2.x (with Bundler)
63
-
64
- # Gemfile
65
- gem "redis-store"
66
-
67
- # in your configuration
68
- config.gem "redis-store"
69
- config.cache_store = :redis_store, { ... optional configuration ... }
70
-
71
- ### Rails 3.x
72
-
73
- # Gemfile
74
- gem 'redis'
75
- gem 'redis-store', '1.0.0.1'
76
-
77
- # config/environments/production.rb
78
- config.cache_store = :redis_store, { ... optional configuration ... }
79
-
80
- For advanced configurations scenarios please visit [the wiki](https://github.com/jodosha/redis-store/wiki/Frameworks-Configuration).
81
-
82
- ### Merb
83
-
84
- dependency "redis-store", "1.0.0.1"
85
- dependency("merb-cache", merb_gems_version) do
86
- Merb::Cache.setup do
87
- register(:redis, Merb::Cache::RedisStore, :servers => ["127.0.0.1:6379"])
88
- end
89
- end
90
-
91
- ### Sinatra
92
-
93
- require "sinatra"
94
- require "redis-store"
95
- class MyApp < Sinatra::Base
96
- register Sinatra::Cache
97
- get "/hi" do
98
- settings.cache.fetch("greet") { "Hello, World!" }
99
- end
100
- end
101
-
102
- Keep in mind that the above fetch will return "OK" on success, not the return of the block.
103
-
104
- For advanced configurations scenarios please visit [the wiki](https://github.com/jodosha/redis-store/wiki/Frameworks-Configuration).
105
-
106
- ## Rack::Session
107
-
108
- Provides a Redis store for Rack::Session. See [http://rack.rubyforge.org/doc/Rack/Session.html](http://rack.rubyforge.org/doc/Rack/Session.html)
109
-
110
- ### Rack application
111
-
112
- require "rack"
113
- require "redis-store"
114
- require "application"
115
- use Rack::Session::Redis
116
- run Application.new
117
-
118
- ### Rails 2.x
119
-
120
- # config/environment.rb
121
- config.gem "redis-store"
122
-
123
- # then configure as following:
124
-
125
- # config/environments/*.rb
126
- config.cache_store = :redis_store
127
-
128
- # or
129
-
130
- # config/initializers/session_store.rb
131
- ActionController::Base.session = {
132
- :key => APPLICATION['session_key'],
133
- :secret => APPLICATION['session_secret'],
134
- :key_prefix => Rails.env
135
- }
136
-
137
- ActionController::Base.session_store = :redis_session_store
138
-
139
- ### Rails 2.x (with Bundler)
140
-
141
- # Gemfile
142
- gem "redis-store"
143
-
144
- # then configure as following:
145
-
146
- # config/environments/*.rb
147
- config.cache_store = :redis_store
148
-
149
- # or
150
-
151
- # config/initializers/session_store.rb
152
- ActionController::Base.session = {
153
- :key => APPLICATION['session_key'],
154
- :secret => APPLICATION['session_secret'],
155
- :key_prefix => Rails.env
156
- }
157
-
158
- ActionController::Base.session_store = :redis_session_store
159
-
160
- ### Rails 3.x
161
-
162
- # Gemfile
163
- gem 'rails', '3.0.3'
164
- gem 'redis'
165
- gem 'redis-store', '1.0.0.1'
166
-
167
- # config/initializers/session_store.rb
168
- MyApp::Application.config.session_store :redis_session_store
169
-
170
- For advanced configurations scenarios please visit [the wiki](https://github.com/jodosha/redis-store/wiki/Frameworks-Configuration).
171
-
172
- ### Merb
173
-
174
- dependency "redis-store", "1.0.0.1"
175
- Merb::Config.use do |c|
176
- c[:session_store] = "redis"
177
- end
178
- Merb::BootLoader.before_app_loads do
179
- Merb::SessionContainer.subclasses << "Merb::RedisSession"
180
- end
181
-
182
- ### Sinatra
183
-
184
- require "sinatra"
185
- require "redis-store"
186
-
187
- class MyApp < Sinatra::Base
188
- use Rack::Session::Redis, :redis_server => 'redis://127.0.0.1:6379/0' # Redis server on localhost port 6379, database 0
189
-
190
- get "/" do
191
- session[:visited_at] = DateTime.now.to_s # This is stored in Redis
192
- "Hello, visitor."
193
- end
194
- end
195
-
196
- For advanced configurations scenarios please visit [the wiki](https://github.com/jodosha/redis-store/wiki/Frameworks-Configuration).
197
-
198
- ## Rack::Cache
199
-
200
- Provides a Redis store for HTTP caching. See [http://github.com/rtomayko/rack-cache](http://github.com/rtomayko/rack-cache)
201
-
202
- require "rack"
203
- require "rack/cache"
204
- require "redis-store"
205
- require "application"
206
- use Rack::Cache,
207
- :metastore => 'redis://localhost:6379/0/metastore',
208
- :entitystore => 'redis://localhost:6380/0/entitystore'
209
- run Application.new
210
-
211
- ## I18n
212
-
213
- require "i18n"
214
- require "redis-store"
215
- I18n.backend = I18n::Backend::Redis.new
216
-
217
- The backend accepts the uri string and hash options.
218
-
219
- ## Unicorn
220
-
221
- Use `Rails.cache.reconnect` in your Unicorn hooks, in order to force the client reconnection.
222
-
223
- ## Running specs
25
+ ## Running tests
224
26
 
225
- gem install jeweler bundler
226
27
  git clone git://github.com/jodosha/redis-store.git
227
- cd redis-store
228
- bundle install
229
- REDIS_STORE_ENV=rails3 bundle install # to install Rails 3 gems
230
- rake dtach:install
231
- rake redis:install
232
- rake
233
- REDIS_STORE_ENV=rails3 rake # to test against Rails 3
28
+ cd redis-store/redis-store
29
+ gem install bundler --pre # required version: 1.1.rc
30
+ ruby ci/run.rb
234
31
 
235
- If you are on **Snow Leopard** you have to run `env ARCHFLAGS="-arch x86_64" bundle install`
32
+ If you are on **Snow Leopard** you have to run `env ARCHFLAGS="-arch x86_64" ruby ci/run.rb`
236
33
 
237
34
  ## Copyright
238
35
 
data/Rakefile CHANGED
@@ -1,60 +1,13 @@
1
- $:.unshift 'lib'
2
- require 'rubygems'
1
+ require 'bundler'
2
+ Bundler.setup
3
3
  require 'rake'
4
- require 'rake/testtask'
5
- require 'rake/rdoctask'
6
- require 'spec/rake/spectask'
7
-
8
- task :default => "spec:suite"
4
+ require 'bundler/gem_tasks'
9
5
 
10
6
  begin
11
- require "jeweler"
12
- Jeweler::Tasks.new do |gemspec|
13
- gemspec.name = "#{ENV["GEM_PREFIX"]}redis-store"
14
- gemspec.summary = "Namespaced Rack::Session, Rack::Cache, I18n and cache Redis stores for Ruby web frameworks."
15
- gemspec.description = "Namespaced Rack::Session, Rack::Cache, I18n and cache Redis stores for Ruby web frameworks."
16
- gemspec.email = "guidi.luca@gmail.com"
17
- gemspec.homepage = "http://github.com/jodosha/redis-store"
18
- gemspec.authors = [ "Luca Guidi" ]
19
- gemspec.executables = [ ]
20
- gemspec.add_dependency "redis", ">= 2.0.0"
21
- end
22
-
23
- Jeweler::GemcutterTasks.new
7
+ require 'rdoc/task'
24
8
  rescue LoadError
25
- puts "Jeweler not available. Install it with: sudo gem install jeweler"
26
- end
27
-
28
- namespace :spec do
29
- desc "Run all the examples by starting a detached Redis instance"
30
- task :suite => :prepare do
31
- invoke_with_redis_replication "spec:run"
32
- end
33
-
34
- Spec::Rake::SpecTask.new(:run) do |t|
35
- t.spec_files = FileList['spec/**/*_spec.rb']
36
- t.spec_opts = %w(-fs --color)
37
- end
38
- end
39
-
40
- desc "Run all examples with RCov"
41
- task :rcov => :prepare do
42
- invoke_with_redis_replication "rcov_run"
43
- end
44
-
45
- Spec::Rake::SpecTask.new(:rcov_run) do |t|
46
- t.spec_files = FileList['spec/**/*_spec.rb']
47
- t.rcov = true
48
- end
49
-
50
- task :prepare do
51
- `mkdir -p tmp && rm tmp/*.rdb`
52
- end
53
-
54
- namespace :bundle do
55
- task :clean do
56
- system "rm -rf ~/.bundle/ ~/.gem/ .bundle/ Gemfile.lock"
57
- end
9
+ require 'rake/rdoctask'
58
10
  end
59
11
 
60
- load "tasks/redis.tasks.rb"
12
+ load 'tasks/redis.tasks.rb'
13
+ task :default => 'redis:test:suite'
data/lib/redis-store.rb CHANGED
@@ -1,45 +1,12 @@
1
- require "redis"
2
- require "redis/distributed"
3
- require "redis/factory"
4
- require "redis/store/interface"
5
- require "redis/store/ttl"
6
- require "redis/store/namespace"
7
- require "redis/store/marshalling"
8
- require "redis/store/version"
9
- require "redis/store"
10
- require "redis/distributed_store"
11
-
12
- # Cache store
13
- if defined?(Sinatra)
14
- require "cache/sinatra/redis_store"
15
- elsif defined?(Merb)
16
- # HACK for cyclic dependency: redis-store is required before merb-cache
17
- module Merb; module Cache; class AbstractStore; end end end
18
- require "cache/merb/redis_store"
19
- elsif defined?(ActiveSupport)
20
- require "active_support/cache/redis_store"
21
- end
22
-
23
- # Rack::Session
24
- if defined?(Rack::Session)
25
- require "rack/session/abstract/id"
26
- require "rack/session/redis"
27
- if defined?(Merb)
28
- require "rack/session/merb"
1
+ require 'redis'
2
+ require 'redis/store'
3
+ require 'redis/factory'
4
+ require 'redis/distributed_store'
5
+ require 'redis/store/namespace'
6
+ require 'redis/store/marshalling'
7
+ require 'redis/store/version'
8
+
9
+ class Redis
10
+ class Store < self
29
11
  end
30
- end
31
-
32
- if defined?(Rails)
33
- require "action_controller/session/redis_session_store"
34
- end
35
-
36
- # Rack::Cache
37
- if defined?(Rack::Cache)
38
- require "rack/cache/key"
39
- require "rack/cache/redis_metastore"
40
- require "rack/cache/redis_entitystore"
41
- end
42
-
43
- if defined?(I18n)
44
- require "i18n/backend/redis"
45
- end
12
+ end
@@ -1,10 +1,13 @@
1
+ require 'redis/distributed'
2
+
1
3
  class Redis
2
4
  class DistributedStore < Distributed
5
+ @@timeout = 5
3
6
  attr_reader :ring
4
7
 
5
8
  def initialize(addresses, options = { })
6
9
  nodes = addresses.map do |address|
7
- ::Redis::Store.new address
10
+ ::Redis::Store.new _merge_options(address, options)
8
11
  end
9
12
  _extend_namespace options
10
13
  @ring = Redis::HashRing.new nodes
@@ -35,5 +38,9 @@ class Redis
35
38
  @namespace = options[:namespace]
36
39
  extend ::Redis::Store::Namespace if @namespace
37
40
  end
41
+
42
+ def _merge_options(address, options)
43
+ address.merge(:timeout => options[:timeout] || @@timeout)
44
+ end
38
45
  end
39
46
  end
data/lib/redis/factory.rb CHANGED
@@ -1,8 +1,10 @@
1
+ require 'uri'
2
+
1
3
  class Redis
2
4
  class Factory
3
5
  def self.create(*redis_client_options)
4
6
  redis_client_options = redis_client_options.flatten.compact.inject([]) do |result, address|
5
- result << convert_to_redis_client_options(address)
7
+ result << resolve(address)
6
8
  result
7
9
  end
8
10
  if redis_client_options.size > 1
@@ -12,32 +14,26 @@ class Redis
12
14
  end
13
15
  end
14
16
 
15
- def self.convert_to_redis_client_options(address_or_options)
16
- if address_or_options.is_a?(Hash)
17
- options = address_or_options.dup
17
+ def self.resolve(uri) #:api: private
18
+ if uri.is_a?(Hash)
19
+ options = uri.dup
18
20
  options[:namespace] ||= options.delete(:key_prefix) # RailsSessionStore
19
21
  options
20
22
  else
21
- if address_or_options =~ /redis\:\/\//
22
- require 'uri'
23
- uri = URI.parse address_or_options
24
- _, db, namespace = if uri.path
25
- uri.path.split /\//
26
- end
27
- else
28
- warn "[DEPRECATION] `#{address_or_options}` is deprecated. Please use `redis://#{address_or_options}` instead."
29
- address_or_options, password = address_or_options.split(/\@/).reverse
30
- password = password.gsub(/\:/, "") if password
31
- host, port = address_or_options.split /\:/
32
- port, db, namespace = port.split /\// if port
23
+ uri = URI.parse(uri)
24
+ _, db, namespace = if uri.path
25
+ uri.path.split /\//
33
26
  end
34
27
 
35
- options = {}
36
- options[:host] = host || uri && uri.host
37
- options[:port] = port || uri && uri.port
38
- options[:db] = db.to_i if db
28
+ options = {
29
+ :host => uri.host,
30
+ :port => uri.port,
31
+ :password => uri.password
32
+ }
33
+
34
+ options[:db] = db.to_i if db
39
35
  options[:namespace] = namespace if namespace
40
- options[:password] = password || uri && uri.password
36
+
41
37
  options
42
38
  end
43
39
  end