dalli 2.0.1 → 3.2.8

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.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +671 -0
  3. data/Gemfile +15 -3
  4. data/LICENSE +1 -1
  5. data/README.md +33 -148
  6. data/lib/dalli/cas/client.rb +3 -0
  7. data/lib/dalli/client.rb +293 -131
  8. data/lib/dalli/compressor.rb +40 -0
  9. data/lib/dalli/key_manager.rb +121 -0
  10. data/lib/dalli/options.rb +22 -4
  11. data/lib/dalli/pid_cache.rb +40 -0
  12. data/lib/dalli/pipelined_getter.rb +177 -0
  13. data/lib/dalli/protocol/base.rb +250 -0
  14. data/lib/dalli/protocol/binary/request_formatter.rb +117 -0
  15. data/lib/dalli/protocol/binary/response_header.rb +36 -0
  16. data/lib/dalli/protocol/binary/response_processor.rb +239 -0
  17. data/lib/dalli/protocol/binary/sasl_authentication.rb +60 -0
  18. data/lib/dalli/protocol/binary.rb +173 -0
  19. data/lib/dalli/protocol/connection_manager.rb +255 -0
  20. data/lib/dalli/protocol/meta/key_regularizer.rb +31 -0
  21. data/lib/dalli/protocol/meta/request_formatter.rb +121 -0
  22. data/lib/dalli/protocol/meta/response_processor.rb +211 -0
  23. data/lib/dalli/protocol/meta.rb +178 -0
  24. data/lib/dalli/protocol/response_buffer.rb +54 -0
  25. data/lib/dalli/protocol/server_config_parser.rb +86 -0
  26. data/lib/dalli/protocol/ttl_sanitizer.rb +45 -0
  27. data/lib/dalli/protocol/value_compressor.rb +85 -0
  28. data/lib/dalli/protocol/value_marshaller.rb +59 -0
  29. data/lib/dalli/protocol/value_serializer.rb +91 -0
  30. data/lib/dalli/protocol.rb +19 -0
  31. data/lib/dalli/ring.rb +98 -50
  32. data/lib/dalli/server.rb +4 -524
  33. data/lib/dalli/servers_arg_normalizer.rb +54 -0
  34. data/lib/dalli/socket.rb +154 -53
  35. data/lib/dalli/version.rb +5 -1
  36. data/lib/dalli.rb +49 -13
  37. data/lib/rack/session/dalli.rb +169 -26
  38. metadata +53 -88
  39. data/History.md +0 -262
  40. data/Performance.md +0 -42
  41. data/Rakefile +0 -39
  42. data/dalli.gemspec +0 -28
  43. data/lib/action_dispatch/middleware/session/dalli_store.rb +0 -76
  44. data/lib/active_support/cache/dalli_store.rb +0 -203
  45. data/test/abstract_unit.rb +0 -281
  46. data/test/benchmark_test.rb +0 -187
  47. data/test/helper.rb +0 -41
  48. data/test/memcached_mock.rb +0 -113
  49. data/test/test_active_support.rb +0 -163
  50. data/test/test_dalli.rb +0 -461
  51. data/test/test_encoding.rb +0 -43
  52. data/test/test_failover.rb +0 -107
  53. data/test/test_network.rb +0 -54
  54. data/test/test_ring.rb +0 -85
  55. data/test/test_sasl.rb +0 -83
  56. data/test/test_session_store.rb +0 -224
@@ -1,113 +0,0 @@
1
- require "socket"
2
-
3
- $started = {}
4
-
5
- module MemcachedMock
6
- def self.start(port=19123, &block)
7
- server = TCPServer.new("localhost", port)
8
- session = server.accept
9
- block.call session
10
- end
11
-
12
- def self.delayed_start(port=19123, wait=1, &block)
13
- server = TCPServer.new("localhost", port)
14
- sleep wait
15
- block.call server
16
- end
17
-
18
- module Helper
19
- # Forks the current process and starts a new mock Memcached server on
20
- # port 22122.
21
- #
22
- # memcached_mock(lambda {|sock| socket.write('123') }) do
23
- # assert_equal "PONG", Dalli::Client.new('localhost:22122').get('abc')
24
- # end
25
- #
26
- def memcached_mock(proc, meth = :start)
27
- return unless supports_fork?
28
- begin
29
- pid = fork do
30
- trap("TERM") { exit }
31
-
32
- MemcachedMock.send(meth) do |*args|
33
- proc.call(*args)
34
- end
35
- end
36
-
37
- sleep 0.3 # Give time for the socket to start listening.
38
- yield
39
- ensure
40
- if pid
41
- Process.kill("TERM", pid)
42
- Process.wait(pid)
43
- end
44
- end
45
- end
46
-
47
- PATHS = %w(
48
- /usr/local/bin/
49
- /opt/local/bin/
50
- /usr/bin/
51
- )
52
-
53
- def find_memcached
54
- output = `memcached -h | head -1`.strip
55
- if output && output =~ /^memcached (\d.\d.\d+)/ && $1 > '1.4'
56
- return (puts "Found #{output} in PATH"; '')
57
- end
58
- PATHS.each do |path|
59
- output = `memcached -h | head -1`.strip
60
- if output && output =~ /^memcached (\d\.\d\.\d+)/ && $1 > '1.4'
61
- return (puts "Found #{output} in #{path}"; path)
62
- end
63
- end
64
-
65
- raise Errno::ENOENT, "Unable to find memcached 1.4+ locally"
66
- nil
67
- end
68
-
69
- def memcached(port=19122, args='', options={})
70
- Memcached.path ||= find_memcached
71
-
72
- cmd = "#{Memcached.path}memcached #{args} -p #{port}"
73
-
74
- $started[port] ||= begin
75
- #puts "Starting: #{cmd}..."
76
- pid = IO.popen(cmd).pid
77
- at_exit do
78
- begin
79
- Process.kill("TERM", pid)
80
- Process.wait(pid)
81
- File.delete(MemcachedMock.tmp_socket_path) if options[:unix]
82
- rescue Errno::ECHILD, Errno::ESRCH
83
- end
84
- end
85
- sleep 0.1
86
- pid
87
- end
88
- yield Dalli::Client.new(["localhost:#{port}", "127.0.0.1:#{port}"], options)
89
- end
90
-
91
- def supports_fork?
92
- !defined?(RUBY_ENGINE) || RUBY_ENGINE != 'jruby'
93
- end
94
-
95
- def memcached_kill(port)
96
- pid = $started.delete(port)
97
- if pid
98
- begin
99
- Process.kill("TERM", pid)
100
- Process.wait(pid)
101
- rescue Errno::ECHILD, Errno::ESRCH
102
- end
103
- end
104
- end
105
-
106
- end
107
- end
108
-
109
- module Memcached
110
- class << self
111
- attr_accessor :path
112
- end
113
- end
@@ -1,163 +0,0 @@
1
- # encoding: utf-8
2
- require 'helper'
3
-
4
- describe 'ActiveSupport' do
5
- context 'active_support caching' do
6
-
7
- should 'write should handle nil options' do
8
- @dalli = ActiveSupport::Cache.lookup_store(:dalli_store, 'localhost:19122')
9
- @dalli.write('foo', 'bar', nil)
10
- end
11
-
12
- should 'support fetch' do
13
- with_activesupport do
14
- memcached do
15
- connect
16
- dvalue = @dalli.fetch('someotherkeywithoutspaces', :expires_in => 1.second) { 123 }
17
- assert_equal 123, dvalue
18
-
19
- o = Object.new
20
- o.instance_variable_set :@foo, 'bar'
21
- dvalue = @dalli.fetch(rand_key, :raw => true) { o }
22
- assert_equal o, dvalue
23
-
24
- dvalue = @dalli.fetch(rand_key) { o }
25
- assert_equal o, dvalue
26
- end
27
- end
28
- end
29
-
30
- should 'support keys with spaces on Rails3' do
31
- with_activesupport do
32
- memcached do
33
- connect
34
- dvalue = @dalli.fetch('some key with spaces', :expires_in => 1.second) { 123 }
35
- assert_equal 123, dvalue
36
- end
37
- end
38
- end
39
-
40
- should 'support read_multi' do
41
- with_activesupport do
42
- memcached do
43
- connect
44
- x = rand_key
45
- y = rand_key
46
- assert_equal({}, @dalli.read_multi(x, y))
47
- @dalli.write(x, '123')
48
- @dalli.write(y, 123)
49
- assert_equal({ x => '123', y => 123 }, @dalli.read_multi(x, y))
50
- end
51
- end
52
- end
53
-
54
- should 'support read_multi with an array' do
55
- with_activesupport do
56
- memcached do
57
- connect
58
- x = rand_key
59
- y = rand_key
60
- assert_equal({}, @dalli.read_multi([x, y]))
61
- @dalli.write(x, '123')
62
- @dalli.write(y, 123)
63
- assert_equal({ x => '123', y => 123 }, @dalli.read_multi([x, y]))
64
- end
65
- end
66
- end
67
-
68
- should 'support raw read_multi' do
69
- with_activesupport do
70
- memcached do
71
- connect
72
- @dalli.write("abc", 5, :raw => true)
73
- @dalli.write("cba", 5, :raw => true)
74
- assert_equal({'abc' => '5', 'cba' => '5' }, @dalli.read_multi("abc", "cba"))
75
- end
76
- end
77
- end
78
-
79
- should 'support read, write and delete' do
80
- with_activesupport do
81
- memcached do
82
- connect
83
- x = rand_key
84
- y = rand_key
85
- assert_nil @dalli.read(y)
86
- dres = @dalli.write(y, 123)
87
- assert_equal true, dres
88
-
89
- dres = @dalli.read(y)
90
- assert_equal 123, dres
91
-
92
- dres = @dalli.delete(y)
93
- assert_equal true, dres
94
- end
95
- end
96
- end
97
-
98
- should 'support increment/decrement commands' do
99
- with_activesupport do
100
- memcached do
101
- connect
102
- assert_equal true, @dalli.write('counter', 0, :raw => true)
103
- assert_equal 1, @dalli.increment('counter')
104
- assert_equal 2, @dalli.increment('counter')
105
- assert_equal 1, @dalli.decrement('counter')
106
- assert_equal "1", @dalli.read('counter', :raw => true)
107
-
108
- assert_equal 1, @dalli.increment('counterX')
109
- assert_equal 2, @dalli.increment('counterX')
110
- assert_equal 2, @dalli.read('counterX', :raw => true).to_i
111
- end
112
- end
113
- end
114
-
115
- should 'support other esoteric commands' do
116
- with_activesupport do
117
- memcached do
118
- connect
119
- ds = @dalli.stats
120
- assert_equal 1, ds.keys.size
121
- assert ds[ds.keys.first].keys.size > 0
122
-
123
- assert_equal true, @dalli.write(:foo, 'a')
124
- assert_equal true, @dalli.exist?(:foo)
125
- assert_equal false, @dalli.exist?(:bar)
126
-
127
- @dalli.reset
128
- end
129
- end
130
- end
131
- end
132
-
133
- should 'handle crazy characters from far-away lands' do
134
- with_activesupport do
135
- memcached do
136
- connect
137
- key = "fooƒ"
138
- value = 'bafƒ'
139
- assert_equal true, @dalli.write(key, value)
140
- assert_equal value, @dalli.read(key)
141
- end
142
- end
143
- end
144
-
145
- should 'normalize options as expected' do
146
- with_activesupport do
147
- memcached do
148
- @dalli = ActiveSupport::Cache::DalliStore.new('localhost:19122', :expires_in => 1, :namespace => 'foo', :compress => true)
149
- assert_equal 1, @dalli.instance_variable_get(:@data).instance_variable_get(:@options)[:expires_in]
150
- assert_equal 'foo', @dalli.instance_variable_get(:@data).instance_variable_get(:@options)[:namespace]
151
- end
152
- end
153
- end
154
-
155
- def connect
156
- @dalli = ActiveSupport::Cache.lookup_store(:dalli_store, 'localhost:19122', :expires_in => 10.seconds, :namespace => 'x')
157
- @dalli.clear
158
- end
159
-
160
- def rand_key
161
- rand(1_000_000_000)
162
- end
163
- end