class Dalli::Protocol::Binary
Access point for a single Memcached server, accessed via Memcached's binary protocol. Contains logic for managing connection state to the server (retries, etc), formatting requests to the server, and unpacking responses.
Constants
- NOT_FOUND_EXPIRY
This allows us to special case a nil initial value, and handle it differently than a zero. This special value for expiry causes memcached to return a not found if the key doesn't already exist, rather than setting the initial value
Public Instance Methods
# File lib/dalli/protocol/binary.rb, line 14 def response_processor @response_processor ||= ResponseProcessor.new(@connection_manager, @value_marshaller) end
Private Instance Methods
# File lib/dalli/protocol/binary.rb, line 58 def add(key, value, ttl, options) opkey = quiet? ? :addq : :add storage_req(opkey, key, value, ttl, 0, options) end
rubocop:enable Metrics/ParameterLists
# File lib/dalli/protocol/binary.rb, line 81 def append(key, value) opkey = quiet? ? :appendq : :append write_append_prepend opkey, key, value end
TODO: This is confusing, as there's a cas command in memcached and this isn't it. Maybe rename? Maybe eliminate?
# File lib/dalli/protocol/binary.rb, line 46 def cas(key) req = RequestFormatter.standard_request(opkey: :get, key: key) write(req) response_processor.data_cas_response end
Arithmetic Commands
# File lib/dalli/protocol/binary.rb, line 105 def decr(key, count, ttl, initial) opkey = quiet? ? :decrq : :decr decr_incr opkey, key, count, ttl, initial end
# File lib/dalli/protocol/binary.rb, line 122 def decr_incr(opkey, key, count, ttl, initial) expiry = initial ? TtlSanitizer.sanitize(ttl) : NOT_FOUND_EXPIRY initial ||= 0 write(RequestFormatter.decr_incr_request(opkey: opkey, key: key, count: count, initial: initial, expiry: expiry)) response_processor.decr_incr unless quiet? end
Delete Commands
# File lib/dalli/protocol/binary.rb, line 97 def delete(key, cas) opkey = quiet? ? :deleteq : :delete req = RequestFormatter.standard_request(opkey: opkey, key: key, cas: cas) write(req) response_processor.delete unless quiet? end
Other Commands
# File lib/dalli/protocol/binary.rb, line 131 def flush(ttl = 0) opkey = quiet? ? :flushq : :flush write(RequestFormatter.standard_request(opkey: opkey, ttl: ttl)) response_processor.no_body_response unless quiet? end
# File lib/dalli/protocol/binary.rb, line 31 def gat(key, ttl, options = nil) ttl = TtlSanitizer.sanitize(ttl) req = RequestFormatter.standard_request(opkey: :gat, key: key, ttl: ttl) write(req) response_processor.get(cache_nils: cache_nils?(options)) end
Retrieval Commands
# File lib/dalli/protocol/binary.rb, line 21 def get(key, options = nil) req = RequestFormatter.standard_request(opkey: :get, key: key) write(req) response_processor.get(cache_nils: cache_nils?(options)) end
# File lib/dalli/protocol/binary.rb, line 110 def incr(key, count, ttl, initial) opkey = quiet? ? :incrq : :incr decr_incr opkey, key, count, ttl, initial end
Noop is a keepalive operation but also used to demarcate the end of a set of pipelined commands. We need to read all the responses at once.
# File lib/dalli/protocol/binary.rb, line 139 def noop write_noop response_processor.consume_all_responses_until_noop end
# File lib/dalli/protocol/binary.rb, line 86 def prepend(key, value) opkey = quiet? ? :prependq : :prepend write_append_prepend opkey, key, value end
# File lib/dalli/protocol/binary.rb, line 27 def quiet_get_request(key) RequestFormatter.standard_request(opkey: :getkq, key: key) end
# File lib/dalli/protocol/binary.rb, line 63 def replace(key, value, ttl, cas, options) opkey = quiet? ? :replaceq : :replace storage_req(opkey, key, value, ttl, cas, options) end
# File lib/dalli/protocol/binary.rb, line 150 def reset_stats write(RequestFormatter.standard_request(opkey: :stat, key: 'reset')) response_processor.reset end
Storage Commands
# File lib/dalli/protocol/binary.rb, line 53 def set(key, value, ttl, cas, options) opkey = quiet? ? :setq : :set storage_req(opkey, key, value, ttl, cas, options) end
# File lib/dalli/protocol/binary.rb, line 144 def stats(info = '') req = RequestFormatter.standard_request(opkey: :stat, key: info) write(req) response_processor.stats end
rubocop:disable Metrics/ParameterLists
# File lib/dalli/protocol/binary.rb, line 69 def storage_req(opkey, key, value, ttl, cas, options) (value, bitflags) = @value_marshaller.store(key, value, options) ttl = TtlSanitizer.sanitize(ttl) req = RequestFormatter.standard_request(opkey: opkey, key: key, value: value, bitflags: bitflags, ttl: ttl, cas: cas) write(req) response_processor.storage_response unless quiet? end
# File lib/dalli/protocol/binary.rb, line 38 def touch(key, ttl) ttl = TtlSanitizer.sanitize(ttl) write(RequestFormatter.standard_request(opkey: :touch, key: key, ttl: ttl)) response_processor.generic_response end
# File lib/dalli/protocol/binary.rb, line 155 def version write(RequestFormatter.standard_request(opkey: :version)) response_processor.version end
# File lib/dalli/protocol/binary.rb, line 91 def write_append_prepend(opkey, key, value) write(RequestFormatter.standard_request(opkey: opkey, key: key, value: value)) response_processor.no_body_response unless quiet? end
# File lib/dalli/protocol/binary.rb, line 160 def write_noop req = RequestFormatter.standard_request(opkey: :noop) write(req) end