xlymian-redis-store 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,35 @@
1
+ require File.join(File.dirname(__FILE__), "/../spec_helper")
2
+
3
+ describe "DistributedMarshaledRedis" do
4
+ before(:each) do
5
+ @dmr = DistributedMarshaledRedis.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
+ after(:all) do
15
+ @dmr.ring.nodes.each { |server| server.flush_db }
16
+ end
17
+
18
+ it "should accept connection params" do
19
+ dmr = DistributedMarshaledRedis.new [ :host => "localhost", :port => "6380", :db => "1" ]
20
+ dmr.ring.should have(1).node
21
+ mr = dmr.ring.nodes.first
22
+ mr.host.should == "localhost"
23
+ mr.port.should == 6380
24
+ mr.db.should == 1
25
+ end
26
+
27
+ it "should set an object" do
28
+ @dmr.set "rabbit", @white_rabbit
29
+ @dmr.get("rabbit").should == @white_rabbit
30
+ end
31
+
32
+ it "should get an object" do
33
+ @dmr.get("rabbit").should == @rabbit
34
+ end
35
+ end
@@ -0,0 +1,54 @@
1
+ require File.join(File.dirname(__FILE__), "/../spec_helper")
2
+
3
+ describe "MarshaledRedis" do
4
+ before(:each) do
5
+ @store = MarshaledRedis.new
6
+ @rabbit = OpenStruct.new :name => "bunny"
7
+ @white_rabbit = OpenStruct.new :color => "white"
8
+ @store.set "rabbit", @rabbit
9
+ @store.delete "rabbit2"
10
+ end
11
+
12
+ after :each do
13
+ @store.quit
14
+ end
15
+
16
+ it "should unmarshal an object on get" do
17
+ @store.get("rabbit").should === @rabbit
18
+ end
19
+
20
+ it "should marshal object on set" do
21
+ @store.set "rabbit", @white_rabbit
22
+ @store.get("rabbit").should === @white_rabbit
23
+ end
24
+
25
+ it "should not unmarshal object on get if raw option is true" do
26
+ @store.get("rabbit", :raw => true).should == "\004\bU:\017OpenStruct{\006:\tname\"\nbunny"
27
+ end
28
+
29
+ it "should not marshal object on set if raw option is true" do
30
+ @store.set "rabbit", @white_rabbit, :raw => true
31
+ @store.get("rabbit", :raw => true).should == %(#<OpenStruct color="white">)
32
+ end
33
+
34
+ it "should not unmarshal object if getting an empty string" do
35
+ @store.set "empty_string", ""
36
+ lambda { @store.get("empty_string").should == "" }.should_not raise_error
37
+ end
38
+
39
+ it "should not set an object if already exist" do
40
+ @store.set_unless_exists "rabbit", @white_rabbit
41
+ @store.get("rabbit").should === @rabbit
42
+ end
43
+
44
+ it "should marshal object on set_unless_exists" do
45
+ @store.set_unless_exists "rabbit2", @white_rabbit
46
+ @store.get("rabbit2").should === @white_rabbit
47
+ end
48
+
49
+ it "should not marshal object on set_unless_exists if raw option is true" do
50
+ @store.set_unless_exists "rabbit2", @white_rabbit, :raw => true
51
+ @store.get("rabbit2", :raw => true).should == %(#<OpenStruct color="white">)
52
+ end
53
+ end
54
+
@@ -0,0 +1,34 @@
1
+ require File.join(File.dirname(__FILE__), "/../spec_helper")
2
+
3
+ describe "RedisFactory" do
4
+ it "should instantiate a MarshaledRedis store" do
5
+ store = RedisFactory.create
6
+ store.should be_kind_of(MarshaledRedis)
7
+ store.host.should == "127.0.0.1"
8
+ store.port.should == 6379
9
+ store.db.should == 0
10
+ end
11
+
12
+ it "should allow to specify host" do
13
+ store = RedisFactory.create "localhost"
14
+ store.host.should == "localhost"
15
+ end
16
+
17
+ it "should allow to specify port" do
18
+ store = RedisFactory.create "localhost:6380"
19
+ store.host.should == "localhost"
20
+ store.port.should == 6380
21
+ end
22
+
23
+ it "should allow to specify db" do
24
+ store = RedisFactory.create "localhost:6380/13"
25
+ store.host.should == "localhost"
26
+ store.port.should == 6380
27
+ store.db.should == 13
28
+ end
29
+
30
+ it "should instantiate a DistributedMarshaledRedis store" do
31
+ store = RedisFactory.create "localhost:6379", "localhost:6380"
32
+ store.should be_kind_of(DistributedMarshaledRedis)
33
+ end
34
+ end
@@ -0,0 +1,16 @@
1
+ $: << File.join(File.dirname(__FILE__), "/../lib")
2
+ require "vendor/gems/environment"
3
+ require "ostruct"
4
+ require "spec"
5
+ require "redis"
6
+ require "merb"
7
+ require "rack/cache"
8
+ require "rack/cache/metastore"
9
+ require "rack/cache/entitystore"
10
+ require "redis-store"
11
+ require "active_support"
12
+ require "cache/rails/redis_store"
13
+ require "cache/sinatra/redis_store"
14
+
15
+ class Redis; attr_reader :host, :port, :db end
16
+ $DEBUG = ENV["DEBUG"] === "true"
@@ -0,0 +1,70 @@
1
+ # steal the cool tasks from redis-rb
2
+ begin
3
+ require 'rbconfig'
4
+ engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'
5
+ version = Config::CONFIG['ruby_version']
6
+ load File.expand_path("../../vendor/gems/#{engine}/#{version}/gems/redis-0.1.1/tasks/redis.tasks.rb", __FILE__)
7
+ rescue LoadError
8
+ end
9
+
10
+ class RedisRunner
11
+ def self.port
12
+ 6379
13
+ end
14
+
15
+ def self.stop
16
+ system %(echo "SHUTDOWN" | nc localhost #{port})
17
+ end
18
+ end
19
+
20
+ class SingleRedisRunner < RedisRunner
21
+ def self.redisconfdir
22
+ File.expand_path(File.dirname(__FILE__) + "/../spec/config/single.conf")
23
+ end
24
+ end
25
+
26
+ class MasterRedisRunner < RedisRunner
27
+ def self.redisconfdir
28
+ File.expand_path(File.dirname(__FILE__) + "/../spec/config/master.conf")
29
+ end
30
+
31
+ def self.dtach_socket
32
+ "/tmp/redis_master.dtach"
33
+ end
34
+
35
+ def self.port
36
+ 6380
37
+ end
38
+ end
39
+
40
+ class SlaveRedisRunner < RedisRunner
41
+ def self.redisconfdir
42
+ File.expand_path(File.dirname(__FILE__) + "/../spec/config/slave.conf")
43
+ end
44
+
45
+ def self.dtach_socket
46
+ "/tmp/redis_slave.dtach"
47
+ end
48
+
49
+ def self.port
50
+ 6381
51
+ end
52
+ end
53
+
54
+ class RedisClusterRunner
55
+ def self.runners
56
+ [ SingleRedisRunner, MasterRedisRunner, SlaveRedisRunner ]
57
+ end
58
+
59
+ def self.start_detached
60
+ runners.each do |runner|
61
+ runner.start_detached
62
+ end
63
+ end
64
+
65
+ def self.stop
66
+ runners.each do |runner|
67
+ runner.stop
68
+ end
69
+ end
70
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xlymian-redis-store
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 3
8
+ - 8
9
+ version: 0.3.8
10
+ platform: ruby
11
+ authors:
12
+ - Luca Guidi
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-22 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Rack::Session, Rack::Cache and cache Redis stores for Ruby web frameworks.
22
+ email: guidi.luca@gmail.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - README.md
29
+ files:
30
+ - .gitignore
31
+ - Gemfile
32
+ - MIT-LICENSE
33
+ - README.md
34
+ - Rakefile
35
+ - VERSION
36
+ - lib/cache/merb/redis_store.rb
37
+ - lib/cache/rails/redis_store.rb
38
+ - lib/cache/sinatra/redis_store.rb
39
+ - lib/rack/cache/redis_entitystore.rb
40
+ - lib/rack/cache/redis_metastore.rb
41
+ - lib/rack/session/merb.rb
42
+ - lib/rack/session/redis.rb
43
+ - lib/redis-store.rb
44
+ - lib/redis/distributed_marshaled_redis.rb
45
+ - lib/redis/marshaled_redis.rb
46
+ - lib/redis/redis_factory.rb
47
+ - redis-store.gemspec
48
+ - spec/cache/merb/redis_store_spec.rb
49
+ - spec/cache/rails/redis_store_spec.rb
50
+ - spec/cache/sinatra/redis_store_spec.rb
51
+ - spec/config/master.conf
52
+ - spec/config/single.conf
53
+ - spec/config/slave.conf
54
+ - spec/rack/cache/entitystore/pony.jpg
55
+ - spec/rack/cache/entitystore/redis_spec.rb
56
+ - spec/rack/cache/metastore/redis_spec.rb
57
+ - spec/rack/session/redis_spec.rb
58
+ - spec/redis/distributed_marshaled_redis_spec.rb
59
+ - spec/redis/marshaled_redis_spec.rb
60
+ - spec/redis/redis_factory_spec.rb
61
+ - spec/spec_helper.rb
62
+ - tasks/redis.tasks.rb
63
+ has_rdoc: true
64
+ homepage: http://github.com/xlymian/redis-store
65
+ licenses: []
66
+
67
+ post_install_message:
68
+ rdoc_options:
69
+ - --charset=UTF-8
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ requirements: []
87
+
88
+ rubyforge_project:
89
+ rubygems_version: 1.3.6
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: Rack::Session, Rack::Cache and cache Redis stores for Ruby web frameworks.
93
+ test_files:
94
+ - spec/cache/merb/redis_store_spec.rb
95
+ - spec/cache/rails/redis_store_spec.rb
96
+ - spec/cache/sinatra/redis_store_spec.rb
97
+ - spec/rack/cache/entitystore/redis_spec.rb
98
+ - spec/rack/cache/metastore/redis_spec.rb
99
+ - spec/rack/session/redis_spec.rb
100
+ - spec/redis/distributed_marshaled_redis_spec.rb
101
+ - spec/redis/marshaled_redis_spec.rb
102
+ - spec/redis/redis_factory_spec.rb
103
+ - spec/spec_helper.rb