Class: Redis
Overview
Redis convenience and compatibility layer
Defined Under Namespace
Modules: SaneShutdown
Class Method Summary collapse
Instance Method Summary collapse
- #available? ⇒ Boolean
-
#broken_shutdown ⇒ Object
redis 2.2.2 shutdown implementation does not disconnect from the redis server.
-
#host ⇒ Object
Redis 2 removed some useful methods.
- #info_with_rescue ⇒ Object
-
#inspect ⇒ Object
Redis 2 tries to establish a connection on inspect.
- #master! ⇒ Object
- #master? ⇒ Boolean
- #msetnx(*values) ⇒ Object
- #port ⇒ Object
- #role ⇒ Object
- #server ⇒ Object
-
#shutdown ⇒ Object
Synchronously save the dataset to disk and then shut down the server.
- #slave? ⇒ Boolean
- #slave_of!(host, port) ⇒ Object
- #slave_of?(host, port) ⇒ Boolean
Class Method Details
.from_server_string(server_string, options = {}) ⇒ Object
:nodoc:
3 4 5 6 7 8 |
# File 'lib/beetle/redis_ext.rb', line 3 def self.from_server_string(server_string, = {}) host, port = server_string.split(':') = {:host => host, :port => port}.update() .delete(:logger) if Redis::VERSION >= "5.0" new() end |
Instance Method Details
#available? ⇒ Boolean
29 30 31 |
# File 'lib/beetle/redis_ext.rb', line 29 def available? info_with_rescue != {} end |
#broken_shutdown ⇒ Object
redis 2.2.2 shutdown implementation does not disconnect from the redis server. this leaves the connection in an inconsistent state and causes the next command to silently fail. this in turn breaks our cucumber test scenarios. fix this here, until a new version is released which fixes the problem.
65 |
# File 'lib/beetle/redis_ext.rb', line 65 alias_method :broken_shutdown, :shutdown |
#host ⇒ Object
Redis 2 removed some useful methods. add them back.
11 |
# File 'lib/beetle/redis_ext.rb', line 11 def host; @client.host; end |
#info_with_rescue ⇒ Object
23 24 25 26 27 |
# File 'lib/beetle/redis_ext.rb', line 23 def info_with_rescue info rescue Exception {} end |
#inspect ⇒ Object
Redis 2 tries to establish a connection on inspect. this is evil!
56 57 58 |
# File 'lib/beetle/redis_ext.rb', line 56 def inspect super end |
#master! ⇒ Object
15 16 17 |
# File 'lib/beetle/redis_ext.rb', line 15 def master! slaveof("no", "one") end |
#master? ⇒ Boolean
37 38 39 |
# File 'lib/beetle/redis_ext.rb', line 37 def master? role == "master" end |
#msetnx(*values) ⇒ Object
79 80 81 |
# File 'lib/beetle/redis_ext.rb', line 79 def msetnx(*values) super != 0 end |
#port ⇒ Object
12 |
# File 'lib/beetle/redis_ext.rb', line 12 def port; @client.port; end |
#role ⇒ Object
33 34 35 |
# File 'lib/beetle/redis_ext.rb', line 33 def role info_with_rescue["role"] || "unknown" end |
#server ⇒ Object
13 |
# File 'lib/beetle/redis_ext.rb', line 13 def server; "#{host}:#{port}"; end |
#shutdown ⇒ Object
Synchronously save the dataset to disk and then shut down the server.
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/beetle/redis_ext.rb', line 68 def shutdown synchronize do begin @client.call [:shutdown] rescue Errno::ECONNREFUSED ensure @client.disconnect end end end |
#slave? ⇒ Boolean
41 42 43 |
# File 'lib/beetle/redis_ext.rb', line 41 def slave? role == "slave" end |
#slave_of!(host, port) ⇒ Object
19 20 21 |
# File 'lib/beetle/redis_ext.rb', line 19 def slave_of!(host, port) slaveof(host, port) end |
#slave_of?(host, port) ⇒ Boolean
45 46 47 48 |
# File 'lib/beetle/redis_ext.rb', line 45 def slave_of?(host, port) info = info_with_rescue info["role"] == "slave" && info["master_host"] == host && info["master_port"] == port.to_s end |