redis-actionpack-json 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data/.gitignore +15 -0
  2. data/.travis.yml +7 -0
  3. data/CHANGELOG +450 -0
  4. data/README.md +23 -0
  5. data/redis-actionpack-json/.gitignore +4 -0
  6. data/redis-actionpack-json/Gemfile +6 -0
  7. data/redis-actionpack-json/MIT-LICENSE +20 -0
  8. data/redis-actionpack-json/Rakefile +8 -0
  9. data/redis-actionpack-json/lib/action_dispatch/middleware/session/redis_store_json.rb +24 -0
  10. data/redis-actionpack-json/lib/redis-actionpack-json.rb +4 -0
  11. data/redis-actionpack-json/lib/redis/actionpack/version.rb +5 -0
  12. data/redis-actionpack-json/redis-actionpack-json.gemspec +32 -0
  13. data/redis-actionpack-json/test/dummy/.gitignore +1 -0
  14. data/redis-actionpack-json/test/dummy/Rakefile +7 -0
  15. data/redis-actionpack-json/test/dummy/app/controllers/test_controller.rb +37 -0
  16. data/redis-actionpack-json/test/dummy/config.ru +4 -0
  17. data/redis-actionpack-json/test/dummy/config/application.rb +29 -0
  18. data/redis-actionpack-json/test/dummy/config/boot.rb +10 -0
  19. data/redis-actionpack-json/test/dummy/config/environment.rb +5 -0
  20. data/redis-actionpack-json/test/dummy/config/initializers/secret_token.rb +7 -0
  21. data/redis-actionpack-json/test/dummy/config/initializers/session_store.rb +11 -0
  22. data/redis-actionpack-json/test/dummy/config/routes.rb +3 -0
  23. data/redis-actionpack-json/test/dummy/script/rails +6 -0
  24. data/redis-actionpack-json/test/fixtures/session_autoload_test/session_autoload_test/foo.rb +10 -0
  25. data/redis-actionpack-json/test/integration/redis_store_integration_test.rb +130 -0
  26. data/redis-actionpack-json/test/integration/redis_store_json_integration_test.rb +130 -0
  27. data/redis-actionpack-json/test/redis/actionpack/version_test.rb +7 -0
  28. data/redis-actionpack-json/test/test_helper.rb +23 -0
  29. data/redis-rack-json/.gitignore +5 -0
  30. data/redis-rack-json/Gemfile +5 -0
  31. data/redis-rack-json/MIT-LICENSE +20 -0
  32. data/redis-rack-json/Rakefile +8 -0
  33. data/redis-rack-json/lib/rack/session/redis.rb +69 -0
  34. data/redis-rack-json/lib/redis-rack-json.rb +3 -0
  35. data/redis-rack-json/lib/redis/rack/version.rb +6 -0
  36. data/redis-rack-json/redis-rack-json.gemspec +29 -0
  37. data/redis-rack-json/test/rack/session/redis_test.rb +289 -0
  38. data/redis-rack-json/test/redis/rack/version_test.rb +7 -0
  39. data/redis-rack-json/test/test_helper.rb +7 -0
  40. data/redis-store-json/Gemfile +4 -0
  41. data/redis-store-json/MIT-LICENSE +20 -0
  42. data/redis-store-json/Rakefile +7 -0
  43. data/redis-store-json/lib/redis-store-json.rb +11 -0
  44. data/redis-store-json/lib/redis/distributed_store.rb +46 -0
  45. data/redis-store-json/lib/redis/factory.rb +41 -0
  46. data/redis-store-json/lib/redis/store.rb +47 -0
  47. data/redis-store-json/lib/redis/store/interface.rb +21 -0
  48. data/redis-store-json/lib/redis/store/namespace.rb +66 -0
  49. data/redis-store-json/lib/redis/store/strategy.rb +60 -0
  50. data/redis-store-json/lib/redis/store/strategy/json.rb +49 -0
  51. data/redis-store-json/lib/redis/store/strategy/json_session.rb +67 -0
  52. data/redis-store-json/lib/redis/store/strategy/marshal.rb +16 -0
  53. data/redis-store-json/lib/redis/store/strategy/yaml.rb +16 -0
  54. data/redis-store-json/lib/redis/store/ttl.rb +37 -0
  55. data/redis-store-json/lib/redis/store/version.rb +5 -0
  56. data/redis-store-json/lib/tasks/redis.tasks.rb +167 -0
  57. data/redis-store-json/redis-store-json.gemspec +29 -0
  58. data/redis-store-json/test/config/node-one.conf +46 -0
  59. data/redis-store-json/test/config/node-two.conf +46 -0
  60. data/redis-store-json/test/config/redis.conf +46 -0
  61. data/redis-store-json/test/redis/distributed_store_test.rb +53 -0
  62. data/redis-store-json/test/redis/factory_test.rb +120 -0
  63. data/redis-store-json/test/redis/store/interface_test.rb +27 -0
  64. data/redis-store-json/test/redis/store/namespace_test.rb +103 -0
  65. data/redis-store-json/test/redis/store/strategy/json_session_test.rb +160 -0
  66. data/redis-store-json/test/redis/store/strategy/json_test.rb +108 -0
  67. data/redis-store-json/test/redis/store/strategy/marshal_test.rb +121 -0
  68. data/redis-store-json/test/redis/store/strategy/yaml_test.rb +105 -0
  69. data/redis-store-json/test/redis/store/ttl_test.rb +107 -0
  70. data/redis-store-json/test/redis/store/version_test.rb +7 -0
  71. data/redis-store-json/test/redis/store_test.rb +45 -0
  72. data/redis-store-json/test/test_helper.rb +22 -0
  73. metadata +279 -0
@@ -0,0 +1,16 @@
1
+ class Redis
2
+ class Store < self
3
+ module Strategy
4
+ module Marshal
5
+ private
6
+ def _dump(object)
7
+ ::Marshal.dump(object)
8
+ end
9
+
10
+ def _load(string)
11
+ ::Marshal.load(string)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ class Redis
2
+ class Store < self
3
+ module Strategy
4
+ module Yaml
5
+ private
6
+ def _dump(object)
7
+ YAML.dump(object)
8
+ end
9
+
10
+ def _load(string)
11
+ YAML.load(string)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,37 @@
1
+ class Redis
2
+ class Store < self
3
+ module Ttl
4
+ def set(key, value, options = nil)
5
+ if ttl = expires_in(options)
6
+ setex(key, ttl.to_i, value, :raw => true)
7
+ else
8
+ super(key, value)
9
+ end
10
+ end
11
+
12
+ def setnx(key, value, options = nil)
13
+ if ttl = expires_in(options)
14
+ setnx_with_expire(key, value, ttl.to_i)
15
+ else
16
+ super(key, value)
17
+ end
18
+ end
19
+
20
+ protected
21
+ def setnx_with_expire(key, value, ttl)
22
+ multi do
23
+ setnx(key, value, :raw => true)
24
+ expire(key, ttl)
25
+ end
26
+ end
27
+
28
+ private
29
+ def expires_in(options)
30
+ if options
31
+ # Rack::Session Merb Rails/Sinatra
32
+ options[:expire_after] || options[:expires_in] || options[:expire_in]
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,5 @@
1
+ class Redis
2
+ class Store < self
3
+ VERSION = '3.0.0'
4
+ end
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-json.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
+
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'redis/store/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'redis-store-json'
7
+ s.version = Redis::Store::VERSION
8
+ s.authors = ["Nathan Tsoi", "Luca Guidi", "Matt Horan"]
9
+ s.email = ["nathan@vertile.com"]
10
+ s.homepage = "http://github.com/nathantsoi/redis-store-json"
11
+ s.summary = "Rails 4 Redis session store for ActionPack with JSON serialization"
12
+ s.description = "Rails 4 Redis session store for ActionPack with JSON serialization"
13
+
14
+ s.rubyforge_project = 'redis-store-json'
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', '~> 3.0.0'
22
+
23
+ s.add_development_dependency 'rake', '~> 10'
24
+ s.add_development_dependency 'bundler', '~> 1.2'
25
+ s.add_development_dependency 'mocha', '~> 0.13.0'
26
+ s.add_development_dependency 'minitest', '~> 4.3.1'
27
+ s.add_development_dependency 'git', '~> 1.2.5'
28
+ end
29
+
@@ -0,0 +1,46 @@
1
+ daemonize yes
2
+ pidfile ./tmp/pids/node-one.pid
3
+ port 6380
4
+ timeout 0
5
+ loglevel verbose
6
+ logfile stdout
7
+ databases 16
8
+
9
+ save 900 1
10
+ save 300 10
11
+ save 60 10000
12
+
13
+ # stop-writes-on-bgsave-error yes
14
+ rdbcompression yes
15
+ # rdbchecksum yes
16
+ dbfilename tmp/node-one-dump.rdb
17
+ dir ./
18
+
19
+ slave-serve-stale-data yes
20
+ # slave-read-only yes
21
+ # slave-priority 100
22
+
23
+ appendonly no
24
+ appendfsync everysec
25
+ no-appendfsync-on-rewrite no
26
+ # auto-aof-rewrite-percentage 100
27
+ # auto-aof-rewrite-min-size 64mb
28
+
29
+ # lua-time-limit 5000
30
+
31
+ # slowlog-log-slower-than 10000
32
+ # slowlog-max-len 128
33
+
34
+ # hash-max-ziplist-entries 512
35
+ # hash-max-ziplist-value 64
36
+ list-max-ziplist-entries 512
37
+ list-max-ziplist-value 64
38
+ set-max-intset-entries 512
39
+ # zset-max-ziplist-entries 128
40
+ # zset-max-ziplist-value 64
41
+
42
+ activerehashing yes
43
+
44
+ # client-output-buffer-limit normal 0 0 0
45
+ # client-output-buffer-limit slave 256mb 64mb 60
46
+ # client-output-buffer-limit pubsub 32mb 8mb 60
@@ -0,0 +1,46 @@
1
+ daemonize yes
2
+ pidfile ./tmp/pids/node-two.pid
3
+ port 6381
4
+ timeout 0
5
+ loglevel verbose
6
+ logfile stdout
7
+ databases 16
8
+
9
+ save 900 1
10
+ save 300 10
11
+ save 60 10000
12
+
13
+ # stop-writes-on-bgsave-error yes
14
+ rdbcompression yes
15
+ # rdbchecksum yes
16
+ dbfilename tmp/node-two-dump.rdb
17
+ dir ./
18
+
19
+ slave-serve-stale-data yes
20
+ # slave-read-only yes
21
+ # slave-priority 100
22
+
23
+ appendonly no
24
+ appendfsync everysec
25
+ no-appendfsync-on-rewrite no
26
+ # auto-aof-rewrite-percentage 100
27
+ # auto-aof-rewrite-min-size 64mb
28
+
29
+ # lua-time-limit 5000
30
+
31
+ # slowlog-log-slower-than 10000
32
+ # slowlog-max-len 128
33
+
34
+ # hash-max-ziplist-entries 512
35
+ # hash-max-ziplist-value 64
36
+ list-max-ziplist-entries 512
37
+ list-max-ziplist-value 64
38
+ set-max-intset-entries 512
39
+ # zset-max-ziplist-entries 128
40
+ # zset-max-ziplist-value 64
41
+
42
+ activerehashing yes
43
+
44
+ # client-output-buffer-limit normal 0 0 0
45
+ # client-output-buffer-limit slave 256mb 64mb 60
46
+ # client-output-buffer-limit pubsub 32mb 8mb 60
@@ -0,0 +1,46 @@
1
+ daemonize yes
2
+ pidfile ./tmp/pids/redis.pid
3
+ port 6379
4
+ timeout 0
5
+ loglevel verbose
6
+ logfile stdout
7
+ databases 16
8
+
9
+ save 900 1
10
+ save 300 10
11
+ save 60 10000
12
+
13
+ # stop-writes-on-bgsave-error yes
14
+ rdbcompression yes
15
+ # rdbchecksum yes
16
+ dbfilename tmp/dump.rdb
17
+ dir ./
18
+
19
+ slave-serve-stale-data yes
20
+ # slave-read-only yes
21
+ # slave-priority 100
22
+
23
+ appendonly no
24
+ appendfsync everysec
25
+ no-appendfsync-on-rewrite no
26
+ # auto-aof-rewrite-percentage 100
27
+ # auto-aof-rewrite-min-size 64mb
28
+
29
+ # lua-time-limit 5000
30
+
31
+ # slowlog-log-slower-than 10000
32
+ # slowlog-max-len 128
33
+
34
+ # hash-max-ziplist-entries 512
35
+ # hash-max-ziplist-value 64
36
+ list-max-ziplist-entries 512
37
+ list-max-ziplist-value 64
38
+ set-max-intset-entries 512
39
+ # zset-max-ziplist-entries 128
40
+ # zset-max-ziplist-value 64
41
+
42
+ activerehashing yes
43
+
44
+ # client-output-buffer-limit normal 0 0 0
45
+ # client-output-buffer-limit slave 256mb 64mb 60
46
+ # client-output-buffer-limit pubsub 32mb 8mb 60
@@ -0,0 +1,53 @@
1
+ require 'test_helper'
2
+
3
+ describe "Redis::DistributedStore" do
4
+ def setup
5
+ @dmr = Redis::DistributedStore.new [
6
+ {:host => "localhost", :port => "6380", :db => 0},
7
+ {:host => "localhost", :port => "6381", :db => 0}
8
+ ]
9
+ @rabbit = OpenStruct.new :name => "bunny"
10
+ @white_rabbit = OpenStruct.new :color => "white"
11
+ @dmr.set "rabbit", @rabbit
12
+ end
13
+
14
+ def teardown
15
+ @dmr.ring.nodes.each { |server| server.flushdb }
16
+ end
17
+
18
+ it "accepts connection params" do
19
+ dmr = Redis::DistributedStore.new [ :host => "localhost", :port => "6380", :db => "1" ]
20
+ dmr.ring.nodes.size == 1
21
+ mr = dmr.ring.nodes.first
22
+ mr.to_s.must_equal("Redis Client connected to localhost:6380 against DB 1")
23
+ end
24
+
25
+ it "forces reconnection" do
26
+ @dmr.nodes.each do |node|
27
+ node.expects(:reconnect)
28
+ end
29
+
30
+ @dmr.reconnect
31
+ end
32
+
33
+ it "sets an object" do
34
+ @dmr.set "rabbit", @white_rabbit
35
+ @dmr.get("rabbit").must_equal(@white_rabbit)
36
+ end
37
+
38
+ it "gets an object" do
39
+ @dmr.get("rabbit").must_equal(@rabbit)
40
+ end
41
+
42
+ describe "namespace" do
43
+ it "uses namespaced key" do
44
+ @dmr = Redis::DistributedStore.new [
45
+ {:host => "localhost", :port => "6380", :db => 0},
46
+ {:host => "localhost", :port => "6381", :db => 0}
47
+ ], :namespace => "theplaylist"
48
+
49
+ @dmr.expects(:node_for).with("theplaylist:rabbit").returns(@dmr.nodes.first)
50
+ @dmr.get "rabbit"
51
+ end
52
+ end
53
+ end