redis_util 0.5.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.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +17 -0
- data/.travis.yml +8 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +53 -0
- data/Rakefile +18 -0
- data/lib/redis_util.rb +3 -0
- data/lib/redis_util/factory.rb +144 -0
- data/lib/redis_util/test_helper.rb +37 -0
- data/lib/redis_util/version.rb +3 -0
- data/redis_util.gemspec +31 -0
- data/test/test_helper.rb +81 -0
- data/test/unit/redis_util/factory_test.rb +137 -0
- metadata +187 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c0982a8f3706eaf058b21298a4a852948b03b0c4
|
4
|
+
data.tar.gz: 79f9c6340a25b9fa608d615e7b7f0495207b4a83
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: afdf9c67bc79d11578bae562a4a2a6053857834b8bd11dd01e561360049a7f778abf640e5f1e39882031998025a6fd378f4435ed418cc2537c4ca0928a570c63
|
7
|
+
data.tar.gz: 0dded02a0fb006b26564331c37f73d92408bd913e3d69fcabdc7c6dd962e173cc0a163495856944a644bf5ea7eeea0e307be482681447467b11585e0069565c6
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Matt Conway
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# RedisUtil
|
2
|
+
|
3
|
+
An aggregation of redis utility code, including:
|
4
|
+
|
5
|
+
* A factory which allows you to define redis connections in a config file, and keeps track of them for reconnecting in forks
|
6
|
+
* Test helpers
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'redis_util'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install redis_util
|
21
|
+
|
22
|
+
Then setup a config file in config/redis.yml that could look like:
|
23
|
+
|
24
|
+
common: &common
|
25
|
+
host: localhost
|
26
|
+
port: 6379
|
27
|
+
thread_safe: true
|
28
|
+
|
29
|
+
development:
|
30
|
+
resque:
|
31
|
+
<<: *common
|
32
|
+
db: 0
|
33
|
+
redis_objects:
|
34
|
+
<<: *common
|
35
|
+
db: 1
|
36
|
+
|
37
|
+
test:
|
38
|
+
resque:
|
39
|
+
<<: *common
|
40
|
+
db: 10
|
41
|
+
redis_objects:
|
42
|
+
<<: *common
|
43
|
+
db: 11
|
44
|
+
|
45
|
+
If not running in rails, an additional step is needed to set the config_file and env:
|
46
|
+
|
47
|
+
RedisUtil::Factory.config_file = "#{root}/config/redis.yml"
|
48
|
+
RedisUtil::Factory.env = "development"
|
49
|
+
|
50
|
+
## Usage
|
51
|
+
|
52
|
+
redis = RedisUtil::Factory.connect(:foo)
|
53
|
+
redis.keys('*')
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/testtask'
|
4
|
+
|
5
|
+
Rake::TestTask.new do |t|
|
6
|
+
t.pattern = 'test/**/*_test.rb'
|
7
|
+
t.libs.push 'test'
|
8
|
+
end
|
9
|
+
|
10
|
+
task :default => :test
|
11
|
+
|
12
|
+
task :console do
|
13
|
+
Bundler.require
|
14
|
+
require "redis_util"
|
15
|
+
ARGV.clear
|
16
|
+
require "irb"
|
17
|
+
IRB.start
|
18
|
+
end
|
data/lib/redis_util.rb
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
require 'redis'
|
2
|
+
require 'redis-namespace'
|
3
|
+
|
4
|
+
module RedisUtil
|
5
|
+
|
6
|
+
# A factory class for creating redis connections, useful for
|
7
|
+
# reconnecting them after a fork
|
8
|
+
#
|
9
|
+
class Factory
|
10
|
+
include GemLogger::LoggerSupport
|
11
|
+
extend MonitorMixin
|
12
|
+
|
13
|
+
class << self
|
14
|
+
|
15
|
+
# Set the path to the yml config file which defines all the redis connections.
|
16
|
+
# If running in rails, it will default to "#{Rails.root}/config/redis.yml"
|
17
|
+
attr_accessor :config_file
|
18
|
+
|
19
|
+
# Set the environment we are running in (development/test/etc).
|
20
|
+
# If running in rails, it will default to Rails.env
|
21
|
+
attr_accessor :env
|
22
|
+
|
23
|
+
attr_accessor :clients, :configuration
|
24
|
+
|
25
|
+
# Creates/retrieves a single redis client for the given named configuration
|
26
|
+
#
|
27
|
+
# @param [Symbol] name The name of the redis configuration (config/redis.yml) to use
|
28
|
+
# @return [Redis] A redis client object
|
29
|
+
def connect(name)
|
30
|
+
conf = lookup_config(name)
|
31
|
+
synchronize do
|
32
|
+
clients[name] ||= []
|
33
|
+
if clients[name].first.nil?
|
34
|
+
clients[name] << new_redis_client(conf)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
clients[name].first
|
38
|
+
end
|
39
|
+
|
40
|
+
# Always create and return a new redis client for the given named configuration
|
41
|
+
#
|
42
|
+
# @param [Symbol] name The name of the redis configuration (config/redis.yml) to use
|
43
|
+
# @return [Redis] A redis client object
|
44
|
+
def create(name)
|
45
|
+
conf = lookup_config(name)
|
46
|
+
synchronize do
|
47
|
+
clients[name] ||= []
|
48
|
+
clients[name] << new_redis_client(conf)
|
49
|
+
end
|
50
|
+
clients[name].last
|
51
|
+
end
|
52
|
+
|
53
|
+
# Disconnect all known redis clients
|
54
|
+
#
|
55
|
+
# @param [Symbol] key (optional, defaults to all) The name of the redis configuration (config/redis.yml) to disconnect
|
56
|
+
def disconnect(key=nil)
|
57
|
+
logger.debug "RedisUtil::Factory.disconnect start"
|
58
|
+
synchronize do
|
59
|
+
clients.clone.each do |name, client|
|
60
|
+
next if key && name != key
|
61
|
+
|
62
|
+
connections = clients.delete(name) || []
|
63
|
+
connections.each do |connection|
|
64
|
+
begin
|
65
|
+
logger.debug "Disconnecting Redis client: #{connection}"
|
66
|
+
connection.quit
|
67
|
+
rescue => e
|
68
|
+
logger.warn("Exception while disconnecting: #{e}")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
logger.debug "RedisUtil::Factory.disconnect complete"
|
74
|
+
nil
|
75
|
+
end
|
76
|
+
|
77
|
+
# Reconnect all known redis clients
|
78
|
+
#
|
79
|
+
# @param [Symbol] key (optional, defaults to all) The name of the redis configuration (config/redis.yml) to reconnect
|
80
|
+
def reconnect(key=nil)
|
81
|
+
logger.debug "RedisUtil::Factory.reconnect start"
|
82
|
+
synchronize do
|
83
|
+
clients.each do |name, connections|
|
84
|
+
next if key && name != key
|
85
|
+
|
86
|
+
connections.each do |connection|
|
87
|
+
logger.debug "Reconnecting Redis client: #{connection}"
|
88
|
+
connection.client.reconnect
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
logger.debug "RedisUtil::Factory.reconnect complete"
|
93
|
+
end
|
94
|
+
|
95
|
+
def configuration
|
96
|
+
synchronize do
|
97
|
+
@configuration ||= begin
|
98
|
+
|
99
|
+
if config_file.nil? || env.nil?
|
100
|
+
if defined?(Rails)
|
101
|
+
self.config_file ||= "#{Rails.root}/config/redis.yml"
|
102
|
+
self.env ||= Rails.env.to_s
|
103
|
+
else
|
104
|
+
raise "You need to initialize with an env and config file"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
self.clients = {}
|
109
|
+
require 'erb'
|
110
|
+
config = YAML::load(ERB.new(IO.read(config_file)).result)
|
111
|
+
symbolize(config[env])
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
private
|
117
|
+
|
118
|
+
def lookup_config(name)
|
119
|
+
conf = configuration[name]
|
120
|
+
raise "No redis configuration for #{env} environment in redis.yml for #{name}" unless conf
|
121
|
+
conf
|
122
|
+
end
|
123
|
+
|
124
|
+
def new_redis_client(conf)
|
125
|
+
redis = ::Redis.new(conf)
|
126
|
+
if conf[:namespace]
|
127
|
+
redis = Redis::Namespace.new(conf[:namespace].to_sym, :redis => redis)
|
128
|
+
end
|
129
|
+
redis
|
130
|
+
end
|
131
|
+
|
132
|
+
def symbolize(hash)
|
133
|
+
hash.inject({}) do |options, (key, value)|
|
134
|
+
value = symbolize(value) if value.kind_of?(Hash)
|
135
|
+
options[key.to_sym || key] = value
|
136
|
+
options
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module RedisUtil
|
2
|
+
|
3
|
+
# Test helpers for working with redis in tests
|
4
|
+
module TestHelper
|
5
|
+
|
6
|
+
# flushes all redis connections that are configured for
|
7
|
+
# this environment in redis.yml
|
8
|
+
def redis_util_truncate_redis
|
9
|
+
RedisUtil::Factory.configuration.keys.each do |k|
|
10
|
+
RedisUtil::Factory.connect(k).flushdb()
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def redis_util_dump_redis
|
15
|
+
result = {}
|
16
|
+
RedisUtil::Factory.configuration.keys.each do |k|
|
17
|
+
redis = RedisUtil::Factory.connect(k)
|
18
|
+
result[k] = {}
|
19
|
+
redis.keys("*").each do |key|
|
20
|
+
type = redis.type(key)
|
21
|
+
result[k]["#{key} (#{type})"] = case type
|
22
|
+
when 'string' then redis.get(key)
|
23
|
+
when 'list' then redis.lrange(key, 0, -1)
|
24
|
+
when 'zset' then redis.zrange(key, 0, -1, :with_scores => true)
|
25
|
+
when 'set' then redis.smembers(key)
|
26
|
+
when 'hash' then redis.hgetall(key)
|
27
|
+
else type
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
return result
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
data/redis_util.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'redis_util/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "redis_util"
|
8
|
+
spec.version = RedisUtil::VERSION
|
9
|
+
spec.authors = ["Matt Conway"]
|
10
|
+
spec.email = ["matt@conwaysplace.com"]
|
11
|
+
spec.description = %q{An aggregation of redis utility code, including a factory for tracking connections}
|
12
|
+
spec.summary = %q{Redis utilities}
|
13
|
+
spec.homepage = "http://github.com/wr0ngway/redis_util"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "minitest"
|
24
|
+
spec.add_development_dependency "minitest_should"
|
25
|
+
spec.add_development_dependency "minitest-reporters"
|
26
|
+
spec.add_development_dependency "mocha"
|
27
|
+
|
28
|
+
spec.add_dependency "gem_logger"
|
29
|
+
spec.add_dependency "redis"
|
30
|
+
spec.add_dependency "redis-namespace"
|
31
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
if ENV['CI']
|
4
|
+
require 'coveralls'
|
5
|
+
Coveralls.wear!
|
6
|
+
end
|
7
|
+
|
8
|
+
require 'bundler'
|
9
|
+
begin
|
10
|
+
Bundler.setup(:default, :development)
|
11
|
+
rescue Bundler::BundlerError => e
|
12
|
+
$stderr.puts e.message
|
13
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
14
|
+
exit e.status_code
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'minitest/autorun'
|
18
|
+
require 'minitest/should'
|
19
|
+
require "minitest/reporters"
|
20
|
+
require 'mocha/setup'
|
21
|
+
|
22
|
+
reporter = ENV['REPORTER']
|
23
|
+
reporter = case reporter
|
24
|
+
when 'none' then nil
|
25
|
+
when 'spec' then MiniTest::Reporters::SpecReporter.new
|
26
|
+
when 'progress' then MiniTest::Reporters::ProgressReporter.new
|
27
|
+
else MiniTest::Reporters::DefaultReporter.new
|
28
|
+
end
|
29
|
+
MiniTest::Reporters.use!(reporter) if reporter
|
30
|
+
|
31
|
+
require 'redis_util'
|
32
|
+
GemLogger.default_logger = Logger.new("/dev/null")
|
33
|
+
|
34
|
+
class MiniTest::Should::TestCase
|
35
|
+
|
36
|
+
require 'redis_util/test_helper'
|
37
|
+
include RedisUtil::TestHelper
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
# Allow triggering single tests when running from rubymine
|
42
|
+
# reopen the installed runner so we don't step on runner customizations
|
43
|
+
class << MiniTest::Unit.runner
|
44
|
+
# Rubymine sends --name=/\Atest\: <context> should <should>\./
|
45
|
+
# Minitest runs each context as a suite
|
46
|
+
# Minitest filters methods by matching against: <suite>#test_0001_<should>
|
47
|
+
# Nested contexts are separted by spaces in rubymine, but ::s in minitest
|
48
|
+
|
49
|
+
def _run_suites(suites, type)
|
50
|
+
if options[:filter]
|
51
|
+
if options[:filter] =~ /\/\\Atest\\: (.*) should (.*)\\\.\//
|
52
|
+
context_filter = $1
|
53
|
+
should_filter = $2
|
54
|
+
should_filter.strip!
|
55
|
+
should_filter.gsub!(" ", "_")
|
56
|
+
should_filter.gsub!(/\W/, "")
|
57
|
+
context_filter = context_filter.gsub(" ", "((::)| )")
|
58
|
+
options[:filter] = "/\\A#{context_filter}(Test)?#test(_\\d+)?_should_#{should_filter}\\Z/"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
super
|
63
|
+
end
|
64
|
+
|
65
|
+
# Prevent "Empty test suite" verbosity when running in rubymine
|
66
|
+
def _run_suite(suite, type)
|
67
|
+
|
68
|
+
filter = options[:filter] || '/./'
|
69
|
+
filter = Regexp.new $1 if filter =~ /\/(.*)\//
|
70
|
+
all_test_methods = suite.send "#{type}_methods"
|
71
|
+
filtered_test_methods = all_test_methods.find_all { |m|
|
72
|
+
filter === m || filter === "#{suite}##{m}"
|
73
|
+
}
|
74
|
+
|
75
|
+
if filtered_test_methods.size > 0
|
76
|
+
super
|
77
|
+
else
|
78
|
+
[0, 0]
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
require_relative '../../test_helper.rb'
|
2
|
+
|
3
|
+
module RedisUtil
|
4
|
+
class FactoryTest < MiniTest::Should::TestCase
|
5
|
+
|
6
|
+
setup do
|
7
|
+
@config = "config/redis.yml"
|
8
|
+
RedisUtil::Factory.config_file = @config
|
9
|
+
RedisUtil::Factory.env = "test"
|
10
|
+
RedisUtil::Factory.clients = nil
|
11
|
+
RedisUtil::Factory.configuration = nil
|
12
|
+
@config_file_data = <<-EOF
|
13
|
+
test:
|
14
|
+
resque:
|
15
|
+
db: 1
|
16
|
+
host: localhost
|
17
|
+
port: 6379
|
18
|
+
thread_safe: true
|
19
|
+
cache:
|
20
|
+
db: 2
|
21
|
+
host: localhost
|
22
|
+
port: 6379
|
23
|
+
thread_safe: true
|
24
|
+
namespaced:
|
25
|
+
db: 3
|
26
|
+
host: localhost
|
27
|
+
port: 6379
|
28
|
+
thread_safe: true
|
29
|
+
namespace: foobar
|
30
|
+
development:
|
31
|
+
resque:
|
32
|
+
host: bar
|
33
|
+
EOF
|
34
|
+
IO.stubs(:read).with(@config).returns(@config_file_data)
|
35
|
+
end
|
36
|
+
|
37
|
+
context "#configuration" do
|
38
|
+
|
39
|
+
should "read in redis yml" do
|
40
|
+
config = RedisUtil::Factory.configuration
|
41
|
+
assert_equal [:resque, :cache, :namespaced], config.keys
|
42
|
+
assert_equal({:db=>1, :host=>"localhost", :port=>6379, :thread_safe=>true}, config[:resque])
|
43
|
+
end
|
44
|
+
|
45
|
+
should "read in redis yml for different env" do
|
46
|
+
RedisUtil::Factory.env = "development"
|
47
|
+
assert_equal({:resque => {:host=>"bar"}}, RedisUtil::Factory.configuration)
|
48
|
+
end
|
49
|
+
|
50
|
+
should "use defaults with Rails" do
|
51
|
+
begin
|
52
|
+
RedisUtil::Factory.config_file = nil
|
53
|
+
RedisUtil::Factory.env = nil
|
54
|
+
Object.const_set(:Rails, Class.new)
|
55
|
+
::Rails.stubs(:env).returns "development"
|
56
|
+
::Rails.stubs(:root).returns "/root"
|
57
|
+
IO.stubs(:read).with("/root/config/redis.yml").returns(@config_file_data)
|
58
|
+
RedisUtil::Factory.configuration
|
59
|
+
assert_equal "development", RedisUtil::Factory.env
|
60
|
+
assert_equal "/root/config/redis.yml", RedisUtil::Factory.config_file
|
61
|
+
ensure
|
62
|
+
Object.send(:remove_const, "Rails")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
context "#connect" do
|
69
|
+
|
70
|
+
should "return client for symbol" do
|
71
|
+
assert_equal 1, RedisUtil::Factory.connect(:resque).client.db
|
72
|
+
assert_equal 2, RedisUtil::Factory.connect(:cache).client.db
|
73
|
+
end
|
74
|
+
|
75
|
+
should "reuse client for same symbol" do
|
76
|
+
assert_equal RedisUtil::Factory.connect(:resque).object_id, RedisUtil::Factory.connect(:resque).object_id
|
77
|
+
end
|
78
|
+
|
79
|
+
should "return a standard client if namespace is not present" do
|
80
|
+
client = RedisUtil::Factory.connect(:cache)
|
81
|
+
assert client.instance_of?(Redis)
|
82
|
+
end
|
83
|
+
|
84
|
+
should "return a namespaced client if namespace is present" do
|
85
|
+
client = RedisUtil::Factory.connect(:namespaced)
|
86
|
+
assert client.instance_of?(Redis::Namespace)
|
87
|
+
assert_equal client.namespace, :foobar
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
context "#disconnect" do
|
93
|
+
|
94
|
+
should "disconnect specific client" do
|
95
|
+
resque_client = RedisUtil::Factory.connect(:resque)
|
96
|
+
cache_client = RedisUtil::Factory.connect(:cache)
|
97
|
+
|
98
|
+
resque_client.expects(:quit)
|
99
|
+
cache_client.expects(:quit).never
|
100
|
+
RedisUtil::Factory.disconnect(:resque)
|
101
|
+
end
|
102
|
+
|
103
|
+
should "disconnect all clients" do
|
104
|
+
resque_client = RedisUtil::Factory.connect(:resque)
|
105
|
+
cache_client = RedisUtil::Factory.connect(:cache)
|
106
|
+
|
107
|
+
resque_client.expects(:quit)
|
108
|
+
cache_client.expects(:quit)
|
109
|
+
RedisUtil::Factory.disconnect
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
context "#reconnect" do
|
115
|
+
|
116
|
+
should "reconnect specific client" do
|
117
|
+
resque_client = RedisUtil::Factory.connect(:resque)
|
118
|
+
cache_client = RedisUtil::Factory.connect(:cache)
|
119
|
+
|
120
|
+
resque_client.expects(:client).returns(mock('redis', :reconnect => nil))
|
121
|
+
cache_client.expects(:client).never
|
122
|
+
RedisUtil::Factory.reconnect(:resque)
|
123
|
+
end
|
124
|
+
|
125
|
+
should "reconnect all clients" do
|
126
|
+
resque_client = RedisUtil::Factory.connect(:resque)
|
127
|
+
cache_client = RedisUtil::Factory.connect(:cache)
|
128
|
+
|
129
|
+
resque_client.expects(:client).returns(mock('redis', :reconnect => nil))
|
130
|
+
cache_client.expects(:client).returns(mock('redis', :reconnect => nil))
|
131
|
+
RedisUtil::Factory.reconnect
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
end
|
metadata
ADDED
@@ -0,0 +1,187 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: redis_util
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matt Conway
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest_should
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest-reporters
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: mocha
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: gem_logger
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: redis
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: redis-namespace
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description: An aggregation of redis utility code, including a factory for tracking
|
140
|
+
connections
|
141
|
+
email:
|
142
|
+
- matt@conwaysplace.com
|
143
|
+
executables: []
|
144
|
+
extensions: []
|
145
|
+
extra_rdoc_files: []
|
146
|
+
files:
|
147
|
+
- .coveralls.yml
|
148
|
+
- .gitignore
|
149
|
+
- .travis.yml
|
150
|
+
- Gemfile
|
151
|
+
- LICENSE.txt
|
152
|
+
- README.md
|
153
|
+
- Rakefile
|
154
|
+
- lib/redis_util.rb
|
155
|
+
- lib/redis_util/factory.rb
|
156
|
+
- lib/redis_util/test_helper.rb
|
157
|
+
- lib/redis_util/version.rb
|
158
|
+
- redis_util.gemspec
|
159
|
+
- test/test_helper.rb
|
160
|
+
- test/unit/redis_util/factory_test.rb
|
161
|
+
homepage: http://github.com/wr0ngway/redis_util
|
162
|
+
licenses:
|
163
|
+
- MIT
|
164
|
+
metadata: {}
|
165
|
+
post_install_message:
|
166
|
+
rdoc_options: []
|
167
|
+
require_paths:
|
168
|
+
- lib
|
169
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
175
|
+
requirements:
|
176
|
+
- - '>='
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
version: '0'
|
179
|
+
requirements: []
|
180
|
+
rubyforge_project:
|
181
|
+
rubygems_version: 2.0.6
|
182
|
+
signing_key:
|
183
|
+
specification_version: 4
|
184
|
+
summary: Redis utilities
|
185
|
+
test_files:
|
186
|
+
- test/test_helper.rb
|
187
|
+
- test/unit/redis_util/factory_test.rb
|