dalli 4.3.12 → 5.0.0
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 +23 -172
- data/Gemfile +1 -1
- data/README.md +4 -63
- data/lib/dalli/client.rb +39 -99
- data/lib/dalli/compressor.rb +5 -53
- data/lib/dalli/instrumentation.rb +1 -1
- data/lib/dalli/key_manager.rb +2 -28
- data/lib/dalli/options.rb +2 -2
- data/lib/dalli/pipelined_deleter.rb +3 -3
- data/lib/dalli/pipelined_getter.rb +31 -52
- data/lib/dalli/pipelined_setter.rb +11 -20
- data/lib/dalli/protocol/base.rb +32 -176
- data/lib/dalli/protocol/connection_manager.rb +20 -143
- data/lib/dalli/protocol/meta.rb +16 -55
- data/lib/dalli/protocol/{meta/request_formatter.rb → request_formatter.rb} +8 -21
- data/lib/dalli/protocol/response_buffer.rb +12 -27
- data/lib/dalli/protocol/{meta/response_processor.rb → response_processor.rb} +35 -100
- data/lib/dalli/protocol/server_config_parser.rb +1 -1
- data/lib/dalli/protocol/string_marshaller.rb +1 -3
- data/lib/dalli/protocol/value_compressor.rb +7 -36
- data/lib/dalli/protocol/value_marshaller.rb +0 -4
- data/lib/dalli/protocol/value_serializer.rb +1 -1
- data/lib/dalli/protocol.rb +9 -7
- data/lib/dalli/ring.rb +2 -2
- data/lib/dalli/servers_arg_normalizer.rb +1 -1
- data/lib/dalli/socket.rb +5 -54
- data/lib/dalli/version.rb +2 -2
- data/lib/dalli.rb +0 -3
- data/lib/rack/session/dalli.rb +2 -1
- metadata +8 -18
- data/lib/dalli/json_serializer.rb +0 -28
- data/lib/dalli/protocol/binary/request_formatter.rb +0 -116
- data/lib/dalli/protocol/binary/response_header.rb +0 -36
- data/lib/dalli/protocol/binary/response_processor.rb +0 -259
- data/lib/dalli/protocol/binary/sasl_authentication.rb +0 -60
- data/lib/dalli/protocol/binary.rb +0 -202
- data/lib/dalli/protocol_deprecations.rb +0 -45
- /data/lib/dalli/protocol/{meta/key_regularizer.rb → key_regularizer.rb} +0 -0
|
@@ -102,7 +102,7 @@ module Dalli
|
|
|
102
102
|
Dalli.logger.warn 'SECURITY WARNING: Dalli is using Marshal for serialization. ' \
|
|
103
103
|
'Marshal can execute arbitrary code during deserialization. ' \
|
|
104
104
|
'If your memcached server could be compromised, consider using ' \
|
|
105
|
-
'a safer serializer: Dalli::Client.new(servers, serializer:
|
|
105
|
+
'a safer serializer like JSON: Dalli::Client.new(servers, serializer: JSON)'
|
|
106
106
|
@@marshal_warning_logged = true # rubocop:disable Style/ClassVars
|
|
107
107
|
end
|
|
108
108
|
end
|
data/lib/dalli/protocol.rb
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'openssl'
|
|
4
3
|
require 'timeout'
|
|
5
4
|
|
|
6
5
|
module Dalli
|
|
@@ -17,11 +16,14 @@ module Dalli
|
|
|
17
16
|
[Timeout::Error]
|
|
18
17
|
end
|
|
19
18
|
|
|
20
|
-
# SSL errors
|
|
21
|
-
#
|
|
22
|
-
#
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
# SSL errors that occur during read/write operations (not during initial
|
|
20
|
+
# handshake) should trigger reconnection. These indicate transient network
|
|
21
|
+
# issues, not configuration problems.
|
|
22
|
+
SSL_ERRORS =
|
|
23
|
+
if defined?(OpenSSL::SSL::SSLError)
|
|
24
|
+
[OpenSSL::SSL::SSLError]
|
|
25
|
+
else
|
|
26
|
+
[]
|
|
27
|
+
end
|
|
26
28
|
end
|
|
27
29
|
end
|
data/lib/dalli/ring.rb
CHANGED
|
@@ -23,9 +23,9 @@ module Dalli
|
|
|
23
23
|
|
|
24
24
|
attr_accessor :servers, :continuum
|
|
25
25
|
|
|
26
|
-
def initialize(servers_arg,
|
|
26
|
+
def initialize(servers_arg, options)
|
|
27
27
|
@servers = servers_arg.map do |s|
|
|
28
|
-
|
|
28
|
+
Dalli::Protocol::Meta.new(s, options)
|
|
29
29
|
end
|
|
30
30
|
@continuum = nil
|
|
31
31
|
@continuum = build_continuum(servers) if servers.size > 1
|
|
@@ -16,7 +16,7 @@ module Dalli
|
|
|
16
16
|
# weight are optional (e.g. 'localhost', 'abc.com:12345', 'example.org:22222:3')
|
|
17
17
|
# * A colon separated string of (UNIX socket, weight) where the weight is optional
|
|
18
18
|
# (e.g. '/var/run/memcached/socket', '/tmp/xyz:3') (not supported on Windows)
|
|
19
|
-
# * A URI with a 'memcached' protocol
|
|
19
|
+
# * A URI with a 'memcached' protocol (e.g. 'memcached://localhost:11211')
|
|
20
20
|
#
|
|
21
21
|
# The methods in this module do not validate the format of individual server strings, but
|
|
22
22
|
# rather normalize the argument into a compact array, wherein each array entry corresponds
|
data/lib/dalli/socket.rb
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
require 'openssl'
|
|
4
4
|
require 'rbconfig'
|
|
5
|
-
require 'timeout'
|
|
6
5
|
|
|
7
6
|
module Dalli
|
|
8
7
|
##
|
|
@@ -13,8 +12,6 @@ module Dalli
|
|
|
13
12
|
# Common methods for all socket implementations.
|
|
14
13
|
##
|
|
15
14
|
module InstanceMethods
|
|
16
|
-
MAX_AVAILABLE_BYTES = 8196 * 8
|
|
17
|
-
|
|
18
15
|
def readfull(count)
|
|
19
16
|
value = String.new(capacity: count + 1)
|
|
20
17
|
loop do
|
|
@@ -27,21 +24,16 @@ module Dalli
|
|
|
27
24
|
|
|
28
25
|
def read_available
|
|
29
26
|
value = +''
|
|
30
|
-
|
|
31
|
-
result = read_nonblock(
|
|
27
|
+
loop do
|
|
28
|
+
result = read_nonblock(8196, exception: false)
|
|
32
29
|
break if WAIT_RCS.include?(result)
|
|
33
30
|
raise Errno::ECONNRESET, "Connection reset: #{logged_options.inspect}" unless result
|
|
34
31
|
|
|
35
32
|
value << result
|
|
36
|
-
break if result.bytesize < 8196 && !buffered_data?
|
|
37
33
|
end
|
|
38
34
|
value
|
|
39
35
|
end
|
|
40
36
|
|
|
41
|
-
def buffered_data?
|
|
42
|
-
false
|
|
43
|
-
end
|
|
44
|
-
|
|
45
37
|
WAIT_RCS = %i[wait_writable wait_readable].freeze
|
|
46
38
|
|
|
47
39
|
def append_to_buffer?(result)
|
|
@@ -72,14 +64,6 @@ module Dalli
|
|
|
72
64
|
class SSLSocket < ::OpenSSL::SSL::SSLSocket
|
|
73
65
|
include Dalli::Socket::InstanceMethods
|
|
74
66
|
|
|
75
|
-
def pending_data?
|
|
76
|
-
pending.positive? || (@rbuffer && !@rbuffer.empty?)
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def buffered_data?
|
|
80
|
-
RUBY_ENGINE == 'jruby' || pending_data?
|
|
81
|
-
end
|
|
82
|
-
|
|
83
67
|
def options
|
|
84
68
|
io.options
|
|
85
69
|
end
|
|
@@ -117,11 +101,7 @@ module Dalli
|
|
|
117
101
|
sock.options = { host: host, port: port }.merge(options)
|
|
118
102
|
init_socket_options(sock, options)
|
|
119
103
|
|
|
120
|
-
|
|
121
|
-
wrapping_ssl_socket(sock, host, options[:ssl_context], options[:socket_timeout])
|
|
122
|
-
else
|
|
123
|
-
sock
|
|
124
|
-
end
|
|
104
|
+
options[:ssl_context] ? wrapping_ssl_socket(sock, host, options[:ssl_context]) : sock
|
|
125
105
|
end
|
|
126
106
|
end
|
|
127
107
|
|
|
@@ -201,41 +181,12 @@ module Dalli
|
|
|
201
181
|
[seconds, microseconds].pack(timeval_pack_format(sock))
|
|
202
182
|
end
|
|
203
183
|
|
|
204
|
-
|
|
205
|
-
# attempt doesn't hold a file descriptor until GC.
|
|
206
|
-
def self.wrapping_ssl_socket(tcp_socket, host, ssl_context, socket_timeout = nil)
|
|
207
|
-
warn_if_unverified(ssl_context)
|
|
208
|
-
connected = false
|
|
184
|
+
def self.wrapping_ssl_socket(tcp_socket, host, ssl_context)
|
|
209
185
|
ssl_socket = Dalli::Socket::SSLSocket.new(tcp_socket, ssl_context)
|
|
210
186
|
ssl_socket.hostname = host
|
|
211
187
|
ssl_socket.sync_close = true
|
|
212
|
-
|
|
213
|
-
connected = true
|
|
188
|
+
ssl_socket.connect
|
|
214
189
|
ssl_socket
|
|
215
|
-
ensure
|
|
216
|
-
tcp_socket.close unless connected
|
|
217
|
-
end
|
|
218
|
-
|
|
219
|
-
# Class variable to track whether the TLS verification warning has been logged
|
|
220
|
-
@@ssl_verification_warning_logged = false # rubocop:disable Style/ClassVars
|
|
221
|
-
|
|
222
|
-
# Verification comes entirely from the caller's ssl_context, and a bare
|
|
223
|
-
# SSLContext.new verifies nothing, so warn (once per process) when the
|
|
224
|
-
# certificate or the hostname won't be checked.
|
|
225
|
-
def self.warn_if_unverified(ssl_context)
|
|
226
|
-
return if @@ssl_verification_warning_logged
|
|
227
|
-
|
|
228
|
-
problem = if !ssl_context.verify_mode.to_i.anybits?(::OpenSSL::SSL::VERIFY_PEER)
|
|
229
|
-
'verify_mode is VERIFY_NONE, so the server certificate is not checked'
|
|
230
|
-
elsif !ssl_context.verify_hostname
|
|
231
|
-
'verify_hostname is false, so the certificate is not checked against the hostname'
|
|
232
|
-
end
|
|
233
|
-
return unless problem
|
|
234
|
-
|
|
235
|
-
Dalli.logger.warn "SECURITY WARNING: Dalli's ssl_context #{problem}. " \
|
|
236
|
-
'Use ssl_context.set_params(verify_mode: OpenSSL::SSL::VERIFY_PEER, ' \
|
|
237
|
-
'verify_hostname: true) to verify the server.'
|
|
238
|
-
@@ssl_verification_warning_logged = true # rubocop:disable Style/ClassVars
|
|
239
190
|
end
|
|
240
191
|
end
|
|
241
192
|
|
data/lib/dalli/version.rb
CHANGED
data/lib/dalli.rb
CHANGED
|
@@ -62,8 +62,6 @@ require_relative 'dalli/version'
|
|
|
62
62
|
require_relative 'dalli/instrumentation'
|
|
63
63
|
|
|
64
64
|
require_relative 'dalli/compressor'
|
|
65
|
-
require_relative 'dalli/json_serializer'
|
|
66
|
-
require_relative 'dalli/protocol_deprecations'
|
|
67
65
|
require_relative 'dalli/client'
|
|
68
66
|
require_relative 'dalli/key_manager'
|
|
69
67
|
require_relative 'dalli/pipelined_getter'
|
|
@@ -72,7 +70,6 @@ require_relative 'dalli/pipelined_deleter'
|
|
|
72
70
|
require_relative 'dalli/ring'
|
|
73
71
|
require_relative 'dalli/protocol'
|
|
74
72
|
require_relative 'dalli/protocol/base'
|
|
75
|
-
require_relative 'dalli/protocol/binary'
|
|
76
73
|
require_relative 'dalli/protocol/connection_manager'
|
|
77
74
|
require_relative 'dalli/protocol/meta'
|
|
78
75
|
require_relative 'dalli/protocol/response_buffer'
|
data/lib/rack/session/dalli.rb
CHANGED
|
@@ -16,10 +16,11 @@ module Rack
|
|
|
16
16
|
attr_reader :data
|
|
17
17
|
|
|
18
18
|
# Don't freeze this until we fix the specs/implementation
|
|
19
|
-
# rubocop:disable
|
|
19
|
+
# rubocop:disable Style/MutableConstant
|
|
20
20
|
DEFAULT_DALLI_OPTIONS = {
|
|
21
21
|
namespace: 'rack:session'
|
|
22
22
|
}
|
|
23
|
+
# rubocop:enable Style/MutableConstant
|
|
23
24
|
|
|
24
25
|
# Brings in a new Rack::Session::Dalli middleware with the given
|
|
25
26
|
# `:memcache_server`. The server is either a hostname, or a
|
metadata
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dalli
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 5.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Peter M. Goldstein
|
|
8
8
|
- Mike Perham
|
|
9
|
-
autorequire:
|
|
10
9
|
bindir: bin
|
|
11
10
|
cert_chain: []
|
|
12
|
-
date:
|
|
11
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
13
12
|
dependencies:
|
|
14
13
|
- !ruby/object:Gem::Dependency
|
|
15
14
|
name: logger
|
|
@@ -42,7 +41,6 @@ files:
|
|
|
42
41
|
- lib/dalli/client.rb
|
|
43
42
|
- lib/dalli/compressor.rb
|
|
44
43
|
- lib/dalli/instrumentation.rb
|
|
45
|
-
- lib/dalli/json_serializer.rb
|
|
46
44
|
- lib/dalli/key_manager.rb
|
|
47
45
|
- lib/dalli/options.rb
|
|
48
46
|
- lib/dalli/pid_cache.rb
|
|
@@ -51,24 +49,18 @@ files:
|
|
|
51
49
|
- lib/dalli/pipelined_setter.rb
|
|
52
50
|
- lib/dalli/protocol.rb
|
|
53
51
|
- lib/dalli/protocol/base.rb
|
|
54
|
-
- lib/dalli/protocol/binary.rb
|
|
55
|
-
- lib/dalli/protocol/binary/request_formatter.rb
|
|
56
|
-
- lib/dalli/protocol/binary/response_header.rb
|
|
57
|
-
- lib/dalli/protocol/binary/response_processor.rb
|
|
58
|
-
- lib/dalli/protocol/binary/sasl_authentication.rb
|
|
59
52
|
- lib/dalli/protocol/connection_manager.rb
|
|
53
|
+
- lib/dalli/protocol/key_regularizer.rb
|
|
60
54
|
- lib/dalli/protocol/meta.rb
|
|
61
|
-
- lib/dalli/protocol/
|
|
62
|
-
- lib/dalli/protocol/meta/request_formatter.rb
|
|
63
|
-
- lib/dalli/protocol/meta/response_processor.rb
|
|
55
|
+
- lib/dalli/protocol/request_formatter.rb
|
|
64
56
|
- lib/dalli/protocol/response_buffer.rb
|
|
57
|
+
- lib/dalli/protocol/response_processor.rb
|
|
65
58
|
- lib/dalli/protocol/server_config_parser.rb
|
|
66
59
|
- lib/dalli/protocol/string_marshaller.rb
|
|
67
60
|
- lib/dalli/protocol/ttl_sanitizer.rb
|
|
68
61
|
- lib/dalli/protocol/value_compressor.rb
|
|
69
62
|
- lib/dalli/protocol/value_marshaller.rb
|
|
70
63
|
- lib/dalli/protocol/value_serializer.rb
|
|
71
|
-
- lib/dalli/protocol_deprecations.rb
|
|
72
64
|
- lib/dalli/ring.rb
|
|
73
65
|
- lib/dalli/servers_arg_normalizer.rb
|
|
74
66
|
- lib/dalli/socket.rb
|
|
@@ -79,9 +71,8 @@ licenses:
|
|
|
79
71
|
- MIT
|
|
80
72
|
metadata:
|
|
81
73
|
bug_tracker_uri: https://github.com/petergoldstein/dalli/issues
|
|
82
|
-
changelog_uri: https://github.com/petergoldstein/dalli/blob/
|
|
74
|
+
changelog_uri: https://github.com/petergoldstein/dalli/blob/main/CHANGELOG.md
|
|
83
75
|
rubygems_mfa_required: 'true'
|
|
84
|
-
post_install_message:
|
|
85
76
|
rdoc_options: []
|
|
86
77
|
require_paths:
|
|
87
78
|
- lib
|
|
@@ -89,15 +80,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
89
80
|
requirements:
|
|
90
81
|
- - ">="
|
|
91
82
|
- !ruby/object:Gem::Version
|
|
92
|
-
version: '3.
|
|
83
|
+
version: '3.3'
|
|
93
84
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
85
|
requirements:
|
|
95
86
|
- - ">="
|
|
96
87
|
- !ruby/object:Gem::Version
|
|
97
88
|
version: '0'
|
|
98
89
|
requirements: []
|
|
99
|
-
rubygems_version:
|
|
100
|
-
signing_key:
|
|
90
|
+
rubygems_version: 4.0.6
|
|
101
91
|
specification_version: 4
|
|
102
92
|
summary: High performance memcached client for Ruby
|
|
103
93
|
test_files: []
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'json'
|
|
4
|
-
|
|
5
|
-
module Dalli
|
|
6
|
-
##
|
|
7
|
-
# A serializer that stores values as JSON and never creates Ruby objects
|
|
8
|
-
# from what it reads.
|
|
9
|
-
#
|
|
10
|
-
# Passing the JSON module itself as the serializer (serializer: JSON) reads
|
|
11
|
-
# values back with JSON.load, which on json gem versions before 3.0 honors
|
|
12
|
-
# "json_class" and instantiates other classes when the json gem's additions
|
|
13
|
-
# are loaded. This serializer reads with JSON.parse, so a value written to
|
|
14
|
-
# memcached by someone else can only come back as plain hashes, arrays,
|
|
15
|
-
# strings, numbers, booleans and nil.
|
|
16
|
-
#
|
|
17
|
-
# Dalli::Client.new(servers, serializer: Dalli::JSONSerializer)
|
|
18
|
-
##
|
|
19
|
-
module JSONSerializer
|
|
20
|
-
def self.dump(value)
|
|
21
|
-
JSON.generate(value)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def self.load(data)
|
|
25
|
-
JSON.parse(data)
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Dalli
|
|
4
|
-
module Protocol
|
|
5
|
-
class Binary
|
|
6
|
-
##
|
|
7
|
-
# Class that encapsulates logic for formatting binary protocol requests
|
|
8
|
-
# to memcached.
|
|
9
|
-
##
|
|
10
|
-
class RequestFormatter
|
|
11
|
-
REQUEST = 0x80
|
|
12
|
-
|
|
13
|
-
OPCODES = {
|
|
14
|
-
get: 0x00,
|
|
15
|
-
set: 0x01,
|
|
16
|
-
add: 0x02,
|
|
17
|
-
replace: 0x03,
|
|
18
|
-
delete: 0x04,
|
|
19
|
-
incr: 0x05,
|
|
20
|
-
decr: 0x06,
|
|
21
|
-
flush: 0x08,
|
|
22
|
-
noop: 0x0A,
|
|
23
|
-
version: 0x0B,
|
|
24
|
-
getkq: 0x0D,
|
|
25
|
-
append: 0x0E,
|
|
26
|
-
prepend: 0x0F,
|
|
27
|
-
stat: 0x10,
|
|
28
|
-
setq: 0x11,
|
|
29
|
-
addq: 0x12,
|
|
30
|
-
replaceq: 0x13,
|
|
31
|
-
deleteq: 0x14,
|
|
32
|
-
incrq: 0x15,
|
|
33
|
-
decrq: 0x16,
|
|
34
|
-
flushq: 0x18,
|
|
35
|
-
appendq: 0x19,
|
|
36
|
-
prependq: 0x1A,
|
|
37
|
-
touch: 0x1C,
|
|
38
|
-
gat: 0x1D,
|
|
39
|
-
auth_negotiation: 0x20,
|
|
40
|
-
auth_request: 0x21,
|
|
41
|
-
auth_continue: 0x22
|
|
42
|
-
}.freeze
|
|
43
|
-
|
|
44
|
-
REQ_HEADER_FORMAT = 'CCnCCnNNQ'
|
|
45
|
-
|
|
46
|
-
KEY_ONLY = 'a*'
|
|
47
|
-
TTL_AND_KEY = 'Na*'
|
|
48
|
-
KEY_AND_VALUE = 'a*a*'
|
|
49
|
-
INCR_DECR = 'NNNNNa*'
|
|
50
|
-
TTL_ONLY = 'N'
|
|
51
|
-
NO_BODY = ''
|
|
52
|
-
|
|
53
|
-
BODY_FORMATS = {
|
|
54
|
-
get: KEY_ONLY,
|
|
55
|
-
getkq: KEY_ONLY,
|
|
56
|
-
delete: KEY_ONLY,
|
|
57
|
-
deleteq: KEY_ONLY,
|
|
58
|
-
stat: KEY_ONLY,
|
|
59
|
-
|
|
60
|
-
append: KEY_AND_VALUE,
|
|
61
|
-
prepend: KEY_AND_VALUE,
|
|
62
|
-
appendq: KEY_AND_VALUE,
|
|
63
|
-
prependq: KEY_AND_VALUE,
|
|
64
|
-
auth_request: KEY_AND_VALUE,
|
|
65
|
-
auth_continue: KEY_AND_VALUE,
|
|
66
|
-
|
|
67
|
-
set: 'NNa*a*',
|
|
68
|
-
setq: 'NNa*a*',
|
|
69
|
-
add: 'NNa*a*',
|
|
70
|
-
addq: 'NNa*a*',
|
|
71
|
-
replace: 'NNa*a*',
|
|
72
|
-
replaceq: 'NNa*a*',
|
|
73
|
-
|
|
74
|
-
incr: INCR_DECR,
|
|
75
|
-
decr: INCR_DECR,
|
|
76
|
-
incrq: INCR_DECR,
|
|
77
|
-
decrq: INCR_DECR,
|
|
78
|
-
|
|
79
|
-
flush: TTL_ONLY,
|
|
80
|
-
flushq: TTL_ONLY,
|
|
81
|
-
|
|
82
|
-
noop: NO_BODY,
|
|
83
|
-
auth_negotiation: NO_BODY,
|
|
84
|
-
version: NO_BODY,
|
|
85
|
-
|
|
86
|
-
touch: TTL_AND_KEY,
|
|
87
|
-
gat: TTL_AND_KEY
|
|
88
|
-
}.freeze
|
|
89
|
-
FORMAT = BODY_FORMATS.transform_values { |v| REQ_HEADER_FORMAT + v }
|
|
90
|
-
|
|
91
|
-
# rubocop:disable-next Metrics/ParameterLists
|
|
92
|
-
def self.standard_request(opkey:, key: nil, value: nil, opaque: 0, cas: 0, bitflags: nil, ttl: nil)
|
|
93
|
-
extra_len = (bitflags.nil? ? 0 : 4) + (ttl.nil? ? 0 : 4)
|
|
94
|
-
key_len = key.nil? ? 0 : key.bytesize
|
|
95
|
-
value_len = value.nil? ? 0 : value.bytesize
|
|
96
|
-
header = [REQUEST, OPCODES[opkey], key_len, extra_len, 0, 0, extra_len + key_len + value_len, opaque, cas]
|
|
97
|
-
body = [bitflags, ttl, key, value].compact
|
|
98
|
-
(header + body).pack(FORMAT[opkey])
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
def self.decr_incr_request(opkey:, key: nil, count: nil, initial: nil, expiry: nil)
|
|
102
|
-
extra_len = 20
|
|
103
|
-
(h, l) = as_8byte_uint(count)
|
|
104
|
-
(dh, dl) = as_8byte_uint(initial)
|
|
105
|
-
header = [REQUEST, OPCODES[opkey], key.bytesize, extra_len, 0, 0, key.bytesize + extra_len, 0, 0]
|
|
106
|
-
body = [h, l, dh, dl, expiry, key]
|
|
107
|
-
(header + body).pack(FORMAT[opkey])
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
def self.as_8byte_uint(val)
|
|
111
|
-
[val >> 32, val & 0xFFFFFFFF]
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
end
|
|
116
|
-
end
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Dalli
|
|
4
|
-
module Protocol
|
|
5
|
-
class Binary
|
|
6
|
-
##
|
|
7
|
-
# Class that encapsulates data parsed from a memcached response header.
|
|
8
|
-
##
|
|
9
|
-
class ResponseHeader
|
|
10
|
-
SIZE = 24
|
|
11
|
-
FMT = '@2nCCnNNQ'
|
|
12
|
-
|
|
13
|
-
attr_reader :key_len, :extra_len, :data_type, :status, :body_len, :opaque, :cas
|
|
14
|
-
|
|
15
|
-
def initialize(buf)
|
|
16
|
-
raise ArgumentError, "Response buffer must be at least #{SIZE} bytes" unless buf.bytesize >= SIZE
|
|
17
|
-
|
|
18
|
-
@key_len, @extra_len, @data_type, @status, @body_len, @opaque, @cas = buf.unpack(FMT)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def ok?
|
|
22
|
-
status.zero?
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def not_found?
|
|
26
|
-
status == 1
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
NOT_STORED_STATUSES = [2, 5].freeze
|
|
30
|
-
def not_stored?
|
|
31
|
-
NOT_STORED_STATUSES.include?(status)
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|