class Dalli::Protocol::Meta
Access point for a single Memcached server, accessed via Memcached’s meta protocol. Contains logic for managing connection state to the server (retries, etc), formatting requests to the server, and unpacking responses.
Constants
- TERMINATOR
Public Instance Methods
response_processor()
click to toggle source
# File lib/dalli/protocol/meta.rb, line 17 def response_processor @response_processor ||= ResponseProcessor.new(@connection_manager, @value_marshaller) end
Private Instance Methods
add(key, value, ttl, options)
click to toggle source
# File lib/dalli/protocol/meta.rb, line 68 def add(key, value, ttl, options) write_storage_req(:add, key, value, ttl, nil, options) response_processor.meta_set_with_cas unless quiet? end
append(key, value)
click to toggle source
rubocop:enable Metrics/ParameterLists
# File lib/dalli/protocol/meta.rb, line 90 def append(key, value) write_append_prepend_req(:append, key, value) response_processor.meta_set_append_prepend unless quiet? end
authenticate_connection()
click to toggle source
# File lib/dalli/protocol/meta.rb, line 168 def authenticate_connection raise Dalli::DalliError, 'Authentication not supported for the meta protocol.' end
cas(key)
click to toggle source
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/meta.rb, line 55 def cas(key) encoded_key, base64 = KeyRegularizer.encode(key) req = RequestFormatter.meta_get(key: encoded_key, value: true, return_cas: true, base64: base64) write(req) response_processor.meta_get_with_value_and_cas end
decr(key, count, ttl, initial)
click to toggle source
Arithmetic Commands
# File lib/dalli/protocol/meta.rb, line 120 def decr(key, count, ttl, initial) decr_incr false, key, count, ttl, initial end
decr_incr(incr, key, delta, ttl, initial)
click to toggle source
# File lib/dalli/protocol/meta.rb, line 128 def decr_incr(incr, key, delta, ttl, initial) ttl = initial ? TtlSanitizer.sanitize(ttl) : nil # Only set a TTL if we want to set a value on miss encoded_key, base64 = KeyRegularizer.encode(key) write(RequestFormatter.meta_arithmetic(key: encoded_key, delta: delta, initial: initial, incr: incr, ttl: ttl, quiet: quiet?, base64: base64)) response_processor.decr_incr unless quiet? end
delete(key, cas)
click to toggle source
Delete Commands
# File lib/dalli/protocol/meta.rb, line 111 def delete(key, cas) encoded_key, base64 = KeyRegularizer.encode(key) req = RequestFormatter.meta_delete(key: encoded_key, cas: cas, base64: base64, quiet: quiet?) write(req) response_processor.meta_delete unless quiet? end
flush(delay = 0)
click to toggle source
Other Commands
# File lib/dalli/protocol/meta.rb, line 137 def flush(delay = 0) write(RequestFormatter.flush(delay: delay)) response_processor.flush unless quiet? end
gat(key, ttl, options = nil)
click to toggle source
# File lib/dalli/protocol/meta.rb, line 38 def gat(key, ttl, options = nil) ttl = TtlSanitizer.sanitize(ttl) encoded_key, base64 = KeyRegularizer.encode(key) req = RequestFormatter.meta_get(key: encoded_key, ttl: ttl, base64: base64) write(req) response_processor.meta_get_with_value(cache_nils: cache_nils?(options)) end
get(key, options = nil)
click to toggle source
Retrieval Commands
# File lib/dalli/protocol/meta.rb, line 26 def get(key, options = nil) encoded_key, base64 = KeyRegularizer.encode(key) req = RequestFormatter.meta_get(key: encoded_key, base64: base64) write(req) response_processor.meta_get_with_value(cache_nils: cache_nils?(options)) end
incr(key, count, ttl, initial)
click to toggle source
# File lib/dalli/protocol/meta.rb, line 124 def incr(key, count, ttl, initial) decr_incr true, key, count, ttl, initial end
noop()
click to toggle source
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/meta.rb, line 144 def noop write_noop response_processor.consume_all_responses_until_mn end
prepend(key, value)
click to toggle source
# File lib/dalli/protocol/meta.rb, line 95 def prepend(key, value) write_append_prepend_req(:prepend, key, value) response_processor.meta_set_append_prepend unless quiet? end
quiet_get_request(key)
click to toggle source
# File lib/dalli/protocol/meta.rb, line 33 def quiet_get_request(key) encoded_key, base64 = KeyRegularizer.encode(key) RequestFormatter.meta_get(key: encoded_key, return_cas: true, base64: base64, quiet: true) end
replace(key, value, ttl, cas, options)
click to toggle source
# File lib/dalli/protocol/meta.rb, line 73 def replace(key, value, ttl, cas, options) write_storage_req(:replace, key, value, ttl, cas, options) response_processor.meta_set_with_cas unless quiet? end
reset_stats()
click to toggle source
# File lib/dalli/protocol/meta.rb, line 154 def reset_stats write(RequestFormatter.stats('reset')) response_processor.reset end
set(key, value, ttl, cas, options)
click to toggle source
Storage Commands
# File lib/dalli/protocol/meta.rb, line 63 def set(key, value, ttl, cas, options) write_storage_req(:set, key, value, ttl, cas, options) response_processor.meta_set_with_cas unless quiet? end
stats(info = nil)
click to toggle source
# File lib/dalli/protocol/meta.rb, line 149 def stats(info = nil) write(RequestFormatter.stats(info)) response_processor.stats end
touch(key, ttl)
click to toggle source
# File lib/dalli/protocol/meta.rb, line 46 def touch(key, ttl) encoded_key, base64 = KeyRegularizer.encode(key) req = RequestFormatter.meta_get(key: encoded_key, ttl: ttl, value: false, base64: base64) write(req) response_processor.meta_get_without_value end
version()
click to toggle source
# File lib/dalli/protocol/meta.rb, line 159 def version write(RequestFormatter.version) response_processor.version end
write_append_prepend_req(mode, key, value, ttl = nil, cas = nil, _options = {})
click to toggle source
rubocop:disable Metrics/ParameterLists
# File lib/dalli/protocol/meta.rb, line 101 def write_append_prepend_req(mode, key, value, ttl = nil, cas = nil, _options = {}) ttl = TtlSanitizer.sanitize(ttl) if ttl encoded_key, base64 = KeyRegularizer.encode(key) req = RequestFormatter.meta_set(key: encoded_key, value: value, base64: base64, cas: cas, ttl: ttl, mode: mode, quiet: quiet?) write(req) end
write_noop()
click to toggle source
# File lib/dalli/protocol/meta.rb, line 164 def write_noop write(RequestFormatter.meta_noop) end
write_storage_req(mode, key, raw_value, ttl = nil, cas = nil, options = {})
click to toggle source
rubocop:disable Metrics/ParameterLists
# File lib/dalli/protocol/meta.rb, line 79 def write_storage_req(mode, key, raw_value, ttl = nil, cas = nil, options = {}) (value, bitflags) = @value_marshaller.store(key, raw_value, options) ttl = TtlSanitizer.sanitize(ttl) if ttl encoded_key, base64 = KeyRegularizer.encode(key) req = RequestFormatter.meta_set(key: encoded_key, value: value, bitflags: bitflags, cas: cas, ttl: ttl, mode: mode, quiet: quiet?, base64: base64) write(req) end