dalli 3.2.8 → 5.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +249 -1
- data/Gemfile +16 -2
- data/README.md +82 -2
- data/lib/dalli/client.rb +286 -25
- data/lib/dalli/instrumentation.rb +143 -0
- data/lib/dalli/key_manager.rb +23 -8
- data/lib/dalli/options.rb +1 -1
- data/lib/dalli/pid_cache.rb +1 -1
- data/lib/dalli/pipelined_deleter.rb +82 -0
- data/lib/dalli/pipelined_getter.rb +44 -20
- data/lib/dalli/pipelined_setter.rb +87 -0
- data/lib/dalli/protocol/base.rb +94 -24
- data/lib/dalli/protocol/connection_manager.rb +23 -12
- data/lib/dalli/protocol/{meta/key_regularizer.rb → key_regularizer.rb} +1 -1
- data/lib/dalli/protocol/meta.rb +173 -10
- data/lib/dalli/protocol/{meta/request_formatter.rb → request_formatter.rb} +42 -10
- data/lib/dalli/protocol/response_buffer.rb +36 -12
- data/lib/dalli/protocol/{meta/response_processor.rb → response_processor.rb} +72 -26
- data/lib/dalli/protocol/server_config_parser.rb +2 -2
- data/lib/dalli/protocol/string_marshaller.rb +65 -0
- data/lib/dalli/protocol/ttl_sanitizer.rb +1 -1
- data/lib/dalli/protocol/value_compressor.rb +2 -11
- data/lib/dalli/protocol/value_marshaller.rb +1 -1
- data/lib/dalli/protocol/value_serializer.rb +59 -40
- data/lib/dalli/protocol.rb +10 -0
- data/lib/dalli/ring.rb +2 -2
- data/lib/dalli/servers_arg_normalizer.rb +1 -1
- data/lib/dalli/socket.rb +74 -14
- data/lib/dalli/version.rb +2 -2
- data/lib/dalli.rb +12 -5
- data/lib/rack/session/dalli.rb +43 -8
- metadata +26 -17
- data/lib/dalli/protocol/binary/request_formatter.rb +0 -117
- data/lib/dalli/protocol/binary/response_header.rb +0 -36
- data/lib/dalli/protocol/binary/response_processor.rb +0 -239
- data/lib/dalli/protocol/binary/sasl_authentication.rb +0 -60
- data/lib/dalli/protocol/binary.rb +0 -173
- data/lib/dalli/server.rb +0 -6
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'forwardable'
|
|
4
|
-
require 'socket'
|
|
5
|
-
require 'timeout'
|
|
6
|
-
|
|
7
|
-
module Dalli
|
|
8
|
-
module Protocol
|
|
9
|
-
##
|
|
10
|
-
# Access point for a single Memcached server, accessed via Memcached's binary
|
|
11
|
-
# protocol. Contains logic for managing connection state to the server (retries, etc),
|
|
12
|
-
# formatting requests to the server, and unpacking responses.
|
|
13
|
-
##
|
|
14
|
-
class Binary < Base
|
|
15
|
-
def response_processor
|
|
16
|
-
@response_processor ||= ResponseProcessor.new(@connection_manager, @value_marshaller)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
private
|
|
20
|
-
|
|
21
|
-
# Retrieval Commands
|
|
22
|
-
def get(key, options = nil)
|
|
23
|
-
req = RequestFormatter.standard_request(opkey: :get, key: key)
|
|
24
|
-
write(req)
|
|
25
|
-
response_processor.get(cache_nils: cache_nils?(options))
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def quiet_get_request(key)
|
|
29
|
-
RequestFormatter.standard_request(opkey: :getkq, key: key)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def gat(key, ttl, options = nil)
|
|
33
|
-
ttl = TtlSanitizer.sanitize(ttl)
|
|
34
|
-
req = RequestFormatter.standard_request(opkey: :gat, key: key, ttl: ttl)
|
|
35
|
-
write(req)
|
|
36
|
-
response_processor.get(cache_nils: cache_nils?(options))
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def touch(key, ttl)
|
|
40
|
-
ttl = TtlSanitizer.sanitize(ttl)
|
|
41
|
-
write(RequestFormatter.standard_request(opkey: :touch, key: key, ttl: ttl))
|
|
42
|
-
response_processor.generic_response
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
# TODO: This is confusing, as there's a cas command in memcached
|
|
46
|
-
# and this isn't it. Maybe rename? Maybe eliminate?
|
|
47
|
-
def cas(key)
|
|
48
|
-
req = RequestFormatter.standard_request(opkey: :get, key: key)
|
|
49
|
-
write(req)
|
|
50
|
-
response_processor.data_cas_response
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
# Storage Commands
|
|
54
|
-
def set(key, value, ttl, cas, options)
|
|
55
|
-
opkey = quiet? ? :setq : :set
|
|
56
|
-
storage_req(opkey, key, value, ttl, cas, options)
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def add(key, value, ttl, options)
|
|
60
|
-
opkey = quiet? ? :addq : :add
|
|
61
|
-
storage_req(opkey, key, value, ttl, 0, options)
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def replace(key, value, ttl, cas, options)
|
|
65
|
-
opkey = quiet? ? :replaceq : :replace
|
|
66
|
-
storage_req(opkey, key, value, ttl, cas, options)
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
# rubocop:disable Metrics/ParameterLists
|
|
70
|
-
def storage_req(opkey, key, value, ttl, cas, options)
|
|
71
|
-
(value, bitflags) = @value_marshaller.store(key, value, options)
|
|
72
|
-
ttl = TtlSanitizer.sanitize(ttl)
|
|
73
|
-
|
|
74
|
-
req = RequestFormatter.standard_request(opkey: opkey, key: key,
|
|
75
|
-
value: value, bitflags: bitflags,
|
|
76
|
-
ttl: ttl, cas: cas)
|
|
77
|
-
write(req)
|
|
78
|
-
response_processor.storage_response unless quiet?
|
|
79
|
-
end
|
|
80
|
-
# rubocop:enable Metrics/ParameterLists
|
|
81
|
-
|
|
82
|
-
def append(key, value)
|
|
83
|
-
opkey = quiet? ? :appendq : :append
|
|
84
|
-
write_append_prepend opkey, key, value
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
def prepend(key, value)
|
|
88
|
-
opkey = quiet? ? :prependq : :prepend
|
|
89
|
-
write_append_prepend opkey, key, value
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
def write_append_prepend(opkey, key, value)
|
|
93
|
-
write(RequestFormatter.standard_request(opkey: opkey, key: key, value: value))
|
|
94
|
-
response_processor.no_body_response unless quiet?
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
# Delete Commands
|
|
98
|
-
def delete(key, cas)
|
|
99
|
-
opkey = quiet? ? :deleteq : :delete
|
|
100
|
-
req = RequestFormatter.standard_request(opkey: opkey, key: key, cas: cas)
|
|
101
|
-
write(req)
|
|
102
|
-
response_processor.delete unless quiet?
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
# Arithmetic Commands
|
|
106
|
-
def decr(key, count, ttl, initial)
|
|
107
|
-
opkey = quiet? ? :decrq : :decr
|
|
108
|
-
decr_incr opkey, key, count, ttl, initial
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
def incr(key, count, ttl, initial)
|
|
112
|
-
opkey = quiet? ? :incrq : :incr
|
|
113
|
-
decr_incr opkey, key, count, ttl, initial
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
# This allows us to special case a nil initial value, and
|
|
117
|
-
# handle it differently than a zero. This special value
|
|
118
|
-
# for expiry causes memcached to return a not found
|
|
119
|
-
# if the key doesn't already exist, rather than
|
|
120
|
-
# setting the initial value
|
|
121
|
-
NOT_FOUND_EXPIRY = 0xFFFFFFFF
|
|
122
|
-
|
|
123
|
-
def decr_incr(opkey, key, count, ttl, initial)
|
|
124
|
-
expiry = initial ? TtlSanitizer.sanitize(ttl) : NOT_FOUND_EXPIRY
|
|
125
|
-
initial ||= 0
|
|
126
|
-
write(RequestFormatter.decr_incr_request(opkey: opkey, key: key,
|
|
127
|
-
count: count, initial: initial, expiry: expiry))
|
|
128
|
-
response_processor.decr_incr unless quiet?
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
# Other Commands
|
|
132
|
-
def flush(ttl = 0)
|
|
133
|
-
opkey = quiet? ? :flushq : :flush
|
|
134
|
-
write(RequestFormatter.standard_request(opkey: opkey, ttl: ttl))
|
|
135
|
-
response_processor.no_body_response unless quiet?
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
# Noop is a keepalive operation but also used to demarcate the end of a set of pipelined commands.
|
|
139
|
-
# We need to read all the responses at once.
|
|
140
|
-
def noop
|
|
141
|
-
write_noop
|
|
142
|
-
response_processor.consume_all_responses_until_noop
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
def stats(info = '')
|
|
146
|
-
req = RequestFormatter.standard_request(opkey: :stat, key: info)
|
|
147
|
-
write(req)
|
|
148
|
-
response_processor.stats
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
def reset_stats
|
|
152
|
-
write(RequestFormatter.standard_request(opkey: :stat, key: 'reset'))
|
|
153
|
-
response_processor.reset
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
def version
|
|
157
|
-
write(RequestFormatter.standard_request(opkey: :version))
|
|
158
|
-
response_processor.version
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
def write_noop
|
|
162
|
-
req = RequestFormatter.standard_request(opkey: :noop)
|
|
163
|
-
write(req)
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
require_relative 'binary/request_formatter'
|
|
167
|
-
require_relative 'binary/response_header'
|
|
168
|
-
require_relative 'binary/response_processor'
|
|
169
|
-
require_relative 'binary/sasl_authentication'
|
|
170
|
-
include SaslAuthentication
|
|
171
|
-
end
|
|
172
|
-
end
|
|
173
|
-
end
|