redis-store 0.3.6 → 0.3.7
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/.gitignore +7 -0
- data/Gemfile +9 -0
- data/README.md +105 -0
- data/Rakefile +38 -39
- data/VERSION +1 -0
- data/lib/redis/marshaled_redis.rb +1 -1
- data/redis-store.gemspec +78 -12
- data/spec/cache/merb/redis_store_spec.rb +2 -2
- data/spec/cache/rails/redis_store_spec.rb +1 -1
- data/spec/cache/sinatra/redis_store_spec.rb +1 -1
- data/spec/config/master.conf +44 -5
- data/spec/config/single.conf +45 -6
- data/spec/config/slave.conf +45 -6
- data/spec/redis/marshaled_redis_spec.rb +22 -17
- data/spec/spec_helper.rb +2 -1
- data/tasks/redis.tasks.rb +67 -0
- metadata +12 -7
- data/README.textile +0 -102
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# use ezmobius/redis-rb HEAD
|
2
|
+
gem "redis-rb", "0.1", :git => "git://github.com/ezmobius/redis-rb.git"
|
3
|
+
|
4
|
+
# testing gems
|
5
|
+
gem "rspec", :only => :testing
|
6
|
+
gem "rack-cache", :only => :testing
|
7
|
+
gem "activesupport", :only => :testing
|
8
|
+
gem "merb", :only => :testing
|
9
|
+
|
data/README.md
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
# Rack::Session, Rack::Cache and cache Redis stores for Ruby web frameworks
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Download and install Redis from [http://code.google.com/p/redis/](http://code.google.com/p/redis/)
|
6
|
+
|
7
|
+
curl -OL http://redis.googlecode.com/files/redis-1.02.tar.gz
|
8
|
+
tar -zxvf redis-1.02.tar.gz
|
9
|
+
mv redis-1.02 redis
|
10
|
+
cd redis
|
11
|
+
make
|
12
|
+
|
13
|
+
Install the gems
|
14
|
+
|
15
|
+
sudo gem install redis-rb redis-store
|
16
|
+
|
17
|
+
## Cache store
|
18
|
+
|
19
|
+
Provides a cache store for your Ruby web framework of choice.
|
20
|
+
|
21
|
+
### Rails
|
22
|
+
|
23
|
+
config.gem "redis-store", :source => "http://gemcutter.org", :lib => "redis-store"
|
24
|
+
require "redis-store"
|
25
|
+
config.cache_store = :redis_store
|
26
|
+
|
27
|
+
### Merb
|
28
|
+
|
29
|
+
dependency "redis-store", "0.3.7"
|
30
|
+
dependency("merb-cache", merb_gems_version) do
|
31
|
+
Merb::Cache.setup do
|
32
|
+
register(:redis, Merb::Cache::RedisStore, :servers => ["127.0.0.1:6379"])
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
### Sinatra
|
37
|
+
|
38
|
+
require "sinatra"
|
39
|
+
require "redis-store"
|
40
|
+
class MyApp < Sinatra::Base
|
41
|
+
register Sinatra::Cache
|
42
|
+
get "/hi" do
|
43
|
+
cache.fetch("greet") { "Hello, World!" }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
## Rack::Session
|
48
|
+
|
49
|
+
Provides a Redis store for Rack::Session. See [http://rack.rubyforge.org/doc/Rack/Session.html](http://rack.rubyforge.org/doc/Rack/Session.html)
|
50
|
+
|
51
|
+
### Rack application
|
52
|
+
|
53
|
+
require "rack"
|
54
|
+
require "redis-store"
|
55
|
+
require "application"
|
56
|
+
use Rack::Session::Redis
|
57
|
+
run Application.new
|
58
|
+
|
59
|
+
### Rails
|
60
|
+
|
61
|
+
config.gem "redis-store", :source => "http://gemcutter.org", :lib => "redis-store"
|
62
|
+
ActionController::Base.session_store = Rack::Session::Redis
|
63
|
+
|
64
|
+
### Merb
|
65
|
+
|
66
|
+
dependency "redis-store", "0.3.7"
|
67
|
+
Merb::Config.use do |c|
|
68
|
+
c[:session_store] = "redis"
|
69
|
+
end
|
70
|
+
Merb::BootLoader.before_app_loads do
|
71
|
+
Merb::SessionContainer.subclasses << "Merb::RedisSession"
|
72
|
+
end
|
73
|
+
|
74
|
+
### Sinatra
|
75
|
+
|
76
|
+
Sorry, but Sinatra application boot system [hardcode](http://github.com/sinatra/sinatra/blob/0f02bafe86f8dd9bba9ab425468cb1067caa83ff/lib/sinatra/base.rb#L785) `Rack::Session::Cookie`
|
77
|
+
|
78
|
+
## Rack::Cache
|
79
|
+
|
80
|
+
Provides a Redis store for HTTP caching. See [http://github.com/rtomayko/rack-cache](http://github.com/rtomayko/rack-cache)
|
81
|
+
|
82
|
+
require "rack"
|
83
|
+
require "rack/cache"
|
84
|
+
require "redis-store"
|
85
|
+
require "application"
|
86
|
+
use Rack::Cache,
|
87
|
+
:metastore => 'redis://localhost:6379/0',
|
88
|
+
:entitystore => 'redis://localhost:6380/1'
|
89
|
+
run Application.new
|
90
|
+
|
91
|
+
## Running specs
|
92
|
+
|
93
|
+
gem install jeweler bundler
|
94
|
+
git clone git://github.com/jodosha/redis-store.git
|
95
|
+
cd redis-store
|
96
|
+
gem bundle
|
97
|
+
rake dtach:install
|
98
|
+
rake redis:install
|
99
|
+
rake
|
100
|
+
|
101
|
+
If you are on **Snow Leopard** you have to run `env ARCHFLAGS="-arch x86_64" gem bundle`
|
102
|
+
|
103
|
+
## Copyright
|
104
|
+
|
105
|
+
(c) 2009 Luca Guidi - [http://lucaguidi.com](http://lucaguidi.com), released under the MIT license
|
data/Rakefile
CHANGED
@@ -1,58 +1,57 @@
|
|
1
1
|
$:.unshift 'lib'
|
2
|
-
require 'rubygems'
|
3
2
|
require 'rake'
|
4
3
|
require 'rake/testtask'
|
5
4
|
require 'rake/rdoctask'
|
6
5
|
require 'spec/rake/spectask'
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
task :default => "spec:suite"
|
8
|
+
|
9
|
+
begin
|
10
|
+
require "jeweler"
|
11
|
+
Jeweler::Tasks.new do |gemspec|
|
12
|
+
gemspec.name = "redis-store"
|
13
|
+
gemspec.summary = "Rack::Session, Rack::Cache and cache Redis stores for Ruby web frameworks."
|
14
|
+
gemspec.description = "Rack::Session, Rack::Cache and cache Redis stores for Ruby web frameworks."
|
15
|
+
gemspec.email = "guidi.luca@gmail.com"
|
16
|
+
gemspec.homepage = "http://github.com/jodosha/redis-store"
|
17
|
+
gemspec.authors = [ "Luca Guidi" ]
|
18
|
+
end
|
11
19
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
system "sudo gem uninstall redis-store"
|
16
|
-
system "sudo gem install --local --no-rdoc --no-ri redis-store-#{REDIS_STORE_VERSION}.gem"
|
17
|
-
system "rm redis-store-*.gem"
|
20
|
+
Jeweler::GemcutterTasks.new
|
21
|
+
rescue LoadError
|
22
|
+
puts "Jeweler not available. Install it with: sudo gem install jeweler"
|
18
23
|
end
|
19
24
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
25
|
+
namespace :spec do
|
26
|
+
desc "Run all the examples by starting a detached Redis instance"
|
27
|
+
task :suite do
|
28
|
+
invoke_with_redis_cluster "spec:run"
|
29
|
+
end
|
24
30
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
31
|
+
Spec::Rake::SpecTask.new(:run) do |t|
|
32
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
33
|
+
t.spec_opts = %w(-fs --color)
|
34
|
+
end
|
29
35
|
end
|
30
36
|
|
31
37
|
desc "Run all examples with RCov"
|
32
|
-
|
38
|
+
task :rcov do
|
39
|
+
invoke_with_redis_cluster "rcov_run"
|
40
|
+
end
|
41
|
+
|
42
|
+
Spec::Rake::SpecTask.new(:rcov_run) do |t|
|
33
43
|
t.spec_files = FileList['spec/**/*_spec.rb']
|
34
44
|
t.rcov = true
|
35
45
|
end
|
36
46
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
task :stop do
|
47
|
-
# TODO replace with:
|
48
|
-
# system "kill -9 `tmp/redis-single.pid`"
|
49
|
-
# system "kill -9 `tmp/redis-master.pid`"
|
50
|
-
# system "kill -9 `tmp/redis-slave.pid`"
|
51
|
-
system "ps -eo pid,comm | grep redis | xargs kill -9"
|
52
|
-
end
|
53
|
-
|
54
|
-
desc 'Clean the tmp/ directory'
|
55
|
-
task :clean do
|
56
|
-
system "rm tmp/*" rescue nil
|
47
|
+
# courtesy of http://github.com/ezmobius/redis-rb team
|
48
|
+
load "tasks/redis.tasks.rb"
|
49
|
+
def invoke_with_redis_cluster(task_name)
|
50
|
+
begin
|
51
|
+
result = RedisClusterRunner.start_detached
|
52
|
+
raise("Could not start redis-server, aborting.") unless result
|
53
|
+
Rake::Task[task_name].invoke
|
54
|
+
ensure
|
55
|
+
RedisClusterRunner.stop
|
57
56
|
end
|
58
57
|
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.3.7
|
data/redis-store.gemspec
CHANGED
@@ -1,14 +1,80 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
1
6
|
Gem::Specification.new do |s|
|
2
|
-
s.name
|
3
|
-
s.version
|
4
|
-
|
5
|
-
s.
|
6
|
-
s.
|
7
|
-
s.
|
8
|
-
s.
|
9
|
-
s.
|
10
|
-
s.
|
11
|
-
|
12
|
-
|
13
|
-
s.
|
7
|
+
s.name = %q{redis-store}
|
8
|
+
s.version = "0.3.7"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Luca Guidi"]
|
12
|
+
s.date = %q{2009-11-15}
|
13
|
+
s.description = %q{Rack::Session, Rack::Cache and cache Redis stores for Ruby web frameworks.}
|
14
|
+
s.email = %q{guidi.luca@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.md"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".gitignore",
|
20
|
+
"Gemfile",
|
21
|
+
"MIT-LICENSE",
|
22
|
+
"README.md",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"lib/cache/merb/redis_store.rb",
|
26
|
+
"lib/cache/rails/redis_store.rb",
|
27
|
+
"lib/cache/sinatra/redis_store.rb",
|
28
|
+
"lib/rack/cache/redis_entitystore.rb",
|
29
|
+
"lib/rack/cache/redis_metastore.rb",
|
30
|
+
"lib/rack/session/merb.rb",
|
31
|
+
"lib/rack/session/redis.rb",
|
32
|
+
"lib/redis-store.rb",
|
33
|
+
"lib/redis/distributed_marshaled_redis.rb",
|
34
|
+
"lib/redis/marshaled_redis.rb",
|
35
|
+
"lib/redis/redis_factory.rb",
|
36
|
+
"redis-store.gemspec",
|
37
|
+
"spec/cache/merb/redis_store_spec.rb",
|
38
|
+
"spec/cache/rails/redis_store_spec.rb",
|
39
|
+
"spec/cache/sinatra/redis_store_spec.rb",
|
40
|
+
"spec/config/master.conf",
|
41
|
+
"spec/config/single.conf",
|
42
|
+
"spec/config/slave.conf",
|
43
|
+
"spec/rack/cache/entitystore/pony.jpg",
|
44
|
+
"spec/rack/cache/entitystore/redis_spec.rb",
|
45
|
+
"spec/rack/cache/metastore/redis_spec.rb",
|
46
|
+
"spec/rack/session/redis_spec.rb",
|
47
|
+
"spec/redis/distributed_marshaled_redis_spec.rb",
|
48
|
+
"spec/redis/marshaled_redis_spec.rb",
|
49
|
+
"spec/redis/redis_factory_spec.rb",
|
50
|
+
"spec/spec_helper.rb",
|
51
|
+
"tasks/redis.tasks.rb"
|
52
|
+
]
|
53
|
+
s.homepage = %q{http://github.com/jodosha/redis-store}
|
54
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
55
|
+
s.require_paths = ["lib"]
|
56
|
+
s.rubygems_version = %q{1.3.5}
|
57
|
+
s.summary = %q{Rack::Session, Rack::Cache and cache Redis stores for Ruby web frameworks.}
|
58
|
+
s.test_files = [
|
59
|
+
"spec/cache/merb/redis_store_spec.rb",
|
60
|
+
"spec/cache/rails/redis_store_spec.rb",
|
61
|
+
"spec/cache/sinatra/redis_store_spec.rb",
|
62
|
+
"spec/rack/cache/entitystore/redis_spec.rb",
|
63
|
+
"spec/rack/cache/metastore/redis_spec.rb",
|
64
|
+
"spec/rack/session/redis_spec.rb",
|
65
|
+
"spec/redis/distributed_marshaled_redis_spec.rb",
|
66
|
+
"spec/redis/marshaled_redis_spec.rb",
|
67
|
+
"spec/redis/redis_factory_spec.rb",
|
68
|
+
"spec/spec_helper.rb"
|
69
|
+
]
|
70
|
+
|
71
|
+
if s.respond_to? :specification_version then
|
72
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
73
|
+
s.specification_version = 3
|
74
|
+
|
75
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
76
|
+
else
|
77
|
+
end
|
78
|
+
else
|
79
|
+
end
|
14
80
|
end
|
@@ -120,14 +120,14 @@ module Merb
|
|
120
120
|
it "should delete all the data" do
|
121
121
|
with_store_management do |store|
|
122
122
|
store.delete_all
|
123
|
-
store.instance_variable_get(:@data).keys("*").should be_empty
|
123
|
+
store.instance_variable_get(:@data).keys("*").flatten.should be_empty
|
124
124
|
end
|
125
125
|
end
|
126
126
|
|
127
127
|
it "should delete all the data with bang method" do
|
128
128
|
with_store_management do |store|
|
129
129
|
store.delete_all!
|
130
|
-
store.instance_variable_get(:@data).keys("*").should be_empty
|
130
|
+
store.instance_variable_get(:@data).keys("*").flatten.should be_empty
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
@@ -136,7 +136,7 @@ module ActiveSupport
|
|
136
136
|
it "should clear the store" do
|
137
137
|
with_store_management do |store|
|
138
138
|
store.clear
|
139
|
-
store.instance_variable_get(:@data).keys("*").should be_empty
|
139
|
+
store.instance_variable_get(:@data).keys("*").flatten.should be_empty
|
140
140
|
end
|
141
141
|
end
|
142
142
|
|
@@ -157,7 +157,7 @@ module Sinatra
|
|
157
157
|
it "should clear the store" do
|
158
158
|
with_store_management do |store|
|
159
159
|
store.clear
|
160
|
-
store.instance_variable_get(:@data).keys("*").should be_empty
|
160
|
+
store.instance_variable_get(:@data).keys("*").flatten.should be_empty
|
161
161
|
end
|
162
162
|
end
|
163
163
|
|
data/spec/config/master.conf
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
# By default Redis does not run as a daemon. Use 'yes' if you need it.
|
4
4
|
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
|
5
|
-
daemonize
|
5
|
+
daemonize no
|
6
6
|
|
7
7
|
# When run as a daemon, Redis write a pid file in /var/run/redis.pid by default.
|
8
8
|
# You can specify a custom pid file location here.
|
9
|
-
pidfile
|
9
|
+
pidfile /var/run/redis.pid
|
10
10
|
|
11
11
|
# Accept connections on the specified port, default is 6379
|
12
12
|
port 6380
|
@@ -14,7 +14,7 @@ port 6380
|
|
14
14
|
# If you want you can bind a single interface, if the bind option is not
|
15
15
|
# specified all the interfaces will listen for connections.
|
16
16
|
#
|
17
|
-
bind 127.0.0.1
|
17
|
+
# bind 127.0.0.1
|
18
18
|
|
19
19
|
# Close the connection after a client is idle for N seconds (0 to disable)
|
20
20
|
timeout 300
|
@@ -35,11 +35,11 @@ save 300 10
|
|
35
35
|
save 60 10000
|
36
36
|
|
37
37
|
# The filename where to dump the DB
|
38
|
-
dbfilename master.rdb
|
38
|
+
dbfilename master-dump.rdb
|
39
39
|
|
40
40
|
# For default save/load DB in/from the working directory
|
41
41
|
# Note that you must specify a directory not a file name.
|
42
|
-
dir ./
|
42
|
+
dir ./
|
43
43
|
|
44
44
|
# Set server verbosity to 'debug'
|
45
45
|
# it can be one of:
|
@@ -107,6 +107,45 @@ databases 16
|
|
107
107
|
|
108
108
|
# maxmemory <bytes>
|
109
109
|
|
110
|
+
############################## APPEND ONLY MODE ###############################
|
111
|
+
|
112
|
+
# By default Redis asynchronously dumps the dataset on disk. If you can live
|
113
|
+
# with the idea that the latest records will be lost if something like a crash
|
114
|
+
# happens this is the preferred way to run Redis. If instead you care a lot
|
115
|
+
# about your data and don't want to that a single record can get lost you should
|
116
|
+
# enable the append only mode: when this mode is enabled Redis will append
|
117
|
+
# every write operation received in the file appendonly.log. This file will
|
118
|
+
# be read on startup in order to rebuild the full dataset in memory.
|
119
|
+
#
|
120
|
+
# Note that you can have both the async dumps and the append only file if you
|
121
|
+
# like (you have to comment the "save" statements above to disable the dumps).
|
122
|
+
# Still if append only mode is enabled Redis will load the data from the
|
123
|
+
# log file at startup ignoring the dump.rdb file.
|
124
|
+
#
|
125
|
+
# The name of the append only file is "appendonly.log"
|
126
|
+
|
127
|
+
appendonly no
|
128
|
+
|
129
|
+
# The fsync() call tells the Operating System to actually write data on disk
|
130
|
+
# instead to wait for more data in the output buffer. Some OS will really flush
|
131
|
+
# data on disk, some other OS will just try to do it ASAP.
|
132
|
+
#
|
133
|
+
# Redis supports three different modes:
|
134
|
+
#
|
135
|
+
# no: don't fsync, just let the OS flush the data when it wants. Faster.
|
136
|
+
# always: fsync after every write to the append only log . Slow, Safest.
|
137
|
+
# everysec: fsync only if one second passed since the last fsync. Compromise.
|
138
|
+
#
|
139
|
+
# The default is "always" that's the safer of the options. It's up to you to
|
140
|
+
# understand if you can relax this to "everysec" that will fsync every second
|
141
|
+
# or to "no" that will let the operating system flush the output buffer when
|
142
|
+
# it want, for better performances (but if you can live with the idea of
|
143
|
+
# some data loss consider the default persistence mode that's snapshotting).
|
144
|
+
|
145
|
+
appendfsync always
|
146
|
+
# appendfsync everysec
|
147
|
+
# appendfsync no
|
148
|
+
|
110
149
|
############################### ADVANCED CONFIG ###############################
|
111
150
|
|
112
151
|
# Glue small output buffers together in order to send small replies in a
|
data/spec/config/single.conf
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
# By default Redis does not run as a daemon. Use 'yes' if you need it.
|
4
4
|
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
|
5
|
-
daemonize
|
5
|
+
daemonize no
|
6
6
|
|
7
7
|
# When run as a daemon, Redis write a pid file in /var/run/redis.pid by default.
|
8
8
|
# You can specify a custom pid file location here.
|
9
|
-
pidfile
|
9
|
+
pidfile /var/run/redis.pid
|
10
10
|
|
11
11
|
# Accept connections on the specified port, default is 6379
|
12
12
|
port 6379
|
@@ -14,10 +14,10 @@ port 6379
|
|
14
14
|
# If you want you can bind a single interface, if the bind option is not
|
15
15
|
# specified all the interfaces will listen for connections.
|
16
16
|
#
|
17
|
-
bind 127.0.0.1
|
17
|
+
# bind 127.0.0.1
|
18
18
|
|
19
19
|
# Close the connection after a client is idle for N seconds (0 to disable)
|
20
|
-
timeout
|
20
|
+
timeout 300
|
21
21
|
|
22
22
|
# Save the DB on disk:
|
23
23
|
#
|
@@ -35,11 +35,11 @@ save 300 10
|
|
35
35
|
save 60 10000
|
36
36
|
|
37
37
|
# The filename where to dump the DB
|
38
|
-
dbfilename
|
38
|
+
dbfilename dump.rdb
|
39
39
|
|
40
40
|
# For default save/load DB in/from the working directory
|
41
41
|
# Note that you must specify a directory not a file name.
|
42
|
-
dir ./
|
42
|
+
dir ./
|
43
43
|
|
44
44
|
# Set server verbosity to 'debug'
|
45
45
|
# it can be one of:
|
@@ -107,6 +107,45 @@ databases 16
|
|
107
107
|
|
108
108
|
# maxmemory <bytes>
|
109
109
|
|
110
|
+
############################## APPEND ONLY MODE ###############################
|
111
|
+
|
112
|
+
# By default Redis asynchronously dumps the dataset on disk. If you can live
|
113
|
+
# with the idea that the latest records will be lost if something like a crash
|
114
|
+
# happens this is the preferred way to run Redis. If instead you care a lot
|
115
|
+
# about your data and don't want to that a single record can get lost you should
|
116
|
+
# enable the append only mode: when this mode is enabled Redis will append
|
117
|
+
# every write operation received in the file appendonly.log. This file will
|
118
|
+
# be read on startup in order to rebuild the full dataset in memory.
|
119
|
+
#
|
120
|
+
# Note that you can have both the async dumps and the append only file if you
|
121
|
+
# like (you have to comment the "save" statements above to disable the dumps).
|
122
|
+
# Still if append only mode is enabled Redis will load the data from the
|
123
|
+
# log file at startup ignoring the dump.rdb file.
|
124
|
+
#
|
125
|
+
# The name of the append only file is "appendonly.log"
|
126
|
+
|
127
|
+
appendonly no
|
128
|
+
|
129
|
+
# The fsync() call tells the Operating System to actually write data on disk
|
130
|
+
# instead to wait for more data in the output buffer. Some OS will really flush
|
131
|
+
# data on disk, some other OS will just try to do it ASAP.
|
132
|
+
#
|
133
|
+
# Redis supports three different modes:
|
134
|
+
#
|
135
|
+
# no: don't fsync, just let the OS flush the data when it wants. Faster.
|
136
|
+
# always: fsync after every write to the append only log . Slow, Safest.
|
137
|
+
# everysec: fsync only if one second passed since the last fsync. Compromise.
|
138
|
+
#
|
139
|
+
# The default is "always" that's the safer of the options. It's up to you to
|
140
|
+
# understand if you can relax this to "everysec" that will fsync every second
|
141
|
+
# or to "no" that will let the operating system flush the output buffer when
|
142
|
+
# it want, for better performances (but if you can live with the idea of
|
143
|
+
# some data loss consider the default persistence mode that's snapshotting).
|
144
|
+
|
145
|
+
appendfsync always
|
146
|
+
# appendfsync everysec
|
147
|
+
# appendfsync no
|
148
|
+
|
110
149
|
############################### ADVANCED CONFIG ###############################
|
111
150
|
|
112
151
|
# Glue small output buffers together in order to send small replies in a
|
data/spec/config/slave.conf
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
# By default Redis does not run as a daemon. Use 'yes' if you need it.
|
4
4
|
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
|
5
|
-
daemonize
|
5
|
+
daemonize no
|
6
6
|
|
7
7
|
# When run as a daemon, Redis write a pid file in /var/run/redis.pid by default.
|
8
8
|
# You can specify a custom pid file location here.
|
9
|
-
pidfile
|
9
|
+
pidfile /var/run/redis.pid
|
10
10
|
|
11
11
|
# Accept connections on the specified port, default is 6379
|
12
12
|
port 6381
|
@@ -14,7 +14,7 @@ port 6381
|
|
14
14
|
# If you want you can bind a single interface, if the bind option is not
|
15
15
|
# specified all the interfaces will listen for connections.
|
16
16
|
#
|
17
|
-
bind 127.0.0.1
|
17
|
+
# bind 127.0.0.1
|
18
18
|
|
19
19
|
# Close the connection after a client is idle for N seconds (0 to disable)
|
20
20
|
timeout 300
|
@@ -35,11 +35,11 @@ save 300 10
|
|
35
35
|
save 60 10000
|
36
36
|
|
37
37
|
# The filename where to dump the DB
|
38
|
-
dbfilename slave.rdb
|
38
|
+
dbfilename slave-dump.rdb
|
39
39
|
|
40
40
|
# For default save/load DB in/from the working directory
|
41
41
|
# Note that you must specify a directory not a file name.
|
42
|
-
dir ./
|
42
|
+
dir ./
|
43
43
|
|
44
44
|
# Set server verbosity to 'debug'
|
45
45
|
# it can be one of:
|
@@ -65,7 +65,7 @@ databases 16
|
|
65
65
|
# so for example it is possible to configure the slave to save the DB with a
|
66
66
|
# different interval, or to listen to another port, and so on.
|
67
67
|
|
68
|
-
slaveof
|
68
|
+
slaveof localhost 6380
|
69
69
|
|
70
70
|
################################## SECURITY ###################################
|
71
71
|
|
@@ -107,6 +107,45 @@ slaveof 127.0.0.1 6380
|
|
107
107
|
|
108
108
|
# maxmemory <bytes>
|
109
109
|
|
110
|
+
############################## APPEND ONLY MODE ###############################
|
111
|
+
|
112
|
+
# By default Redis asynchronously dumps the dataset on disk. If you can live
|
113
|
+
# with the idea that the latest records will be lost if something like a crash
|
114
|
+
# happens this is the preferred way to run Redis. If instead you care a lot
|
115
|
+
# about your data and don't want to that a single record can get lost you should
|
116
|
+
# enable the append only mode: when this mode is enabled Redis will append
|
117
|
+
# every write operation received in the file appendonly.log. This file will
|
118
|
+
# be read on startup in order to rebuild the full dataset in memory.
|
119
|
+
#
|
120
|
+
# Note that you can have both the async dumps and the append only file if you
|
121
|
+
# like (you have to comment the "save" statements above to disable the dumps).
|
122
|
+
# Still if append only mode is enabled Redis will load the data from the
|
123
|
+
# log file at startup ignoring the dump.rdb file.
|
124
|
+
#
|
125
|
+
# The name of the append only file is "appendonly.log"
|
126
|
+
|
127
|
+
appendonly no
|
128
|
+
|
129
|
+
# The fsync() call tells the Operating System to actually write data on disk
|
130
|
+
# instead to wait for more data in the output buffer. Some OS will really flush
|
131
|
+
# data on disk, some other OS will just try to do it ASAP.
|
132
|
+
#
|
133
|
+
# Redis supports three different modes:
|
134
|
+
#
|
135
|
+
# no: don't fsync, just let the OS flush the data when it wants. Faster.
|
136
|
+
# always: fsync after every write to the append only log . Slow, Safest.
|
137
|
+
# everysec: fsync only if one second passed since the last fsync. Compromise.
|
138
|
+
#
|
139
|
+
# The default is "always" that's the safer of the options. It's up to you to
|
140
|
+
# understand if you can relax this to "everysec" that will fsync every second
|
141
|
+
# or to "no" that will let the operating system flush the output buffer when
|
142
|
+
# it want, for better performances (but if you can live with the idea of
|
143
|
+
# some data loss consider the default persistence mode that's snapshotting).
|
144
|
+
|
145
|
+
appendfsync always
|
146
|
+
# appendfsync everysec
|
147
|
+
# appendfsync no
|
148
|
+
|
110
149
|
############################### ADVANCED CONFIG ###############################
|
111
150
|
|
112
151
|
# Glue small output buffers together in order to send small replies in a
|
@@ -2,48 +2,53 @@ require File.join(File.dirname(__FILE__), "/../spec_helper")
|
|
2
2
|
|
3
3
|
describe "MarshaledRedis" do
|
4
4
|
before(:each) do
|
5
|
-
@
|
5
|
+
@store = MarshaledRedis.new
|
6
6
|
@rabbit = OpenStruct.new :name => "bunny"
|
7
7
|
@white_rabbit = OpenStruct.new :color => "white"
|
8
|
-
@
|
9
|
-
@
|
8
|
+
@store.set "rabbit", @rabbit
|
9
|
+
@store.delete "rabbit2"
|
10
|
+
end
|
11
|
+
|
12
|
+
after :each do
|
13
|
+
@store.quit
|
10
14
|
end
|
11
15
|
|
12
16
|
it "should unmarshal an object on get" do
|
13
|
-
@
|
17
|
+
@store.get("rabbit").should === @rabbit
|
14
18
|
end
|
15
19
|
|
16
20
|
it "should marshal object on set" do
|
17
|
-
@
|
18
|
-
@
|
21
|
+
@store.set "rabbit", @white_rabbit
|
22
|
+
@store.get("rabbit").should === @white_rabbit
|
19
23
|
end
|
20
24
|
|
21
25
|
it "should not unmarshal object on get if raw option is true" do
|
22
|
-
@
|
26
|
+
@store.get("rabbit", :raw => true).should == "\004\bU:\017OpenStruct{\006:\tname\"\nbunny"
|
23
27
|
end
|
24
28
|
|
25
29
|
it "should not marshal object on set if raw option is true" do
|
26
|
-
@
|
27
|
-
@
|
30
|
+
@store.set "rabbit", @white_rabbit, :raw => true
|
31
|
+
@store.get("rabbit", :raw => true).should == %(#<OpenStruct color="white">)
|
28
32
|
end
|
29
33
|
|
30
34
|
it "should not unmarshal object if getting an empty string" do
|
31
|
-
@
|
32
|
-
lambda { @
|
35
|
+
@store.set "empty_string", ""
|
36
|
+
lambda { @store.get("empty_string").should == "" }.should_not raise_error
|
33
37
|
end
|
34
38
|
|
35
39
|
it "should not set an object if already exist" do
|
36
|
-
@
|
37
|
-
@
|
40
|
+
@store.set_unless_exists "rabbit", @white_rabbit
|
41
|
+
@store.get("rabbit").should === @rabbit
|
38
42
|
end
|
39
43
|
|
40
44
|
it "should marshal object on set_unless_exists" do
|
41
|
-
@
|
42
|
-
@
|
45
|
+
@store.set_unless_exists "rabbit2", @white_rabbit
|
46
|
+
@store.get("rabbit2").should === @white_rabbit
|
43
47
|
end
|
44
48
|
|
45
49
|
it "should not marshal object on set_unless_exists if raw option is true" do
|
46
|
-
@
|
47
|
-
@
|
50
|
+
@store.set_unless_exists "rabbit2", @white_rabbit, :raw => true
|
51
|
+
@store.get("rabbit2", :raw => true).should == %(#<OpenStruct color="white">)
|
48
52
|
end
|
49
53
|
end
|
54
|
+
|
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
$: << File.join(File.dirname(__FILE__), "/../lib")
|
2
|
-
require "
|
2
|
+
require "vendor/gems/environment"
|
3
3
|
require "ostruct"
|
4
4
|
require "spec"
|
5
5
|
require "redis"
|
@@ -14,3 +14,4 @@ require "cache/sinatra/redis_store"
|
|
14
14
|
|
15
15
|
class Redis; attr_reader :host, :port, :db end
|
16
16
|
$DEBUG = ENV["DEBUG"] === "true"
|
17
|
+
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# steal the cool tasks from redis-rb
|
2
|
+
begin
|
3
|
+
load File.join(File.dirname(__FILE__), "/../vendor/gems/gems/redis-rb-0.1/tasks/redis.tasks.rb")
|
4
|
+
rescue LoadError
|
5
|
+
end
|
6
|
+
|
7
|
+
class RedisRunner
|
8
|
+
def self.port
|
9
|
+
6379
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.stop
|
13
|
+
system %(echo "SHUTDOWN" | nc localhost #{port})
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class SingleRedisRunner < RedisRunner
|
18
|
+
def self.redisconfdir
|
19
|
+
File.expand_path(File.dirname(__FILE__) + "/../spec/config/single.conf")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class MasterRedisRunner < RedisRunner
|
24
|
+
def self.redisconfdir
|
25
|
+
File.expand_path(File.dirname(__FILE__) + "/../spec/config/master.conf")
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.dtach_socket
|
29
|
+
"/tmp/redis_master.dtach"
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.port
|
33
|
+
6380
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class SlaveRedisRunner < RedisRunner
|
38
|
+
def self.redisconfdir
|
39
|
+
File.expand_path(File.dirname(__FILE__) + "/../spec/config/slave.conf")
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.dtach_socket
|
43
|
+
"/tmp/redis_slave.dtach"
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.port
|
47
|
+
6381
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class RedisClusterRunner
|
52
|
+
def self.runners
|
53
|
+
[ SingleRedisRunner, MasterRedisRunner, SlaveRedisRunner ]
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.start_detached
|
57
|
+
runners.each do |runner|
|
58
|
+
runner.start_detached
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.stop
|
63
|
+
runners.each do |runner|
|
64
|
+
runner.stop
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Guidi
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-11-15 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -20,11 +20,14 @@ executables: []
|
|
20
20
|
extensions: []
|
21
21
|
|
22
22
|
extra_rdoc_files:
|
23
|
-
- README.
|
23
|
+
- README.md
|
24
24
|
files:
|
25
|
+
- .gitignore
|
26
|
+
- Gemfile
|
25
27
|
- MIT-LICENSE
|
26
|
-
- README.
|
28
|
+
- README.md
|
27
29
|
- Rakefile
|
30
|
+
- VERSION
|
28
31
|
- lib/cache/merb/redis_store.rb
|
29
32
|
- lib/cache/rails/redis_store.rb
|
30
33
|
- lib/cache/sinatra/redis_store.rb
|
@@ -51,13 +54,14 @@ files:
|
|
51
54
|
- spec/redis/marshaled_redis_spec.rb
|
52
55
|
- spec/redis/redis_factory_spec.rb
|
53
56
|
- spec/spec_helper.rb
|
57
|
+
- tasks/redis.tasks.rb
|
54
58
|
has_rdoc: true
|
55
|
-
homepage: http://
|
59
|
+
homepage: http://github.com/jodosha/redis-store
|
56
60
|
licenses: []
|
57
61
|
|
58
62
|
post_install_message:
|
59
|
-
rdoc_options:
|
60
|
-
|
63
|
+
rdoc_options:
|
64
|
+
- --charset=UTF-8
|
61
65
|
require_paths:
|
62
66
|
- lib
|
63
67
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -89,3 +93,4 @@ test_files:
|
|
89
93
|
- spec/redis/distributed_marshaled_redis_spec.rb
|
90
94
|
- spec/redis/marshaled_redis_spec.rb
|
91
95
|
- spec/redis/redis_factory_spec.rb
|
96
|
+
- spec/spec_helper.rb
|
data/README.textile
DELETED
@@ -1,102 +0,0 @@
|
|
1
|
-
h1. Rack::Session, Rack::Cache and cache Redis stores for Ruby web frameworks
|
2
|
-
|
3
|
-
h2. Installation
|
4
|
-
|
5
|
-
Download and install Redis from "http://code.google.com/p/redis/":http://code.google.com/p/redis/
|
6
|
-
|
7
|
-
curl -OL "http://redis.googlecode.com/files/redis-0.900_2.tar.gz":http://redis.googlecode.com/files/redis-0.900_2.tar.gz
|
8
|
-
tar -zxvf redis-0.900_2.tar.gz
|
9
|
-
mv redis-0.900_2 redis
|
10
|
-
cd redis
|
11
|
-
make
|
12
|
-
|
13
|
-
Install the gems
|
14
|
-
|
15
|
-
-sudo gem install ezmobius-redis-rb -s http://gems.github.com-
|
16
|
-
|
17
|
-
git clone git://github.com/ezmobius/redis-rb.git
|
18
|
-
cd redis-rb
|
19
|
-
sudo rake install
|
20
|
-
|
21
|
-
sudo gem install jodosha-redis-store -s http://gems.github.com
|
22
|
-
|
23
|
-
h2. Cache store
|
24
|
-
|
25
|
-
Provides a cache store for your Ruby web framework of choice.
|
26
|
-
|
27
|
-
h3. How to use with Rails
|
28
|
-
|
29
|
-
config.gem "jodosha-redis-store", :source => "http://gems.github.com", :lib => "redis-store"
|
30
|
-
require "redis-store"
|
31
|
-
config.cache_store = :redis_store
|
32
|
-
|
33
|
-
h3. How to use with Merb
|
34
|
-
|
35
|
-
dependency "jodosha-redis-store", "0.3.6"
|
36
|
-
dependency("merb-cache", merb_gems_version) do
|
37
|
-
Merb::Cache.setup do
|
38
|
-
register(:redis, Merb::Cache::RedisStore, :servers => ["127.0.0.1:6379"])
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
h3. How to use with Sinatra
|
43
|
-
|
44
|
-
require 'rubygems'
|
45
|
-
require 'sinatra'
|
46
|
-
require 'jodosha-redis-store'
|
47
|
-
class MyApp < Sinatra::Base
|
48
|
-
register Sinatra::Cache
|
49
|
-
get '/hi' do
|
50
|
-
cache.fetch("greet") { "Hello, World!" }
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
h2. Rack::Session
|
55
|
-
|
56
|
-
Provides a Redis store for Rack::Session. See "http://rack.rubyforge.org/doc/Rack/Session.html":http://rack.rubyforge.org/doc/Rack/Session.html
|
57
|
-
|
58
|
-
h3. How to use with a generic Rack application
|
59
|
-
|
60
|
-
require "rubygems"
|
61
|
-
require "rack"
|
62
|
-
require "jodosha-redis-store"
|
63
|
-
require "application"
|
64
|
-
use Rack::Session::Redis
|
65
|
-
run Application.new
|
66
|
-
|
67
|
-
h3. How to use with Rails
|
68
|
-
|
69
|
-
config.gem "jodosha-redis-store", :source => "http://gems.github.com", :lib => "redis-store"
|
70
|
-
ActionController::Base.session_store = Rack::Session::Redis
|
71
|
-
|
72
|
-
h3. How to use with Merb
|
73
|
-
|
74
|
-
dependency "jodosha-redis-store", "0.3.6"
|
75
|
-
Merb::Config.use do |c|
|
76
|
-
c[:session_store] = 'redis'
|
77
|
-
end
|
78
|
-
Merb::BootLoader.before_app_loads do
|
79
|
-
Merb::SessionContainer.subclasses << "Merb::RedisSession"
|
80
|
-
end
|
81
|
-
|
82
|
-
h3. How to use with Sinatra
|
83
|
-
|
84
|
-
Sorry, but Sinatra application boot system "hardcode":http://github.com/sinatra/sinatra/blob/0f02bafe86f8dd9bba9ab425468cb1067caa83ff/lib/sinatra/base.rb#L785 Rack::Session::Cookie
|
85
|
-
|
86
|
-
h2. Rack::Cache
|
87
|
-
|
88
|
-
Provides a Redis store for HTTP caching. See "http://github.com/rtomayko/rack-cache":http://github.com/rtomayko/rack-cache
|
89
|
-
|
90
|
-
require "rubygems"
|
91
|
-
require "rack"
|
92
|
-
require "rack/cache"
|
93
|
-
require "jodosha-redis-store"
|
94
|
-
require "application"
|
95
|
-
use Rack::Cache,
|
96
|
-
:metastore => 'redis://localhost:6379/0',
|
97
|
-
:entitystore => 'redis://localhost:6380/1'
|
98
|
-
run Application.new
|
99
|
-
|
100
|
-
h2. Copyright
|
101
|
-
|
102
|
-
(c) 2009 Luca Guidi - "http://lucaguidi.com":http://lucaguidi.com, released under the MIT license
|