Module: FastCache::Memcache::Protocol
- Included in:
- Connection
- Defined in:
- lib/fastcache/memcache/protocol.rb
Overview
Informal protocol for mixin:
bucket will ask for a key and return a bucket
nodes will return connection nodes
Instance Method Summary collapse
- #add(key, value, expiry = 0) ⇒ Object
- #cas ⇒ Object
- #decr ⇒ Object
- #delete(key, expiry = 0) ⇒ Object
- #flush_all_caches ⇒ Object
- #flush_cache(key) ⇒ Object
- #get(key) ⇒ Object
- #incr ⇒ Object
- #replace(key, value, expiry = 0) ⇒ Object
- #reset_connections ⇒ Object
- #set(key, value, expiry = 0) ⇒ Object
- #stats ⇒ Object
Instance Method Details
#add(key, value, expiry = 0) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/fastcache/memcache/protocol.rb', line 37 def add(key, value, expiry = 0) data = value.to_s bucket(key).select(nodes) {|node_key, node| node.write "add #{node_key} 0 #{expiry} #{data.size}\r\n#{data}\r\n" resp = node.gets if resp == "STORED\r\n" FastCache::Maybe.just(data) else FastCache::Maybe.nothing end } rescue FastCache::Memcache::ProtocolError FastCache::Maybe.nothing end |
#cas ⇒ Object
77 78 79 |
# File 'lib/fastcache/memcache/protocol.rb', line 77 def cas(*) fail 'Not implemented' end |
#decr ⇒ Object
85 86 87 |
# File 'lib/fastcache/memcache/protocol.rb', line 85 def decr(*) fail 'Not implemented' end |
#delete(key, expiry = 0) ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/fastcache/memcache/protocol.rb', line 67 def delete(key, expiry = 0) bucket(key).select(nodes) {|node_key, node| node.write "delete #{node_key} #{expiry}\r\n" resp = node.gets resp == "DELETED\r\n" } rescue FastCache::Memcache::Protocol FastCache::Maybe.nothing end |
#flush_all_caches ⇒ Object
89 90 91 |
# File 'lib/fastcache/memcache/protocol.rb', line 89 def flush_all_caches fail 'Not implemented' end |
#flush_cache(key) ⇒ Object
93 94 95 |
# File 'lib/fastcache/memcache/protocol.rb', line 93 def flush_cache(key) fail 'Not implemented' end |
#get(key) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/fastcache/memcache/protocol.rb', line 6 def get(key) bucket(key).select(nodes) {|node_key, node| node.write "get #{node_key}\r\n" resp = node.gets break FastCache::Maybe.nothing if resp == "END\r\n" resp =~ /(\d+)\r/ value = node.read $1.to_i node.read 2 # \r\n node.gets # END\r\n break FastCache::Maybe.just(value) unless value.nil? FastCache::Maybe.nothing } rescue FastCache::Memcache::ProtocolError FastCache::Maybe.nothing end |
#incr ⇒ Object
81 82 83 |
# File 'lib/fastcache/memcache/protocol.rb', line 81 def incr(*) fail 'Not implemented' end |
#replace(key, value, expiry = 0) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/fastcache/memcache/protocol.rb', line 52 def replace(key, value, expiry = 0) data = value.to_s bucket(key).select(nodes) {|node_key, node| node.write "replace #{node_key} 0 #{expiry} #{data.size}\r\n#{data}\r\n" resp = node.gets if resp == "STORED\r\n" FastCache::Maybe.just(data) else FastCache::Maybe.nothing end } rescue FastCache::Memcache::ProtocolError FastCache::Maybe.nothing end |
#reset_connections ⇒ Object
101 102 103 |
# File 'lib/fastcache/memcache/protocol.rb', line 101 def reset_connections fail 'Not implemented yet' end |
#set(key, value, expiry = 0) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/fastcache/memcache/protocol.rb', line 22 def set(key, value, expiry = 0) value = value.to_s bucket(key).select(nodes) {|node_key, node| node.write "set #{node_key} 0 #{expiry} #{value.size}\r\n#{value}\r\n" result = node.gets if result == "STORED\r\n" FastCache::Maybe.just(value) else FastCache::Maybe.nothing end } rescue FastCache::Memcache::ProtocolError FastCache::Maybe.nothing end |
#stats ⇒ Object
97 98 99 |
# File 'lib/fastcache/memcache/protocol.rb', line 97 def stats(*) fail 'Not implemented' end |