Class: MemCache::Server
- Inherits:
-
Object
- Object
- MemCache::Server
- Defined in:
- lib/memcache_server.rb
Overview
Extends the MemCache::Server object so that is is able to request stats.
Instance Method Summary collapse
-
#key ⇒ Object
Returns a unique key for the server.
-
#socket! ⇒ Object
Returns the open socket or raises a MemCache::MemCacheError if one is not available.
-
#stats ⇒ Object
Returns a hash of
{stat_key => value, ...}for all of the Server stats.
Instance Method Details
#key ⇒ Object
Returns a unique key for the server.
5 6 7 |
# File 'lib/memcache_server.rb', line 5 def key "#{host}:#{port}" end |
#socket! ⇒ Object
Returns the open socket or raises a MemCache::MemCacheError if one is not available.
10 11 12 |
# File 'lib/memcache_server.rb', line 10 def socket! socket or raise MemCacheError, "No connection to server" end |
#stats ⇒ Object
Returns a hash of {stat_key => value, ...} for all of the Server stats.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/memcache_server.rb', line 15 def stats sock = socket! stats = {} begin sock.write "stats\r\n" # Loop through the status which are sent back in the format of: # STAT <name> <value>\r\n # and ends with # END\r\n while (text = sock.gets) break if text =~ /^END/ s, name, value = text.split(/ /) stats[name] = value[0..-3] end rescue SystemCallError, IOError => err server.close raise MemCacheError, err. end stats end |