redis-classy 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +30 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +75 -0
- data/Rakefile +45 -0
- data/VERSION +1 -0
- data/lib/redis/classy.rb +27 -0
- data/lib/redis-classy.rb +1 -0
- data/redis-classy.gemspec +65 -0
- data/spec/redis-classy_spec.rb +7 -0
- data/spec/spec_helper.rb +12 -0
- metadata +116 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.2)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.5.2)
|
7
|
+
bundler (~> 1.0.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rake
|
10
|
+
rake (0.8.7)
|
11
|
+
redis (2.1.1)
|
12
|
+
redis-namespace (0.10.0)
|
13
|
+
redis (< 3.0.0)
|
14
|
+
rspec (2.5.0)
|
15
|
+
rspec-core (~> 2.5.0)
|
16
|
+
rspec-expectations (~> 2.5.0)
|
17
|
+
rspec-mocks (~> 2.5.0)
|
18
|
+
rspec-core (2.5.1)
|
19
|
+
rspec-expectations (2.5.0)
|
20
|
+
diff-lcs (~> 1.1.2)
|
21
|
+
rspec-mocks (2.5.0)
|
22
|
+
|
23
|
+
PLATFORMS
|
24
|
+
ruby
|
25
|
+
|
26
|
+
DEPENDENCIES
|
27
|
+
bundler (~> 1.0.0)
|
28
|
+
jeweler (~> 1.5.2)
|
29
|
+
redis-namespace (~> 0.10.0)
|
30
|
+
rspec (~> 2.5.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Kenn Ejima
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
= Redis Classy
|
2
|
+
|
3
|
+
Model-friendly base class for Redis.
|
4
|
+
|
5
|
+
With this library, the class name of your model becomes the prefix part of the Redis keys.
|
6
|
+
|
7
|
+
This library contains only 27 lines of code, yet powerful when you need more abstraction on Redis objects rather than dealing with complicated keys in all strings.
|
8
|
+
|
9
|
+
Requies the redis-namespace gem.
|
10
|
+
|
11
|
+
== Install
|
12
|
+
|
13
|
+
gem install redis-classy
|
14
|
+
|
15
|
+
== Usage
|
16
|
+
|
17
|
+
In Gemfile:
|
18
|
+
|
19
|
+
gem "redis-classy"
|
20
|
+
|
21
|
+
In your initializer:
|
22
|
+
|
23
|
+
Redis::Classy.db = Redis.new
|
24
|
+
|
25
|
+
Now you can write models that inherit the Redis::Classy class, automatically prefixing keys with its class name.
|
26
|
+
|
27
|
+
class UniqueUser < Redis::Classy
|
28
|
+
def self.nuke
|
29
|
+
self.keys.each{|key| self.del(key) }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
UniqueUser.sadd "2011-02-28", @user_a.id
|
34
|
+
UniqueUser.sadd "2011-02-28", @user_b.id
|
35
|
+
UniqueUser.sadd "2011-03-01", @user_c.id
|
36
|
+
|
37
|
+
UniqueUser.smembers "2011-02-28"
|
38
|
+
=> ["123", "456"]
|
39
|
+
|
40
|
+
UniqueUser.nuke
|
41
|
+
=> ["2011-02-28", "2011-03-01"]
|
42
|
+
|
43
|
+
UniqueUser.keys
|
44
|
+
=> []
|
45
|
+
|
46
|
+
In most cases you may be just fine with class methods, but by creating an instance with a key, even further binding is possible.
|
47
|
+
|
48
|
+
class Counter < Redis::Classy
|
49
|
+
def initialize(object)
|
50
|
+
super("#{object.class.name}:#{object.id}")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
counter = Counter.new(@room)
|
55
|
+
counter.incr
|
56
|
+
counter.incr
|
57
|
+
counter.get
|
58
|
+
=> "2"
|
59
|
+
|
60
|
+
counter.key
|
61
|
+
=> "Room:123"
|
62
|
+
|
63
|
+
You also have access to the non-namespaced, raw Redis instance via Redis::Classy.db
|
64
|
+
|
65
|
+
Redis::Classy.db.keys "UniqueUser:*"
|
66
|
+
=> ["UniqueUser:2011-02-28", "UniqueUser:2011-03-01"]
|
67
|
+
|
68
|
+
Redis::Classy.db.multi do
|
69
|
+
UniqueUser.sadd "2011-02-28", @user_a.id
|
70
|
+
UniqueUser.sadd "2011-02-28", @user_b.id
|
71
|
+
end
|
72
|
+
|
73
|
+
Since the "db" attribute is a class instance variable, you can dynamically assign different databases for each class.
|
74
|
+
|
75
|
+
UniqueUser.db = Redis::Namespace.new("UniqueUser", :redis => Redis.new(:host => "another.host"))
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
gem.name = "redis-classy"
|
15
|
+
gem.homepage = "http://github.com/kenn/redis-classy"
|
16
|
+
gem.license = "MIT"
|
17
|
+
gem.summary = "Model-friendly base class for Redis"
|
18
|
+
gem.description = "Make the prefix part of the Redis keys a class name for your model."
|
19
|
+
gem.email = "kenn.ejima@gmail.com"
|
20
|
+
gem.authors = ["Kenn Ejima"]
|
21
|
+
end
|
22
|
+
Jeweler::RubygemsDotOrgTasks.new
|
23
|
+
|
24
|
+
require 'rspec/core'
|
25
|
+
require 'rspec/core/rake_task'
|
26
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
27
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
28
|
+
end
|
29
|
+
|
30
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
31
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
32
|
+
spec.rcov = true
|
33
|
+
end
|
34
|
+
|
35
|
+
task :default => :spec
|
36
|
+
|
37
|
+
require 'rake/rdoctask'
|
38
|
+
Rake::RDocTask.new do |rdoc|
|
39
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
40
|
+
|
41
|
+
rdoc.rdoc_dir = 'rdoc'
|
42
|
+
rdoc.title = "redis-classy #{version}"
|
43
|
+
rdoc.rdoc_files.include('README*')
|
44
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
45
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.9.0
|
data/lib/redis/classy.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'redis-namespace'
|
2
|
+
|
3
|
+
class Redis
|
4
|
+
class Classy
|
5
|
+
class << self
|
6
|
+
attr_accessor :db
|
7
|
+
|
8
|
+
def inherited(subclass)
|
9
|
+
subclass.db = Redis::Namespace.new(subclass.name, :redis => self.db)
|
10
|
+
end
|
11
|
+
|
12
|
+
def method_missing(method_name, *args)
|
13
|
+
self.db.send(method_name, *args)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
attr_accessor :key
|
18
|
+
|
19
|
+
def initialize(key)
|
20
|
+
self.key = key
|
21
|
+
end
|
22
|
+
|
23
|
+
def method_missing(method_name, *args)
|
24
|
+
self.class.send(method_name, self.key, *args)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/redis-classy.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/redis/classy'
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{redis-classy}
|
8
|
+
s.version = "0.9.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Kenn Ejima"]
|
12
|
+
s.date = %q{2011-02-28}
|
13
|
+
s.description = %q{Make the prefix part of the Redis keys a class name for your model.}
|
14
|
+
s.email = %q{kenn.ejima@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"lib/redis-classy.rb",
|
29
|
+
"lib/redis/classy.rb",
|
30
|
+
"redis-classy.gemspec",
|
31
|
+
"spec/redis-classy_spec.rb",
|
32
|
+
"spec/spec_helper.rb"
|
33
|
+
]
|
34
|
+
s.homepage = %q{http://github.com/kenn/redis-classy}
|
35
|
+
s.licenses = ["MIT"]
|
36
|
+
s.require_paths = ["lib"]
|
37
|
+
s.rubygems_version = %q{1.5.3}
|
38
|
+
s.summary = %q{Model-friendly base class for Redis}
|
39
|
+
s.test_files = [
|
40
|
+
"spec/redis-classy_spec.rb",
|
41
|
+
"spec/spec_helper.rb"
|
42
|
+
]
|
43
|
+
|
44
|
+
if s.respond_to? :specification_version then
|
45
|
+
s.specification_version = 3
|
46
|
+
|
47
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
48
|
+
s.add_runtime_dependency(%q<redis-namespace>, ["~> 0.10.0"])
|
49
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.5.0"])
|
50
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
51
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<redis-namespace>, ["~> 0.10.0"])
|
54
|
+
s.add_dependency(%q<rspec>, ["~> 2.5.0"])
|
55
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
56
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
57
|
+
end
|
58
|
+
else
|
59
|
+
s.add_dependency(%q<redis-namespace>, ["~> 0.10.0"])
|
60
|
+
s.add_dependency(%q<rspec>, ["~> 2.5.0"])
|
61
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
62
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'redis-classy'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: redis-classy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.9.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kenn Ejima
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-02-28 00:00:00 -08:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: redis-namespace
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.10.0
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 2.5.0
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: bundler
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.0.0
|
46
|
+
type: :development
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: jeweler
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ~>
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 1.5.2
|
57
|
+
type: :development
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: *id004
|
60
|
+
description: Make the prefix part of the Redis keys a class name for your model.
|
61
|
+
email: kenn.ejima@gmail.com
|
62
|
+
executables: []
|
63
|
+
|
64
|
+
extensions: []
|
65
|
+
|
66
|
+
extra_rdoc_files:
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.rdoc
|
69
|
+
files:
|
70
|
+
- .document
|
71
|
+
- .rspec
|
72
|
+
- Gemfile
|
73
|
+
- Gemfile.lock
|
74
|
+
- LICENSE.txt
|
75
|
+
- README.rdoc
|
76
|
+
- Rakefile
|
77
|
+
- VERSION
|
78
|
+
- lib/redis-classy.rb
|
79
|
+
- lib/redis/classy.rb
|
80
|
+
- redis-classy.gemspec
|
81
|
+
- spec/redis-classy_spec.rb
|
82
|
+
- spec/spec_helper.rb
|
83
|
+
has_rdoc: true
|
84
|
+
homepage: http://github.com/kenn/redis-classy
|
85
|
+
licenses:
|
86
|
+
- MIT
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
hash: 1153223303982788264
|
98
|
+
segments:
|
99
|
+
- 0
|
100
|
+
version: "0"
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: "0"
|
107
|
+
requirements: []
|
108
|
+
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 1.5.3
|
111
|
+
signing_key:
|
112
|
+
specification_version: 3
|
113
|
+
summary: Model-friendly base class for Redis
|
114
|
+
test_files:
|
115
|
+
- spec/redis-classy_spec.rb
|
116
|
+
- spec/spec_helper.rb
|