instructure-redis-store 1.0.0.1.instructure1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/.travis.yml +7 -0
  2. data/CHANGELOG +311 -0
  3. data/Gemfile +34 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.md +239 -0
  6. data/Rakefile +60 -0
  7. data/VERSION +1 -0
  8. data/lib/action_controller/session/redis_session_store.rb +81 -0
  9. data/lib/active_support/cache/redis_store.rb +254 -0
  10. data/lib/cache/merb/redis_store.rb +79 -0
  11. data/lib/cache/sinatra/redis_store.rb +131 -0
  12. data/lib/i18n/backend/redis.rb +67 -0
  13. data/lib/rack/cache/redis_entitystore.rb +48 -0
  14. data/lib/rack/cache/redis_metastore.rb +40 -0
  15. data/lib/rack/session/merb.rb +32 -0
  16. data/lib/rack/session/redis.rb +88 -0
  17. data/lib/redis-store.rb +45 -0
  18. data/lib/redis/distributed_store.rb +39 -0
  19. data/lib/redis/factory.rb +46 -0
  20. data/lib/redis/store.rb +39 -0
  21. data/lib/redis/store/interface.rb +17 -0
  22. data/lib/redis/store/marshalling.rb +51 -0
  23. data/lib/redis/store/namespace.rb +62 -0
  24. data/lib/redis/store/ttl.rb +37 -0
  25. data/lib/redis/store/version.rb +12 -0
  26. data/spec/action_controller/session/redis_session_store_spec.rb +126 -0
  27. data/spec/active_support/cache/redis_store_spec.rb +426 -0
  28. data/spec/cache/merb/redis_store_spec.rb +143 -0
  29. data/spec/cache/sinatra/redis_store_spec.rb +192 -0
  30. data/spec/config/node-one.conf +417 -0
  31. data/spec/config/node-two.conf +417 -0
  32. data/spec/config/redis.conf +417 -0
  33. data/spec/i18n/backend/redis_spec.rb +72 -0
  34. data/spec/rack/cache/entitystore/pony.jpg +0 -0
  35. data/spec/rack/cache/entitystore/redis_spec.rb +124 -0
  36. data/spec/rack/cache/metastore/redis_spec.rb +259 -0
  37. data/spec/rack/session/redis_spec.rb +234 -0
  38. data/spec/redis/distributed_store_spec.rb +55 -0
  39. data/spec/redis/factory_spec.rb +110 -0
  40. data/spec/redis/store/interface_spec.rb +23 -0
  41. data/spec/redis/store/marshalling_spec.rb +119 -0
  42. data/spec/redis/store/namespace_spec.rb +76 -0
  43. data/spec/redis/store/version_spec.rb +7 -0
  44. data/spec/redis/store_spec.rb +13 -0
  45. data/spec/spec_helper.rb +43 -0
  46. data/tasks/redis.tasks.rb +235 -0
  47. metadata +249 -0
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ bundler_args: "--without development"
2
+ script: "bundle exec rake"
3
+ rvm:
4
+ - 1.8.7
5
+ - 1.9.2
6
+ - jruby
7
+ - rbx
data/CHANGELOG ADDED
@@ -0,0 +1,311 @@
1
+ *1.0.0.1 (September 6, 2011)*
2
+
3
+ * Bump version v1.0.0.1
4
+
5
+ *1.0.0 (September 1, 2011)*
6
+
7
+ * Bump version v1.0.0
8
+ * Avoid encoding issues when sending strings to Redis. [Damian Janowski]
9
+ * Fixed a bug that caused all the users to share the same session (with a session_id of 0 or 1) [Mathieu Ravaux]
10
+ * ActiveSupport cache stores reply to read_multi with a hash, not an array. [Matt Griffin]
11
+ * Rack::Session && Rack::Cache store can be created with options [aligo]
12
+ * add destroy_session [aligo]
13
+ * compatible with rails 3.1. rely on Rack::Session::Redis stores API. [aligo]
14
+ * Fixed Marshalling semantic
15
+
16
+ *1.0.0 [rc1] (June 5, 2011)*
17
+
18
+ * Bump version v1.0.0.rc1
19
+ * Re-implement the delete_entry because it s needed by the ActiveSupport::Cache [Cyril Mougel]
20
+ * Change readme documentation for rack-cache to use single redis database with namespace support per Redis maintainers recommendation [Travis D. Warlick, Jr.]
21
+ * Rack-Cache entity and meta store base classes should use the Redis::Factory.convert_to_redis_client_options method for DRYness and for namespace support [Travis D. Warlick, Jr.]
22
+ * Modify #fetch for cache stores to return the yielded value instead of OK [Rune Botten]
23
+ * Minor revisions to Readme language and organization [Jeff Casimir]
24
+ * Re-implement the delete_entry because it s needed by the ActiveSupport::Cache implementation in Rails 3 [Cyril Mougel]
25
+ * Refactor delete_matched [Andrei Kulakov]
26
+
27
+ *1.0.0 [beta5] (April 2, 2011)*
28
+
29
+ * Bump version v1.0.0.beta5
30
+ * Introducing Rails.cache.reconnect, useful for Unicorn environments. Closes #21
31
+ * Namespaced i18n backend should strip namespace when lists available locales. Closes #62
32
+ * how to configure Redis session store in Sinatra [Christian von Kleist]
33
+ * gracefully handle Connection Refused errors, allows database fall-back on fetch [Michael Kintzer]
34
+ * Sinatra's API must have changed, its registered not register. [Michael D'Auria]
35
+
36
+ *1.0.0 [beta4] (December 15, 2010)*
37
+
38
+ * Bump version v1.0.0.beta4
39
+ * Force Rails cache store when ActiveSupport is detected
40
+ * Make sure to accept options when :servers isn't passed
41
+ * Always force session store loading when using Rails
42
+ * Make it compatible with Rails 3 sessions store [Andre Medeiros]
43
+ * Better Rails 3 detection [Andre Medeiros]
44
+ * Added support for password in Redis URI resolution [Jacob Gyllenstierna]
45
+ * fix deleting values from session hash [Calvin Yu]
46
+ * Use defensive design when build options for a store
47
+ * ActiveSupport cache store doesn't accept any argument in Rails 2
48
+ * Updated dependencies
49
+
50
+ *1.0.0 [beta3] (September 10, 2010)*
51
+
52
+ * Bump version v1.0.0.beta3
53
+ * Updated gemspec
54
+ * Made compatible with Ruby 1.9.2
55
+ * Made compatible with Rails 3
56
+ * Making the redis-store rails session store compatible with Rails 2.3.9. [Aaron Gibralter]
57
+ * Updated to v2.3.9 the development dependencies for Rails 2.x
58
+ * Added password support
59
+ * Set default URI string for Rack session store according to redis gem
60
+ * Require redis:// scheme as mandatory part of URI string
61
+ * Updated locked dependencies
62
+ * Added namespace support for Redis::DistrubutedStore
63
+ * Specs for Interface module
64
+ * Moved a spec to reflect lib/ structure
65
+ * Made specs run again with bundler-1.0.0.rc.2
66
+ * Prepare for bundler-1.0.0.rc.1
67
+ * Use tmp/ for Redis database dumps
68
+ * README, gemspec
69
+ * Lookup for scoped keys
70
+ * Introducing I18n::Backend::Redis
71
+ * Don't pollute Redis namespace. closes #16
72
+ * Don't look twice for Rails module
73
+ * Fixed loading ActionDispatch::Session issue with Rails 3
74
+ * ActiveSupport cache now uses new Rails 3 namespace API
75
+ * Let Rack::Cache entity store to use plain Redis client
76
+ * CHANGELOG
77
+ * Gemspec
78
+ * Redis::DistributedMarshaled => Redis::DistributedStore
79
+ * Extracted expiration logic in Redis::Ttl
80
+ * Introducing Redis::Store and extracted marshalling logic into Redis::Marshalling
81
+ * CHANGELOG
82
+ * Gemspec
83
+ * Removed superfluous specs. Documentation.
84
+ * Made the specs pass with Ruby 1.9.2 and Rails 3
85
+ * Made the specs pass with Ruby 1.9.2
86
+ * Prepare specs for Ruby 1.9.2
87
+ * Made the specs pass for Rails 3
88
+ * Namespaced keys for ActiveSupport::Cache::RedisStore
89
+ * Got RedisSessionStore working again with namespace
90
+ * Delegate MarshaledClient#to_s decoration to Redis::Namespace
91
+ * Redis::Namespace
92
+ * Accept :namespace option when instantiate a store
93
+ * Test against merb-1.1.0 for now
94
+ * Updated Rake tasks for Redis installation
95
+ * Advanced configurations for Rails in README. closes #8
96
+ * Locked gems
97
+ * Changed the gemspec according to the new directories structure
98
+ * Changed directories structure, according to the ActiveSupport loading policies
99
+ * Typo in CHANGELOG
100
+
101
+ *1.0.0 [beta2] (June 12, 2010)*
102
+
103
+ * Bump version v1.0.0.beta2
104
+ * Added committers names to CHANGELOG
105
+ * Added CHANGELOG
106
+ * Rake namespace: redis_cluster => redis:cluster
107
+ * Fixed Rails 3 failing spec
108
+ * Added ActiveSupport::Cache::RedisStore#read_multi
109
+ * Enabled notifications for ActiveSupport::Cache::RedisStore
110
+ * Moved spec
111
+ * Use consistent Rails 3 check in session store
112
+ * Make sure of use top-level module
113
+ * Updated Rails 2.x development dependencies
114
+
115
+ *1.0.0 [beta1] (June 9, 2010)*
116
+
117
+ * Bump version v1.0.0.beta1
118
+ * Made specs pass for Ruby 1.9.1
119
+ * Updated instructions to test against Rails 3.x
120
+ * Updated copyright year
121
+ * Prepare for v1.0.0.beta1
122
+ * Use Rails v3.0.0.beta4
123
+ * Require redis >= 2.0.0 gem in Gemfile
124
+ * Updated instructions for Rails 2 session store
125
+ * Added instructions for Rails 3 configuration
126
+ * Check against Rails#version instead of Rails::VERSION::STRING
127
+ * Added redis gem as dependency
128
+ * Changed spec_helper.rb according to the new Rails 3 check
129
+ * Fix the rails3 check [Bruno Michel]
130
+ * Added bundler cleanup Rake task
131
+ * Fixed ActiveSupport::Cache::RedisStore#fetch
132
+ * Re-enabled redis:console Rake task
133
+ * Don't use Rspec#have with ActiveSupport 3
134
+ * Fixed Rails 2 regression for ActiveSupport::Cache::RedisStore#delete_matched
135
+ * Fixed issues for ActiveSupport::Cache::RedisStore #delete_matched, #read, #rwrite
136
+ * Rails 3 namespace
137
+ * Use Rails edge instead of 3.0.0.beta3
138
+ * Made the specs run again
139
+ * Updated Gemfile development/test dependencies for rails3.
140
+ * Updated README instructions
141
+ * Updated test configuration files, according to redis-2.0.0-rc1 defaults
142
+ * Made specs pass with redis-2.0.0 gem
143
+ * Don't support the old redis-rb namespace
144
+ * Import the whole redis-rb old Rake tasks
145
+ * Updated redis-rb dependency
146
+
147
+ *0.3.8 [Final] (May 21, 2010)*
148
+
149
+ * Fixed gemspec executable issue
150
+ * Updated .gemspec
151
+ * Version bump to 0.3.8
152
+ * Started namespace migration for redis-2.0.0
153
+ * Merge branch 'master' of http://github.com/akahn/redis-store
154
+ * Fixed dependency issues. [Brian Takita]
155
+ * Removed methopara because it require ruby 1.9.1. [Brian Takita]
156
+ * Merge branch 'master' of http://github.com/dsander/redis-store [Brian Takita]
157
+ * Moved RedisSessionStore to rack session directory. [Brian Takita]
158
+ * Got RedisSessionStore working with passing specs. [Brian Takita]
159
+ * Using modified version of RedisSessionStore (http://github.com/mattmatt/redis-session-store). Still needs testing. [Brian Takita]
160
+ * Using redis 1.0.5. [Brian Takita]
161
+ * Ignoring gem files and gemspecs with a prefix. [Brian Takita]
162
+ * Added git and jeweler to dependencies. [Brian Takita]
163
+ * Ignoring .bundle and rubymine files. [Brian Takita]
164
+ * Added ability to add a prefix to the gem name via the GEM_PREFIX environment variable. [Brian Takita]
165
+ * Fixed marshalling issues with the new Redis api. Fixed redis-server configurations for the latest version of redis-server. Added redis_cluster:start and redis_cluster:stop rake tasks. Spec suite passes. [Brian Takita]
166
+ * Fixed redis deprecation warnings. [Brian Takita]
167
+ * Using redis 1.0.4. Loading redis.tasks.rb from redis gem using Bundler. Fixed redis test configurations. [Brian Takita]
168
+ * Supports redis 1.0.5 [Dominik Sander]
169
+ * Add Rack::Session::Redis usage for Sinatra to README [Alexander Kahn]
170
+ * Updated development and testing dependencies
171
+ * Made compatible with rack-cache-0.5.2
172
+
173
+ *0.3.7 [Final] (November 15, 2009)*
174
+
175
+ * Version bump to 0.3.7
176
+ * Version bump to 0.3.7
177
+ * Updated spec instructions in README
178
+ * Jeweler generated redis-store.gemspec
179
+ * Removed no longer used Rake tasks. Added Gemcutter support via Jeweler.
180
+ * Typo
181
+ * Let Rcov task run with the Redis cluster started
182
+ * Make spec suite pass again
183
+ * README.textile -> README.md
184
+ * Re-enabled Merb specs
185
+ * Added *.rdb in .gitignore
186
+ * Run detached Redis instances for spec suite
187
+ * Start detached Redis server for specs
188
+ * Added Gemfile, removed rubygems dependecy for testing.
189
+ * Added *.swp to .gitignore
190
+ * Added jeweler rake tasks
191
+ * Make it work in classic Sinatra apps. [Dmitriy Timokhin]
192
+ * Updated README with new instructions about redis-rb
193
+
194
+ *0.3.6 [Final] (June 18, 2009)*
195
+
196
+ * Prepare for v0.3.6
197
+ * Updated README with new version
198
+ * Changed Redis config files for specs
199
+ * Updated README instructions
200
+ * New filelist in gemspec
201
+ * Fixed typo in spec
202
+ * Don't try to unmarshal empty strings
203
+ * Running specs according to the DEBUG env var
204
+ * Added specs for uncovered Merb Cache API
205
+ * Added rcov Rake task
206
+ * Fix README
207
+ * Fix typo in README
208
+ * Updated README instructions
209
+ * Removed RedisError catching
210
+ * Declaring for now RedisError in spec_helper.rb
211
+ * Removed unnecessary classes
212
+ * Fix specs for DistributedMarshaledRedis
213
+ * Fix some specs
214
+ * Made Server#notify_observers private
215
+ * Ensure to select the correct database after the socket connection
216
+ * Reverted socket pooling. Ensure to always return an active socket.
217
+ * Lowering default timeout from 10 to 0.1
218
+
219
+ *0.3.5 [Final] (May 7, 2009)*
220
+
221
+ * Prepare for v0.3.5
222
+ * Totally replace ezmobius-redis-rb Server implementation
223
+ * Fixed default Server timeout to 1 second
224
+ * Little refactoring
225
+ * Ensure Server#active? always returns a boolean and never raise an exception
226
+ * Made configurable connection pool timeout and size
227
+ * Socket connection pooling
228
+ * Updated README
229
+
230
+ *0.3.0 [Final] (May 3, 2009)*
231
+
232
+ * Prepare for v0.3.0
233
+ * README formatting issues
234
+ * README formatting (again)
235
+ * README formatting
236
+ * Updated Rack::Session instructions for Sinatra
237
+ * Make Rack::Session implementation working with Merb
238
+ * Added instructions for Rack::Session
239
+ * Expiration support for Rack::Session
240
+ * Ensure to test Rails and Sinatra expiration implementations with both MarshaledRedis and DistrbutedMarshaledRedis
241
+ * Expiration support for Merb::Cache
242
+ * Use full qualified class names in specs. Minor spec fix.
243
+ * Ported for foreword compatibility the expiration implementation from ezmobius/redis-rb
244
+ * Little spec cleanup
245
+ * Full support for Rack::Session
246
+ * Extracted some logic into RedisFactory
247
+ * Initial support for Rack::Session
248
+
249
+ *0.2.0 [Final] (April 30, 2009)*
250
+
251
+ * Prepare for v0.2.0
252
+ * Links in README
253
+ * Maybe someday I will use the right formatting rules at first attempt
254
+ * Still formatting README
255
+ * Formatting for README
256
+ * Updated instructions for Rack::Cache
257
+ * Don't require any cache store if no Ruby framework is detected
258
+ * Implemented EntityStore for Rack::Cache
259
+ * Added REDIS constant for Rack::Cache::Metastore
260
+ * MetaStore implementation for Rack::Cache
261
+
262
+ *0.1.0 [Final] (April 30, 2009)*
263
+
264
+ * Prepare for v0.1.0
265
+ * Sinatra cache support
266
+
267
+ *0.0.3 [Final] (April 30, 2009)*
268
+
269
+ * Prepare for v0.0.3
270
+ * Updated instructions for Merb
271
+ * Hack for Merb cyclic dependency
272
+ * Renaming main lib
273
+ * Merb store #writable always returns true. Added pending test.
274
+ * Merb store #fetch refactoring
275
+ * Updated Redis installation instructions
276
+ * Implemented #fetch for Merb store
277
+ * Implemented #exists?, #delete and #delete_all for Merb cache store
278
+ * Renamed project name in Rakefile
279
+ * Updated project name in README
280
+ * Updated README with Merb instructions
281
+ * Changed name in gemspec
282
+ * New gemspec
283
+ * Initial cache store support for Merb
284
+ * Moving files around
285
+ * Don't complain about missing db in tmp/
286
+
287
+ *0.0.2 [Final] (April 16, 2009)*
288
+
289
+ * Prepare for v0.0.2
290
+ * Updated file list in gemspec
291
+ * Updated README instructions
292
+ * Re-enabled spec for RedisStore#fetch
293
+ * Update rdoc
294
+ * Fix RedisStore#clear when use a cluster
295
+ * Test RedisStore both with single server and with a cluster
296
+ * Fix port in DistributedMarshaledRedis spec
297
+ * Don't slave Redis cluster node
298
+ * Changed Redis cluster configuration
299
+ * Added configuration for Redis cluster
300
+ * Use a distributed system if the store uses more than one server
301
+ * Accept params for client connection
302
+
303
+ *0.0.1 [Final] (April 11, 2009)*
304
+
305
+ * Added :unless_exist option to #write
306
+ * Added failing specs for :expires_in option
307
+ * Made optional args compatible with the Cache interface
308
+ * Implemented #delete_matched, #clear, #stats
309
+ * Implemented #delete, #exist?, #increment, #decrement
310
+ * Introduced RedisStore
311
+ * Initial import
data/Gemfile ADDED
@@ -0,0 +1,34 @@
1
+ source :gemcutter
2
+ gem "redis", "3.0.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
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 - 2011 Luca Guidi
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,239 @@
1
+ # Namespaced Rack::Session, Rack::Cache, I18n and cache Redis stores for Ruby web frameworks
2
+
3
+ ## Installation
4
+
5
+ ### Redis, Option 1: Homebrew
6
+
7
+ MacOS X users should use [Homebrew](https://github.com/mxcl/homebrew) to install Redis:
8
+
9
+ brew install redis
10
+
11
+ ### Redis, Option 2: From Source
12
+
13
+ Download and install Redis from [http://code.google.com/p/redis/](http://code.google.com/p/redis/)
14
+
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
18
+ cd redis
19
+ make
20
+
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
224
+
225
+ gem install jeweler bundler
226
+ 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
234
+
235
+ If you are on **Snow Leopard** you have to run `env ARCHFLAGS="-arch x86_64" bundle install`
236
+
237
+ ## Copyright
238
+
239
+ (c) 2009 - 2011 Luca Guidi - [http://lucaguidi.com](http://lucaguidi.com), released under the MIT license