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/lib/redis/store.rb CHANGED
@@ -1,3 +1,6 @@
1
+ require 'redis/store/ttl'
2
+ require 'redis/store/interface'
3
+
1
4
  class Redis
2
5
  class Store < self
3
6
  include Ttl, Interface
@@ -8,14 +11,6 @@ class Redis
8
11
  _extend_namespace options
9
12
  end
10
13
 
11
- def self.rails3? #:nodoc:
12
- defined?(::Rails) && ::Rails::VERSION::MAJOR == 3
13
- end
14
-
15
- def self.rails31? #:nodoc:
16
- defined?(::Rails) && ::Rails::VERSION::MAJOR == 3 && ::Rails::VERSION::MINOR == 1
17
- end
18
-
19
14
  def reconnect
20
15
  @client.reconnect
21
16
  end
@@ -12,6 +12,10 @@ class Redis
12
12
  def setnx(key, value, options = nil)
13
13
  super(key, value)
14
14
  end
15
+
16
+ def setex(key, expiry, value, options = nil)
17
+ super(key, expiry, value)
18
+ end
15
19
  end
16
20
  end
17
21
  end
@@ -9,6 +9,10 @@ class Redis
9
9
  _marshal(value, options) { |value| super encode(key), encode(value), options }
10
10
  end
11
11
 
12
+ def setex(key, expiry, value, options = nil)
13
+ _marshal(value, options) { |value| super encode(key), expiry, encode(value), options }
14
+ end
15
+
12
16
  def get(key, options = nil)
13
17
  _unmarshal super(key), options
14
18
  end
@@ -1,12 +1,5 @@
1
1
  class Redis
2
2
  class Store < self
3
- module VERSION #:nodoc:
4
- MAJOR = 1
5
- MINOR = 0
6
- TINY = 0
7
- BUILD = 1
8
-
9
- STRING = [MAJOR, MINOR, TINY, BUILD].join('.')
10
- end
3
+ VERSION = '1.1.0.rc'
11
4
  end
12
5
  end
@@ -0,0 +1,167 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'fileutils'
4
+ require 'open-uri'
5
+
6
+ class RedisRunner
7
+ def self.redisdir
8
+ File.expand_path("../../../vendor/redis", __FILE__)
9
+ end
10
+
11
+ def self.configuration
12
+ File.expand_path("../../../test/config/redis.conf", __FILE__)
13
+ end
14
+
15
+ def self.pid_file
16
+ File.expand_path(Dir.pwd + "/tmp/pids/redis.pid")
17
+ end
18
+
19
+ def self.pid
20
+ File.open(pid_file).read.to_i
21
+ end
22
+
23
+ def self.start
24
+ system %(redis-server #{configuration})
25
+ end
26
+
27
+ def self.stop
28
+ begin
29
+ Process.kill('SIGTERM', pid)
30
+ rescue
31
+ # Suppress exceptions for Travis CI
32
+ end
33
+ end
34
+ end
35
+
36
+ class NodeOneRedisRunner < RedisRunner
37
+ def self.configuration
38
+ File.expand_path("../../../test/config/node-one.conf", __FILE__)
39
+ end
40
+
41
+ def self.pid_file
42
+ File.expand_path(Dir.pwd + "/tmp/pids/node-one.pid")
43
+ end
44
+ end
45
+
46
+ class NodeTwoRedisRunner < RedisRunner
47
+ def self.configuration
48
+ File.expand_path("../../../test/config/node-two.conf", __FILE__)
49
+ end
50
+
51
+ def self.pid_file
52
+ File.expand_path(Dir.pwd + "/tmp/pids/node-two.pid")
53
+ end
54
+ end
55
+
56
+ class RedisReplicationRunner
57
+ def self.runners
58
+ [ RedisRunner, NodeOneRedisRunner, NodeTwoRedisRunner ]
59
+ end
60
+
61
+ def self.start
62
+ runners.each do |runner|
63
+ runner.start
64
+ end
65
+ end
66
+
67
+ def self.stop
68
+ runners.each do |runner|
69
+ runner.stop
70
+ end
71
+ end
72
+ end
73
+
74
+ namespace :redis do
75
+ desc 'About redis'
76
+ task :about do
77
+ puts "\nSee http://code.google.com/p/redis/ for information about redis.\n\n"
78
+ end
79
+
80
+ desc 'Install the lastest verison of Redis from Github (requires git, duh)'
81
+ task :install => [ :about, :download, :make ] do
82
+ %w(redis-benchmark redis-cli redis-server).each do |bin|
83
+ if File.exist?(path = "#{RedisRunner.redisdir}/src/#{bin}")
84
+ sh "sudo cp #{path} /usr/bin/"
85
+ else
86
+ sh "sudo cp #{RedisRunner.redisdir}/#{bin} /usr/bin/"
87
+ end
88
+ end
89
+
90
+ puts "Installed redis-benchmark, redis-cli and redis-server to /usr/bin/"
91
+
92
+ sh "sudo cp #{RedisRunner.redisdir}/redis.conf /etc/"
93
+ puts "Installed redis.conf to /etc/ \n You should look at this file!"
94
+ end
95
+
96
+ task :make do
97
+ sh "cd #{RedisRunner.redisdir} && make clean"
98
+ sh "cd #{RedisRunner.redisdir} && make"
99
+ end
100
+
101
+ desc "Download package"
102
+ task :download do
103
+ require 'git'
104
+
105
+ sh "rm -rf #{RedisRunner.redisdir} && mkdir -p vendor && rm -rf redis"
106
+ Git.clone("git://github.com/antirez/redis.git", "redis")
107
+ sh "mv redis vendor"
108
+
109
+ commit = case ENV['VERSION']
110
+ when "1.3.12" then "26ef09a83526e5099bce"
111
+ when "2.2.12" then "5960ac9dec5184bf4184"
112
+ when "2.2.4" then "2b886275e9756bb8619a"
113
+ when "2.0.5" then "9b695bb0a00c01ad4d55"
114
+ end
115
+
116
+ arguments = commit.nil? ? "pull origin master" : "reset --hard #{commit}"
117
+ sh "cd #{RedisRunner.redisdir} && git #{arguments}"
118
+ end
119
+
120
+ namespace :test do
121
+ desc "Run all the examples by starting a background Redis instance"
122
+ task :suite => 'redis:test:prepare' do
123
+ invoke_with_redis_replication 'redis:test:run'
124
+ end
125
+
126
+ Rake::TestTask.new(:run) do |t|
127
+ t.libs.push 'lib'
128
+ t.test_files = FileList['test/**/*_test.rb']
129
+ t.ruby_opts = ["-I test"]
130
+ t.verbose = true
131
+ end
132
+
133
+ task :prepare do
134
+ FileUtils.mkdir_p 'tmp/pids'
135
+ FileUtils.rm Dir.glob('tmp/*.rdb')
136
+ end
137
+ end
138
+
139
+ namespace :replication do
140
+ desc "Starts redis replication servers"
141
+ task :start do
142
+ RedisReplicationRunner.start
143
+ end
144
+
145
+ desc "Stops redis replication servers"
146
+ task :stop do
147
+ RedisReplicationRunner.stop
148
+ end
149
+
150
+ desc "Open an IRb session with the master/slave replication"
151
+ task :console do
152
+ RedisReplicationRunner.start
153
+ system "bundle exec irb -I lib -I extra -r redis-store.rb"
154
+ RedisReplicationRunner.stop
155
+ end
156
+ end
157
+ end
158
+
159
+ def invoke_with_redis_replication(task_name)
160
+ begin
161
+ Rake::Task["redis:replication:start"].invoke
162
+ Rake::Task[task_name].invoke
163
+ ensure
164
+ Rake::Task["redis:replication:stop"].invoke
165
+ end
166
+ end
167
+
data/redis-store.gemspec CHANGED
@@ -1,105 +1,30 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "redis/store/version"
5
4
 
6
5
  Gem::Specification.new do |s|
7
- s.name = %q{redis-store}
8
- s.version = "1.0.0.1"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = [%q{Luca Guidi}]
12
- s.date = %q{2011-09-06}
6
+ s.name = "redis-store"
7
+ s.version = Redis::Store::VERSION
8
+ s.authors = ["Luca Guidi"]
9
+ s.email = ["guidi.luca@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Redis stores for Ruby frameworks}
13
12
  s.description = %q{Namespaced Rack::Session, Rack::Cache, I18n 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
- ".travis.yml",
20
- "CHANGELOG",
21
- "Gemfile",
22
- "MIT-LICENSE",
23
- "README.md",
24
- "Rakefile",
25
- "VERSION",
26
- "lib/action_controller/session/redis_session_store.rb",
27
- "lib/active_support/cache/redis_store.rb",
28
- "lib/cache/merb/redis_store.rb",
29
- "lib/cache/sinatra/redis_store.rb",
30
- "lib/i18n/backend/redis.rb",
31
- "lib/rack/cache/redis_entitystore.rb",
32
- "lib/rack/cache/redis_metastore.rb",
33
- "lib/rack/session/merb.rb",
34
- "lib/rack/session/redis.rb",
35
- "lib/redis-store.rb",
36
- "lib/redis/distributed_store.rb",
37
- "lib/redis/factory.rb",
38
- "lib/redis/store.rb",
39
- "lib/redis/store/interface.rb",
40
- "lib/redis/store/marshalling.rb",
41
- "lib/redis/store/namespace.rb",
42
- "lib/redis/store/ttl.rb",
43
- "lib/redis/store/version.rb",
44
- "redis-store.gemspec",
45
- "spec/action_controller/session/redis_session_store_spec.rb",
46
- "spec/active_support/cache/redis_store_spec.rb",
47
- "spec/cache/merb/redis_store_spec.rb",
48
- "spec/cache/sinatra/redis_store_spec.rb",
49
- "spec/config/node-one.conf",
50
- "spec/config/node-two.conf",
51
- "spec/config/redis.conf",
52
- "spec/i18n/backend/redis_spec.rb",
53
- "spec/rack/cache/entitystore/pony.jpg",
54
- "spec/rack/cache/entitystore/redis_spec.rb",
55
- "spec/rack/cache/metastore/redis_spec.rb",
56
- "spec/rack/session/redis_spec.rb",
57
- "spec/redis/distributed_store_spec.rb",
58
- "spec/redis/factory_spec.rb",
59
- "spec/redis/store/interface_spec.rb",
60
- "spec/redis/store/marshalling_spec.rb",
61
- "spec/redis/store/namespace_spec.rb",
62
- "spec/redis/store/version_spec.rb",
63
- "spec/redis/store_spec.rb",
64
- "spec/spec_helper.rb",
65
- "tasks/redis.tasks.rb"
66
- ]
67
- s.homepage = %q{http://github.com/jodosha/redis-store}
68
- s.require_paths = [%q{lib}]
69
- s.rubygems_version = %q{1.8.6}
70
- s.summary = %q{Namespaced Rack::Session, Rack::Cache, I18n and cache Redis stores for Ruby web frameworks.}
71
13
 
72
- if s.respond_to? :specification_version then
73
- s.specification_version = 3
14
+ s.rubyforge_project = "redis-store"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency 'redis', '~> 2.2.0'
74
22
 
75
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
76
- s.add_runtime_dependency(%q<redis>, ["~> 2.2.1"])
77
- s.add_development_dependency(%q<jeweler>, [">= 0"])
78
- s.add_development_dependency(%q<git>, [">= 0"])
79
- s.add_development_dependency(%q<rack-cache>, [">= 0"])
80
- s.add_development_dependency(%q<merb>, ["= 1.1.0"])
81
- s.add_development_dependency(%q<rspec>, ["= 1.3.0"])
82
- s.add_development_dependency(%q<i18n>, [">= 0"])
83
- s.add_development_dependency(%q<ruby-debug>, [">= 0"])
84
- else
85
- s.add_dependency(%q<redis>, ["~> 2.2.1"])
86
- s.add_dependency(%q<jeweler>, [">= 0"])
87
- s.add_dependency(%q<git>, [">= 0"])
88
- s.add_dependency(%q<rack-cache>, [">= 0"])
89
- s.add_dependency(%q<merb>, ["= 1.1.0"])
90
- s.add_dependency(%q<rspec>, ["= 1.3.0"])
91
- s.add_dependency(%q<i18n>, [">= 0"])
92
- s.add_dependency(%q<ruby-debug>, [">= 0"])
93
- end
94
- else
95
- s.add_dependency(%q<redis>, ["~> 2.2.1"])
96
- s.add_dependency(%q<jeweler>, [">= 0"])
97
- s.add_dependency(%q<git>, [">= 0"])
98
- s.add_dependency(%q<rack-cache>, [">= 0"])
99
- s.add_dependency(%q<merb>, ["= 1.1.0"])
100
- s.add_dependency(%q<rspec>, ["= 1.3.0"])
101
- s.add_dependency(%q<i18n>, [">= 0"])
102
- s.add_dependency(%q<ruby-debug>, [">= 0"])
103
- end
23
+ s.add_development_dependency 'rake', '~> 0.9.2.2'
24
+ s.add_development_dependency 'bundler', '~> 1.1.rc'
25
+ s.add_development_dependency 'mocha', '~> 0.10.0'
26
+ s.add_development_dependency 'minitest', '~> 2.8.0'
27
+ s.add_development_dependency 'purdytest', '~> 1.0.0'
28
+ s.add_development_dependency 'git', '~> 1.2.5'
104
29
  end
105
30
 
@@ -14,11 +14,11 @@
14
14
 
15
15
  # By default Redis does not run as a daemon. Use 'yes' if you need it.
16
16
  # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
17
- daemonize no
17
+ daemonize yes
18
18
 
19
19
  # When running daemonized, Redis writes a pid file in /var/run/redis.pid by
20
20
  # default. You can specify a custom pid file location here.
21
- pidfile /var/run/redis.pid
21
+ pidfile ./tmp/pids/node-one.pid
22
22
 
23
23
  # Accept connections on the specified port, default is 6379.
24
24
  # If port 0 is specified Redis will not listen on a TCP socket.
@@ -14,11 +14,11 @@
14
14
 
15
15
  # By default Redis does not run as a daemon. Use 'yes' if you need it.
16
16
  # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
17
- daemonize no
17
+ daemonize yes
18
18
 
19
19
  # When running daemonized, Redis writes a pid file in /var/run/redis.pid by
20
20
  # default. You can specify a custom pid file location here.
21
- pidfile /var/run/redis.pid
21
+ pidfile ./tmp/pids/node-two.pid
22
22
 
23
23
  # Accept connections on the specified port, default is 6379.
24
24
  # If port 0 is specified Redis will not listen on a TCP socket.
@@ -14,11 +14,12 @@
14
14
 
15
15
  # By default Redis does not run as a daemon. Use 'yes' if you need it.
16
16
  # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
17
- daemonize no
17
+ daemonize yes
18
18
 
19
19
  # When running daemonized, Redis writes a pid file in /var/run/redis.pid by
20
20
  # default. You can specify a custom pid file location here.
21
- pidfile /var/run/redis.pid
21
+ # pidfile /var/run/redis.pid
22
+ pidfile ./tmp/pids/redis.pid
22
23
 
23
24
  # Accept connections on the specified port, default is 6379.
24
25
  # If port 0 is specified Redis will not listen on a TCP socket.
@@ -1,7 +1,7 @@
1
- require 'spec_helper'
1
+ require 'test_helper'
2
2
 
3
3
  describe "Redis::DistributedStore" do
4
- before(:each) do
4
+ def setup
5
5
  @dmr = Redis::DistributedStore.new [
6
6
  {:host => "localhost", :port => "6380", :db => 0},
7
7
  {:host => "localhost", :port => "6381", :db => 0}
@@ -11,44 +11,42 @@ describe "Redis::DistributedStore" do
11
11
  @dmr.set "rabbit", @rabbit
12
12
  end
13
13
 
14
- after(:all) do
14
+ def teardown
15
15
  @dmr.ring.nodes.each { |server| server.flushdb }
16
16
  end
17
17
 
18
- it "should accept connection params" do
18
+ it "accepts connection params" do
19
19
  dmr = Redis::DistributedStore.new [ :host => "localhost", :port => "6380", :db => "1" ]
20
20
  dmr.ring.nodes.size == 1
21
21
  mr = dmr.ring.nodes.first
22
- mr.to_s.should == "Redis Client connected to localhost:6380 against DB 1"
22
+ mr.to_s.must_equal("Redis Client connected to localhost:6380 against DB 1")
23
23
  end
24
24
 
25
- it "should force reconnection" do
25
+ it "forces reconnection" do
26
26
  @dmr.nodes.each do |node|
27
- node.should_receive(:reconnect)
27
+ node.expects(:reconnect)
28
28
  end
29
29
 
30
30
  @dmr.reconnect
31
31
  end
32
32
 
33
- it "should set an object" do
33
+ it "sets an object" do
34
34
  @dmr.set "rabbit", @white_rabbit
35
- @dmr.get("rabbit").should == @white_rabbit
35
+ @dmr.get("rabbit").must_equal(@white_rabbit)
36
36
  end
37
37
 
38
- it "should get an object" do
39
- @dmr.get("rabbit").should == @rabbit
38
+ it "gets an object" do
39
+ @dmr.get("rabbit").must_equal(@rabbit)
40
40
  end
41
41
 
42
42
  describe "namespace" do
43
- before :each do
43
+ it "uses namespaced key" do
44
44
  @dmr = Redis::DistributedStore.new [
45
45
  {:host => "localhost", :port => "6380", :db => 0},
46
46
  {:host => "localhost", :port => "6381", :db => 0}
47
47
  ], :namespace => "theplaylist"
48
- end
49
48
 
50
- it "should use namespaced key" do
51
- @dmr.should_receive(:node_for).with("theplaylist:rabbit").and_return @dmr.nodes.first
49
+ @dmr.expects(:node_for).with("theplaylist:rabbit").returns(@dmr.nodes.first)
52
50
  @dmr.get "rabbit"
53
51
  end
54
52
  end