dalli 2.7.3 → 3.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/{History.md → CHANGELOG.md} +211 -0
- data/Gemfile +3 -6
- data/LICENSE +1 -1
- data/README.md +30 -208
- data/lib/dalli/cas/client.rb +2 -57
- data/lib/dalli/client.rb +254 -253
- data/lib/dalli/compressor.rb +13 -2
- data/lib/dalli/key_manager.rb +121 -0
- data/lib/dalli/options.rb +7 -7
- data/lib/dalli/pipelined_getter.rb +177 -0
- data/lib/dalli/protocol/base.rb +241 -0
- data/lib/dalli/protocol/binary/request_formatter.rb +117 -0
- data/lib/dalli/protocol/binary/response_header.rb +36 -0
- data/lib/dalli/protocol/binary/response_processor.rb +239 -0
- data/lib/dalli/protocol/binary/sasl_authentication.rb +60 -0
- data/lib/dalli/protocol/binary.rb +173 -0
- data/lib/dalli/protocol/connection_manager.rb +252 -0
- data/lib/dalli/protocol/meta/key_regularizer.rb +31 -0
- data/lib/dalli/protocol/meta/request_formatter.rb +121 -0
- data/lib/dalli/protocol/meta/response_processor.rb +211 -0
- data/lib/dalli/protocol/meta.rb +178 -0
- data/lib/dalli/protocol/response_buffer.rb +54 -0
- data/lib/dalli/protocol/server_config_parser.rb +86 -0
- data/lib/dalli/protocol/ttl_sanitizer.rb +45 -0
- data/lib/dalli/protocol/value_compressor.rb +85 -0
- data/lib/dalli/protocol/value_marshaller.rb +59 -0
- data/lib/dalli/protocol/value_serializer.rb +91 -0
- data/lib/dalli/protocol.rb +8 -0
- data/lib/dalli/ring.rb +97 -86
- data/lib/dalli/server.rb +4 -719
- data/lib/dalli/servers_arg_normalizer.rb +54 -0
- data/lib/dalli/socket.rb +123 -115
- data/lib/dalli/version.rb +5 -1
- data/lib/dalli.rb +45 -14
- data/lib/rack/session/dalli.rb +162 -42
- metadata +136 -63
- data/Performance.md +0 -42
- data/Rakefile +0 -43
- data/dalli.gemspec +0 -29
- data/lib/action_dispatch/middleware/session/dalli_store.rb +0 -81
- data/lib/active_support/cache/dalli_store.rb +0 -372
- data/lib/dalli/railtie.rb +0 -7
- data/test/benchmark_test.rb +0 -243
- data/test/helper.rb +0 -56
- data/test/memcached_mock.rb +0 -201
- data/test/sasl/memcached.conf +0 -1
- data/test/sasl/sasldb +0 -1
- data/test/test_active_support.rb +0 -541
- data/test/test_cas_client.rb +0 -107
- data/test/test_compressor.rb +0 -52
- data/test/test_dalli.rb +0 -682
- data/test/test_encoding.rb +0 -32
- data/test/test_failover.rb +0 -137
- data/test/test_network.rb +0 -64
- data/test/test_rack_session.rb +0 -341
- data/test/test_ring.rb +0 -85
- data/test/test_sasl.rb +0 -105
- data/test/test_serializer.rb +0 -29
- data/test/test_server.rb +0 -110
data/test/memcached_mock.rb
DELETED
@@ -1,201 +0,0 @@
|
|
1
|
-
require "socket"
|
2
|
-
require "tempfile"
|
3
|
-
|
4
|
-
$started = {}
|
5
|
-
|
6
|
-
module MemcachedMock
|
7
|
-
UNIX_SOCKET_PATH = (f = Tempfile.new('dalli_test'); f.close; f.path)
|
8
|
-
|
9
|
-
def self.start(port=19123)
|
10
|
-
server = TCPServer.new("localhost", port)
|
11
|
-
session = server.accept
|
12
|
-
yield(session)
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.start_unix(path=UNIX_SOCKET_PATH)
|
16
|
-
begin
|
17
|
-
File.delete(path)
|
18
|
-
rescue Errno::ENOENT
|
19
|
-
end
|
20
|
-
server = UNIXServer.new(path)
|
21
|
-
session = server.accept
|
22
|
-
yield(session)
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.delayed_start(port=19123, wait=1)
|
26
|
-
server = TCPServer.new("localhost", port)
|
27
|
-
sleep wait
|
28
|
-
yield(server)
|
29
|
-
end
|
30
|
-
|
31
|
-
module Helper
|
32
|
-
# Forks the current process and starts a new mock Memcached server on
|
33
|
-
# port 22122.
|
34
|
-
#
|
35
|
-
# memcached_mock(lambda {|sock| socket.write('123') }) do
|
36
|
-
# assert_equal "PONG", Dalli::Client.new('localhost:22122').get('abc')
|
37
|
-
# end
|
38
|
-
#
|
39
|
-
def memcached_mock(proc, meth=:start, meth_args=[])
|
40
|
-
return unless supports_fork?
|
41
|
-
begin
|
42
|
-
pid = fork do
|
43
|
-
trap("TERM") { exit }
|
44
|
-
|
45
|
-
MemcachedMock.send(meth, *meth_args) do |*args|
|
46
|
-
proc.call(*args)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
sleep 0.3 # Give time for the socket to start listening.
|
51
|
-
yield
|
52
|
-
ensure
|
53
|
-
if pid
|
54
|
-
Process.kill("TERM", pid)
|
55
|
-
Process.wait(pid)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
PATHS = %w(
|
61
|
-
/usr/local/bin/
|
62
|
-
/opt/local/bin/
|
63
|
-
/usr/bin/
|
64
|
-
)
|
65
|
-
|
66
|
-
def find_memcached
|
67
|
-
output = `memcached -h | head -1`.strip
|
68
|
-
if output && output =~ /^memcached (\d.\d.\d+)/ && $1 > '1.4'
|
69
|
-
return (puts "Found #{output} in PATH"; '')
|
70
|
-
end
|
71
|
-
PATHS.each do |path|
|
72
|
-
output = `memcached -h | head -1`.strip
|
73
|
-
if output && output =~ /^memcached (\d\.\d\.\d+)/ && $1 > '1.4'
|
74
|
-
return (puts "Found #{output} in #{path}"; path)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
raise Errno::ENOENT, "Unable to find memcached 1.4+ locally"
|
79
|
-
end
|
80
|
-
|
81
|
-
def memcached_persistent(port=21345)
|
82
|
-
dc = start_and_flush_with_retry(port, '', {})
|
83
|
-
yield dc, port if block_given?
|
84
|
-
end
|
85
|
-
|
86
|
-
def sasl_credentials
|
87
|
-
{ :username => 'testuser', :password => 'testtest' }
|
88
|
-
end
|
89
|
-
|
90
|
-
def sasl_env
|
91
|
-
{
|
92
|
-
'MEMCACHED_SASL_PWDB' => "#{File.dirname(__FILE__)}/sasl/sasldb",
|
93
|
-
'SASL_CONF_PATH' => "#{File.dirname(__FILE__)}/sasl/memcached.conf"
|
94
|
-
}
|
95
|
-
end
|
96
|
-
|
97
|
-
def memcached_sasl_persistent(port=21397)
|
98
|
-
dc = start_and_flush_with_retry(port, '-S', sasl_credentials)
|
99
|
-
yield dc, port if block_given?
|
100
|
-
end
|
101
|
-
|
102
|
-
def memcached_cas_persistent(port = 25662)
|
103
|
-
require 'dalli/cas/client'
|
104
|
-
dc = start_and_flush_with_retry(port)
|
105
|
-
yield dc, port if block_given?
|
106
|
-
end
|
107
|
-
|
108
|
-
|
109
|
-
def memcached_low_mem_persistent(port = 19128)
|
110
|
-
dc = start_and_flush_with_retry(port, '-m 1 -M')
|
111
|
-
yield dc, port if block_given?
|
112
|
-
end
|
113
|
-
|
114
|
-
def start_and_flush_with_retry(port, args = '', client_options = {})
|
115
|
-
dc = nil
|
116
|
-
retry_count = 0
|
117
|
-
while dc.nil? do
|
118
|
-
begin
|
119
|
-
dc = start_and_flush(port, args, client_options, (retry_count == 0))
|
120
|
-
rescue StandardError => e
|
121
|
-
$started[port] = nil
|
122
|
-
retry_count += 1
|
123
|
-
raise e if retry_count >= 3
|
124
|
-
end
|
125
|
-
end
|
126
|
-
dc
|
127
|
-
end
|
128
|
-
|
129
|
-
def start_and_flush(port, args = '', client_options = {}, flush = true)
|
130
|
-
memcached_server(port, args)
|
131
|
-
if "#{port}" =~ /\A\//
|
132
|
-
# unix socket
|
133
|
-
dc = Dalli::Client.new(port, client_options)
|
134
|
-
else
|
135
|
-
dc = Dalli::Client.new(["localhost:#{port}", "127.0.0.1:#{port}"], client_options)
|
136
|
-
end
|
137
|
-
dc.flush_all if flush
|
138
|
-
dc
|
139
|
-
end
|
140
|
-
|
141
|
-
def memcached(port, args='', client_options={})
|
142
|
-
dc = start_and_flush_with_retry(port, args, client_options)
|
143
|
-
yield dc, port if block_given?
|
144
|
-
memcached_kill(port)
|
145
|
-
end
|
146
|
-
|
147
|
-
def memcached_server(port, args='')
|
148
|
-
Memcached.path ||= find_memcached
|
149
|
-
if "#{port}" =~ /\A\//
|
150
|
-
# unix socket
|
151
|
-
port_socket_arg = '-s'
|
152
|
-
begin
|
153
|
-
File.delete(port)
|
154
|
-
rescue Errno::ENOENT
|
155
|
-
end
|
156
|
-
else
|
157
|
-
port_socket_arg = '-p'
|
158
|
-
port = port.to_i
|
159
|
-
end
|
160
|
-
|
161
|
-
cmd = "#{Memcached.path}memcached #{args} #{port_socket_arg} #{port}"
|
162
|
-
|
163
|
-
$started[port] ||= begin
|
164
|
-
pid = IO.popen(cmd).pid
|
165
|
-
at_exit do
|
166
|
-
begin
|
167
|
-
Process.kill("TERM", pid)
|
168
|
-
Process.wait(pid)
|
169
|
-
rescue Errno::ECHILD, Errno::ESRCH
|
170
|
-
end
|
171
|
-
end
|
172
|
-
wait_time = (args && args =~ /\-S/) ? 0.1 : 0.1
|
173
|
-
sleep wait_time
|
174
|
-
pid
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
def supports_fork?
|
179
|
-
!defined?(RUBY_ENGINE) || RUBY_ENGINE != 'jruby'
|
180
|
-
end
|
181
|
-
|
182
|
-
def memcached_kill(port)
|
183
|
-
pid = $started.delete(port)
|
184
|
-
if pid
|
185
|
-
begin
|
186
|
-
Process.kill("TERM", pid)
|
187
|
-
Process.wait(pid)
|
188
|
-
rescue Errno::ECHILD, Errno::ESRCH => e
|
189
|
-
puts e.inspect
|
190
|
-
end
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
module Memcached
|
198
|
-
class << self
|
199
|
-
attr_accessor :path
|
200
|
-
end
|
201
|
-
end
|
data/test/sasl/memcached.conf
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
mech_list: plain
|
data/test/sasl/sasldb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
testuser:testtest:::::::
|