godredis 0.0.1 → 0.0.2
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 +4 -4
- data/README.md +56 -46
- data/godredis.gemspec +3 -1
- data/lib/godredis.rb +8 -4
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b39e42f40ee4cbdef7f3a8c3521410c0adb8836
|
4
|
+
data.tar.gz: ed9788dd87ad5ca1a911fa1abe226c6bd5e80452
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d616cd1a688dbdf492b0cf8b2a6fa6fd13b232063fe5f6442f4b67504c0cb4bb4cf9efb8ecba08871bda247e2a3e98695f5790cedcd0a96174a5665ba135d03
|
7
|
+
data.tar.gz: 9079b30e860812f17c08caaae4237e1717d08c208e3a5bb3131f4b281f8929d21296b9a83c3b17b9e0286147dc4f34a3099ec67fa684d3312ca98facbe831f45
|
data/README.md
CHANGED
@@ -4,12 +4,14 @@ Godredis gem provides unified interface for mass managing [Redis](http://redis.i
|
|
4
4
|
|
5
5
|
It is useful when you need to close or reset connections on forking, for example, with [puma](http://github.com/puma/puma) server in the `on_restart` block:
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
````ruby
|
8
|
+
on_restart do
|
9
|
+
# Rails.cache.instance_variable_get('@data').quit
|
10
|
+
# Redis::Objects.redis.quit
|
11
|
+
# Sidekiq.redis(&:quit)
|
12
|
+
Godredis.quit_all! # instead of commented lines above
|
13
|
+
end
|
14
|
+
````
|
13
15
|
|
14
16
|
## Installation
|
15
17
|
|
@@ -29,60 +31,68 @@ Or install it yourself as:
|
|
29
31
|
|
30
32
|
There are several ways to call bulk commands with Godredis:
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
34
|
+
````ruby
|
35
|
+
# Godredis.command_all! -- will output command execution result
|
36
|
+
Godredis.reconnect_all! # => Redis [cache_store]: reconnect... [OK]
|
37
|
+
# => Redis [objects]: reconnect... [OK]
|
38
|
+
# => Redis [sidekiq]: reconnect... [OK]
|
39
|
+
|
40
|
+
# Godredis.command_all -- silent
|
41
|
+
Godredis.quit_all
|
42
|
+
|
43
|
+
# Just different syntax
|
44
|
+
Godredis.redises(&:quit)
|
45
|
+
Godredis.redises(&:quit!)
|
46
|
+
|
47
|
+
# It's also return an enumerator, so you can do something like this:
|
48
|
+
Godredis.redises.map(&:connected?)
|
49
|
+
````
|
46
50
|
|
47
51
|
Subclass `Godredis::Base` class to collect Redis-related objects and use simple DSL to set mapping for the common methods such as `quit` or `reconnect` if they are different from the defaults.
|
48
52
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
53
|
+
````ruby
|
54
|
+
class CacheStoreGodredis < Godredis::Base
|
55
|
+
redis ->{ Rails.cache.instance_variable_get('@data') }
|
56
|
+
end
|
57
|
+
|
58
|
+
class ObjectsGodredis < Godredis::Base
|
59
|
+
redis ->{ Redis::Objects.redis }
|
60
|
+
end
|
61
|
+
|
62
|
+
class SidekiqGodredis < Godredis::Base
|
63
|
+
# define mappings with blocks or lambdas
|
64
|
+
redis ->(&block){ Sidekiq.redis &block }
|
65
|
+
client { redis &:client }
|
66
|
+
quit { redis &:quit }
|
67
|
+
end
|
68
|
+
````
|
63
69
|
|
64
70
|
Default mapping:
|
65
71
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
72
|
+
````ruby
|
73
|
+
redis { Redis.current }
|
74
|
+
client { redis.client }
|
75
|
+
connected? { client.connected? }
|
76
|
+
reconnect { client.reconnect.connected? }
|
77
|
+
quit { redis.quit }
|
78
|
+
````
|
71
79
|
|
72
80
|
You may also add custom commands:
|
73
81
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
82
|
+
````ruby
|
83
|
+
class SomeGodredis < Godredis::Base
|
84
|
+
del_some_key { redis.del('some_key') }
|
85
|
+
end
|
86
|
+
|
87
|
+
Godredis.redises(&:del_some_key!)
|
88
|
+
# etc...
|
89
|
+
````
|
80
90
|
|
81
91
|
Every commands (except question-marked) also has a banged wrapper `command!`, which calls an itself command and puts a short message about its execution result.
|
82
92
|
|
83
93
|
## Contributing
|
84
94
|
|
85
|
-
1. Fork it ( https://github.com/
|
95
|
+
1. Fork it ( https://github.com/estum/godredis/fork )
|
86
96
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
87
97
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
88
98
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/godredis.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "godredis"
|
7
|
-
spec.version = "0.0.
|
7
|
+
spec.version = "0.0.2"
|
8
8
|
spec.authors = ["Tõnis Simo"]
|
9
9
|
spec.email = ["anton.estum@gmail.com"]
|
10
10
|
spec.summary = %q{Godredis: bulk managing multiply Redis instances.}
|
@@ -19,6 +19,8 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
+
spec.required_ruby_version = ">= 1.9.3"
|
23
|
+
|
22
24
|
spec.add_development_dependency "bundler", "~> 1.6"
|
23
25
|
spec.add_development_dependency "rake"
|
24
26
|
spec.add_dependency "activesupport", ">= 3.0.0"
|
data/lib/godredis.rb
CHANGED
@@ -121,13 +121,17 @@ module Godredis
|
|
121
121
|
|
122
122
|
private
|
123
123
|
def say(action, &block)
|
124
|
-
result =
|
124
|
+
result = get_short_status_calling(&block)
|
125
125
|
puts "Redis [#{tag}]: #{action}... #{result}"
|
126
126
|
end
|
127
127
|
|
128
|
-
def
|
129
|
-
result = begin
|
130
|
-
|
128
|
+
def get_short_status_calling(&block)
|
129
|
+
result = begin
|
130
|
+
block.call
|
131
|
+
rescue => e
|
132
|
+
"[FAIL] #{e.message}"
|
133
|
+
end
|
134
|
+
result == true ? '[OK]' : result || "[FAIL]"
|
131
135
|
end
|
132
136
|
end
|
133
137
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: godredis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tõnis Simo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,7 +80,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
80
80
|
requirements:
|
81
81
|
- - ">="
|
82
82
|
- !ruby/object:Gem::Version
|
83
|
-
version:
|
83
|
+
version: 1.9.3
|
84
84
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
86
|
- - ">="
|
@@ -88,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
88
|
version: '0'
|
89
89
|
requirements: []
|
90
90
|
rubyforge_project:
|
91
|
-
rubygems_version: 2.
|
91
|
+
rubygems_version: 2.4.3
|
92
92
|
signing_key:
|
93
93
|
specification_version: 4
|
94
94
|
summary: 'Godredis: bulk managing multiply Redis instances.'
|