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/test_sasl.rb
DELETED
@@ -1,105 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe 'Sasl' do
|
4
|
-
|
5
|
-
# https://github.com/seattlerb/minitest/issues/298
|
6
|
-
def self.xit(msg, &block)
|
7
|
-
end
|
8
|
-
|
9
|
-
describe 'a server requiring authentication' do
|
10
|
-
before do
|
11
|
-
@server = mock()
|
12
|
-
@server.stubs(:request).returns(true)
|
13
|
-
@server.stubs(:weight).returns(1)
|
14
|
-
@server.stubs(:name).returns("localhost:19124")
|
15
|
-
end
|
16
|
-
|
17
|
-
describe 'without authentication credentials' do
|
18
|
-
before do
|
19
|
-
ENV['MEMCACHE_USERNAME'] = 'foo'
|
20
|
-
ENV['MEMCACHE_PASSWORD'] = 'wrongpwd'
|
21
|
-
end
|
22
|
-
|
23
|
-
after do
|
24
|
-
ENV['MEMCACHE_USERNAME'] = nil
|
25
|
-
ENV['MEMCACHE_PASSWORD'] = nil
|
26
|
-
end
|
27
|
-
|
28
|
-
xit 'gracefully handle authentication failures' do
|
29
|
-
memcached_sasl_persistent do |dc|
|
30
|
-
assert_error Dalli::DalliError, /32/ do
|
31
|
-
dc.set('abc', 123)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
xit 'fail SASL authentication with wrong options' do
|
38
|
-
memcached_sasl_persistent do |dc, port|
|
39
|
-
dc = Dalli::Client.new("localhost:#{port}", :username => 'testuser', :password => 'testtest')
|
40
|
-
assert_error Dalli::DalliError, /32/ do
|
41
|
-
dc.set('abc', 123)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
# OSX: Create a SASL user for the memcached application like so:
|
47
|
-
#
|
48
|
-
# saslpasswd2 -a memcached -c testuser
|
49
|
-
#
|
50
|
-
# with password 'testtest'
|
51
|
-
describe 'in an authenticated environment' do
|
52
|
-
before do
|
53
|
-
ENV['MEMCACHE_USERNAME'] = 'testuser'
|
54
|
-
ENV['MEMCACHE_PASSWORD'] = 'testtest'
|
55
|
-
end
|
56
|
-
|
57
|
-
after do
|
58
|
-
ENV['MEMCACHE_USERNAME'] = nil
|
59
|
-
ENV['MEMCACHE_PASSWORD'] = nil
|
60
|
-
end
|
61
|
-
|
62
|
-
xit 'pass SASL authentication' do
|
63
|
-
memcached_sasl_persistent do |dc|
|
64
|
-
# I get "Dalli::DalliError: Error authenticating: 32" in OSX
|
65
|
-
# but SASL works on Heroku servers. YMMV.
|
66
|
-
assert_equal true, dc.set('abc', 123)
|
67
|
-
assert_equal 123, dc.get('abc')
|
68
|
-
results = dc.stats
|
69
|
-
assert_equal 1, results.size
|
70
|
-
assert_equal 38, results.values.first.size
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
xit 'pass SASL authentication with options' do
|
76
|
-
memcached_sasl_persistent do |dc, port|
|
77
|
-
dc = Dalli::Client.new("localhost:#{port}", sasl_credentials)
|
78
|
-
# I get "Dalli::DalliError: Error authenticating: 32" in OSX
|
79
|
-
# but SASL works on Heroku servers. YMMV.
|
80
|
-
assert_equal true, dc.set('abc', 123)
|
81
|
-
assert_equal 123, dc.get('abc')
|
82
|
-
results = dc.stats
|
83
|
-
assert_equal 1, results.size
|
84
|
-
assert_equal 38, results.values.first.size
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
it 'pass SASL as URI' do
|
89
|
-
Dalli::Server.expects(:new).with("localhost:19124",
|
90
|
-
:username => "testuser", :password => "testtest").returns(@server)
|
91
|
-
dc = Dalli::Client.new('memcached://testuser:testtest@localhost:19124')
|
92
|
-
dc.flush_all
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'pass SASL as ring of URIs' do
|
96
|
-
Dalli::Server.expects(:new).with("localhost:19124",
|
97
|
-
:username => "testuser", :password => "testtest").returns(@server)
|
98
|
-
Dalli::Server.expects(:new).with("otherhost:19125",
|
99
|
-
:username => "testuser2", :password => "testtest2").returns(@server)
|
100
|
-
dc = Dalli::Client.new(['memcached://testuser:testtest@localhost:19124',
|
101
|
-
'memcached://testuser2:testtest2@otherhost:19125'])
|
102
|
-
dc.flush_all
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
data/test/test_serializer.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'helper'
|
3
|
-
require 'json'
|
4
|
-
require 'memcached_mock'
|
5
|
-
|
6
|
-
describe 'Serializer' do
|
7
|
-
|
8
|
-
it 'default to Marshal' do
|
9
|
-
memcached(29198) do |dc|
|
10
|
-
dc.set 1,2
|
11
|
-
assert_equal Marshal, dc.instance_variable_get('@ring').servers.first.serializer
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'support a custom serializer' do
|
16
|
-
memcached(29198) do |dc, port|
|
17
|
-
memcache = Dalli::Client.new("127.0.0.1:#{port}", :serializer => JSON)
|
18
|
-
memcache.set 1,2
|
19
|
-
begin
|
20
|
-
assert_equal JSON, memcache.instance_variable_get('@ring').servers.first.serializer
|
21
|
-
|
22
|
-
memcached(21956) do |newdc|
|
23
|
-
assert newdc.set("json_test", {"foo" => "bar"})
|
24
|
-
assert_equal({"foo" => "bar"}, newdc.get("json_test"))
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
data/test/test_server.rb
DELETED
@@ -1,110 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe Dalli::Server do
|
4
|
-
describe 'hostname parsing' do
|
5
|
-
it 'handles unix socket with no weight' do
|
6
|
-
s = Dalli::Server.new('/var/run/memcached/sock')
|
7
|
-
assert_equal '/var/run/memcached/sock', s.hostname
|
8
|
-
assert_equal 1, s.weight
|
9
|
-
assert_equal :unix, s.socket_type
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'handles unix socket with a weight' do
|
13
|
-
s = Dalli::Server.new('/var/run/memcached/sock:2')
|
14
|
-
assert_equal '/var/run/memcached/sock', s.hostname
|
15
|
-
assert_equal 2, s.weight
|
16
|
-
assert_equal :unix, s.socket_type
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'handles no port or weight' do
|
20
|
-
s = Dalli::Server.new('localhost')
|
21
|
-
assert_equal 'localhost', s.hostname
|
22
|
-
assert_equal 11211, s.port
|
23
|
-
assert_equal 1, s.weight
|
24
|
-
assert_equal :tcp, s.socket_type
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'handles a port, but no weight' do
|
28
|
-
s = Dalli::Server.new('localhost:11212')
|
29
|
-
assert_equal 'localhost', s.hostname
|
30
|
-
assert_equal 11212, s.port
|
31
|
-
assert_equal 1, s.weight
|
32
|
-
assert_equal :tcp, s.socket_type
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'handles a port and a weight' do
|
36
|
-
s = Dalli::Server.new('localhost:11212:2')
|
37
|
-
assert_equal 'localhost', s.hostname
|
38
|
-
assert_equal 11212, s.port
|
39
|
-
assert_equal 2, s.weight
|
40
|
-
assert_equal :tcp, s.socket_type
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'handles ipv4 addresses' do
|
44
|
-
s = Dalli::Server.new('127.0.0.1')
|
45
|
-
assert_equal '127.0.0.1', s.hostname
|
46
|
-
assert_equal 11211, s.port
|
47
|
-
assert_equal 1, s.weight
|
48
|
-
assert_equal :tcp, s.socket_type
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'handles ipv6 addresses' do
|
52
|
-
s = Dalli::Server.new('[::1]')
|
53
|
-
assert_equal '::1', s.hostname
|
54
|
-
assert_equal 11211, s.port
|
55
|
-
assert_equal 1, s.weight
|
56
|
-
assert_equal :tcp, s.socket_type
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'handles ipv6 addresses with port' do
|
60
|
-
s = Dalli::Server.new('[::1]:11212')
|
61
|
-
assert_equal '::1', s.hostname
|
62
|
-
assert_equal 11212, s.port
|
63
|
-
assert_equal 1, s.weight
|
64
|
-
assert_equal :tcp, s.socket_type
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'handles ipv6 addresses with port and weight' do
|
68
|
-
s = Dalli::Server.new('[::1]:11212:2')
|
69
|
-
assert_equal '::1', s.hostname
|
70
|
-
assert_equal 11212, s.port
|
71
|
-
assert_equal 2, s.weight
|
72
|
-
assert_equal :tcp, s.socket_type
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'handles a FQDN' do
|
76
|
-
s = Dalli::Server.new('my.fqdn.com')
|
77
|
-
assert_equal 'my.fqdn.com', s.hostname
|
78
|
-
assert_equal 11211, s.port
|
79
|
-
assert_equal 1, s.weight
|
80
|
-
assert_equal :tcp, s.socket_type
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'handles a FQDN with port and weight' do
|
84
|
-
s = Dalli::Server.new('my.fqdn.com:11212:2')
|
85
|
-
assert_equal 'my.fqdn.com', s.hostname
|
86
|
-
assert_equal 11212, s.port
|
87
|
-
assert_equal 2, s.weight
|
88
|
-
assert_equal :tcp, s.socket_type
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'throws an exception if the hostname cannot be parsed' do
|
92
|
-
lambda { Dalli::Server.new('[]') }.must_raise Dalli::DalliError
|
93
|
-
lambda { Dalli::Server.new('my.fqdn.com:') }.must_raise Dalli::DalliError
|
94
|
-
lambda { Dalli::Server.new('my.fqdn.com:11212,:2') }.must_raise Dalli::DalliError
|
95
|
-
lambda { Dalli::Server.new('my.fqdn.com:11212:abc') }.must_raise Dalli::DalliError
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
describe 'ttl translation' do
|
100
|
-
it 'does not translate ttls under 30 days' do
|
101
|
-
s = Dalli::Server.new('localhost')
|
102
|
-
assert_equal s.send(:sanitize_ttl, 30*24*60*60), 30*24*60*60
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'translates ttls over 30 days into timestamps' do
|
106
|
-
s = Dalli::Server.new('localhost')
|
107
|
-
assert_equal s.send(:sanitize_ttl, 30*24*60*60 + 1), Time.now.to_i + 30*24*60*60+1
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|