red-base 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,50 @@
1
+ Red-base
2
+ ========
3
+
4
+ A simple gem to manage instances of redis-rb. It applies the singleton
5
+ pattern scoped to the passed in config to eliminate instantiation overhead.
6
+
7
+ Usage
8
+ -----
9
+
10
+ @redis = Red.is
11
+ @redis = Red.is(:ns => 'namespace')
12
+ @redis = Red.is(:host => 'x.x.x.x', :db => 5)
13
+
14
+ Installation
15
+ ------------
16
+
17
+ $ gem install redbase
18
+
19
+ To-Do
20
+ -----
21
+
22
+ * Write better tests
23
+
24
+ Maintainer
25
+ ----------
26
+
27
+ * kris :: kris@octohq.com
28
+
29
+ License
30
+ -------
31
+ Copyright (c) 2010 Octohq
32
+
33
+ Permission is hereby granted, free of charge, to any person obtaining
34
+ a copy of this software and associated documentation files (the
35
+ "Software"), to deal in the Software without restriction, including
36
+ without limitation the rights to use, copy, modify, merge, publish,
37
+ distribute, sublicense, and/or sell copies of the Software, and to
38
+ permit persons to whom the Software is furnished to do so, subject to
39
+ the following conditions:
40
+
41
+ The above copyright notice and this permission notice shall be
42
+ included in all copies or substantial portions of the Software.
43
+
44
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
45
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
46
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
47
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
48
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
49
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
50
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,7 @@
1
+ task :default => :spec
2
+ task :test => :spec
3
+
4
+ desc "Run specs"
5
+ task :spec do
6
+ exec "spec spec/red_base_spec.rb"
7
+ end
@@ -0,0 +1,14 @@
1
+ require 'redis'
2
+ require 'redis/namespace'
3
+ require 'red/base'
4
+
5
+ module Red
6
+ # Store our singleton instances
7
+ @@instances = {}
8
+
9
+ # Obtain a singleton Redis::Namespace instance
10
+ def self.is(opts = {})
11
+ config = Red::Base.build_options(opts)
12
+ @@instances[config.to_s] ||= Redis::Namespace.new(config.delete(:ns), :redis => Redis.new(config))
13
+ end
14
+ end
@@ -0,0 +1,35 @@
1
+ module Red
2
+ class Base
3
+ class << self
4
+ @@options = {}
5
+
6
+ # Return a config hash of the default or overridden options
7
+ # merged with passed in hash
8
+ def build_options(opts = {})
9
+ config = @@options.empty? ? self.default_options : @@options
10
+ config.merge(opts)
11
+ end
12
+
13
+ # Assign a default set of options
14
+ #
15
+ # Red.default_options = { :host => ..., :port => ... }
16
+ def default_options=(vals)
17
+ raise ArgumentError, "#default_options= takes a hash argument" unless vals.is_a?(Hash)
18
+ @@options = self.default_options.merge(vals)
19
+ end
20
+
21
+ # Default set of options
22
+ #
23
+ # Everything here is passed to Redis except for :ns,
24
+ # which is the namespace to use for Redis::Namespace
25
+ def default_options
26
+ {
27
+ :host => '127.0.0.1',
28
+ :port => 6379,
29
+ :ns => 'rb',
30
+ :db => 0
31
+ }
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,18 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ require 'red'
3
+
4
+ describe "Red::Base" do
5
+ it "should return an instance of redis" do
6
+ Red.is.should be_an_instance_of(Redis::Namespace)
7
+ end
8
+
9
+ it "should return a cached instance of redis" do
10
+ @redis = Red.is
11
+ @redis.should eql(Red.is)
12
+ end
13
+
14
+ it "should return a namespaced redis" do
15
+ @redis = Red.is(:ns => 'test')
16
+ @redis.namespace.should eql('test')
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ $TESTING=true
3
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: red-base
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - kris
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-09-29 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: redis
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - <
28
+ - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 3
32
+ - 0
33
+ - 0
34
+ version: 3.0.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ description: A simple way to manage multiple instances of redis-rb
38
+ email: kris@octohq.com
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files: []
44
+
45
+ files:
46
+ - README.markdown
47
+ - Rakefile
48
+ - lib/red/base.rb
49
+ - lib/red.rb
50
+ - spec/red_base_spec.rb
51
+ - spec/spec_helper.rb
52
+ has_rdoc: true
53
+ homepage: http://github.com/octohq/red-base
54
+ licenses: []
55
+
56
+ post_install_message:
57
+ rdoc_options: []
58
+
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ hash: 3
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ requirements: []
80
+
81
+ rubyforge_project:
82
+ rubygems_version: 1.3.7
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Redis instance management.
86
+ test_files: []
87
+