redis-classy 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -8,6 +8,27 @@ This library contains only 27 lines of code, yet powerful when you need more abs
8
8
 
9
9
  Requies the redis-namespace gem.
10
10
 
11
+ == Synopsis
12
+
13
+ With the vanilla redis gem, you've been normally doing this:
14
+
15
+ redis = Redis.new
16
+ redis.set "foo", "bar"
17
+
18
+ With the redis-namespace gem, you could add a prefix in the following manner:
19
+
20
+ redis_ns = Redis::Namespace.new('ns', :redis => redis)
21
+ redis_ns['foo'] = 'bar' # equivalent of => redis.set "ns:foo", "bar"
22
+
23
+ Now, with the redis-classy gem, you could finally do:
24
+
25
+ class Prefix < Redis::Classy
26
+ end
27
+
28
+ Prefix.set "foo", "bar" # equivalent of => redis.set "Prefix:foo", "bar"
29
+ Prefix.get "foo"
30
+ => "bar"
31
+
11
32
  == Install
12
33
 
13
34
  gem install redis-classy
@@ -18,11 +39,12 @@ In Gemfile:
18
39
 
19
40
  gem "redis-classy"
20
41
 
21
- In your initializer:
42
+ In config/initializers/redis_classy.rb:
22
43
 
23
44
  Redis::Classy.db = Redis.new
24
45
 
25
46
  Now you can write models that inherit the Redis::Classy class, automatically prefixing keys with its class name.
47
+ You can use any Redis commands on the class, since they are simply passed to the Redis instance.
26
48
 
27
49
  class UniqueUser < Redis::Classy
28
50
  def self.nuke
@@ -60,12 +82,12 @@ In most cases you may be just fine with class methods, but by creating an instan
60
82
  counter.key
61
83
  => "Room:123"
62
84
 
63
- You also have access to the non-namespaced, raw Redis instance via Redis::Classy.db
85
+ You also have access to the non-namespaced, raw Redis instance via Redis::Classy
64
86
 
65
- Redis::Classy.db.keys "UniqueUser:*"
87
+ Redis::Classy.keys "UniqueUser:*"
66
88
  => ["UniqueUser:2011-02-28", "UniqueUser:2011-03-01"]
67
89
 
68
- Redis::Classy.db.multi do
90
+ Redis::Classy.multi do
69
91
  UniqueUser.sadd "2011-02-28", @user_a.id
70
92
  UniqueUser.sadd "2011-02-28", @user_b.id
71
93
  end
@@ -73,3 +95,12 @@ You also have access to the non-namespaced, raw Redis instance via Redis::Classy
73
95
  Since the "db" attribute is a class instance variable, you can dynamically assign different databases for each class.
74
96
 
75
97
  UniqueUser.db = Redis::Namespace.new("UniqueUser", :redis => Redis.new(:host => "another.host"))
98
+
99
+ == Reference
100
+
101
+ Dependency:
102
+ https://github.com/ezmobius/redis-rb
103
+ https://github.com/defunkt/redis-namespace
104
+
105
+ Use case:
106
+ https://github.com/kenn/redis-mutex
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.0
1
+ 0.9.1
data/lib/redis/classy.rb CHANGED
@@ -9,8 +9,8 @@ class Redis
9
9
  subclass.db = Redis::Namespace.new(subclass.name, :redis => self.db)
10
10
  end
11
11
 
12
- def method_missing(method_name, *args)
13
- self.db.send(method_name, *args)
12
+ def method_missing(method_name, *args, &block)
13
+ self.db.send(method_name, *args, &block)
14
14
  end
15
15
  end
16
16
 
@@ -20,8 +20,8 @@ class Redis
20
20
  self.key = key
21
21
  end
22
22
 
23
- def method_missing(method_name, *args)
24
- self.class.send(method_name, self.key, *args)
23
+ def method_missing(method_name, *args, &block)
24
+ self.class.send(method_name, self.key, *args, &block)
25
25
  end
26
26
  end
27
27
  end
data/redis-classy.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{redis-classy}
8
- s.version = "0.9.0"
8
+ s.version = "0.9.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kenn Ejima"]
12
- s.date = %q{2011-02-28}
12
+ s.date = %q{2011-03-16}
13
13
  s.description = %q{Make the prefix part of the Redis keys a class name for your model.}
14
14
  s.email = %q{kenn.ejima@gmail.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: redis-classy
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.9.0
5
+ version: 0.9.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Kenn Ejima
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-02-28 00:00:00 -08:00
13
+ date: 2011-03-16 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -94,7 +94,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
94
94
  requirements:
95
95
  - - ">="
96
96
  - !ruby/object:Gem::Version
97
- hash: 1153223303982788264
97
+ hash: -2882799030924789426
98
98
  segments:
99
99
  - 0
100
100
  version: "0"