dalli 1.1.5 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of dalli might be problematic. Click here for more details.

@@ -1,52 +0,0 @@
1
- class Dalli::Client
2
-
3
- module MemcacheClientCompatibility
4
-
5
- def initialize(*args)
6
- Dalli.logger.error("Starting Dalli in memcache-client compatibility mode")
7
- super(*args)
8
- end
9
-
10
- def set(key, value, ttl = nil, options = nil)
11
- if options == true || options == false
12
- Dalli.logger.error("Dalli: please use set(key, value, ttl, :raw => boolean): #{caller[0]}")
13
- options = { :raw => options }
14
- end
15
- super(key, value, ttl, options) ? "STORED\r\n" : "NOT_STORED\r\n"
16
-
17
- end
18
-
19
- def add(key, value, ttl = nil, options = nil)
20
- if options == true || options == false
21
- Dalli.logger.error("Dalli: please use add(key, value, ttl, :raw => boolean): #{caller[0]}")
22
- options = { :raw => options }
23
- end
24
- super(key, value, ttl, options) ? "STORED\r\n" : "NOT_STORED\r\n"
25
- end
26
-
27
- def replace(key, value, ttl = nil, options = nil)
28
- if options == true || options == false
29
- Dalli.logger.error("Dalli: please use replace(key, value, ttl, :raw => boolean): #{caller[0]}")
30
- options = { :raw => options }
31
- end
32
- super(key, value, ttl, options) ? "STORED\r\n" : "NOT_STORED\r\n"
33
- end
34
-
35
- # Dalli does not unmarshall data that does not have the marshalled flag set so we need
36
- # to unmarshall manually any marshalled data originally put in memcached by memcache-client.
37
- # Peek at the data and see if it looks marshalled.
38
- def get(key, options = nil)
39
- value = super(key, options)
40
- if value && value.is_a?(String) && !options && value.size > 2 &&
41
- (bytes = value.unpack('cc')) && bytes[0] == 4 && bytes[1] == 8
42
- return Marshal.load(value) rescue value
43
- end
44
- value
45
- end
46
-
47
- def delete(key)
48
- super(key) ? "DELETED\r\n" : "NOT_DELETED\r\n"
49
- end
50
- end
51
-
52
- end
@@ -1 +0,0 @@
1
- Dalli::Client.compatibility_mode = true
@@ -1,33 +0,0 @@
1
- require 'helper'
2
-
3
- describe 'Compatibility' do
4
-
5
- before do
6
- require 'dalli/memcache-client'
7
- end
8
-
9
- context 'dalli in memcache-client mode' do
10
-
11
- should 'handle old raw flag to set/add/replace' do
12
- memcached do |dc|
13
- assert_equal "STORED\r\n", dc.set('abc', 123, 5, true)
14
- assert_equal '123', dc.get('abc', true)
15
-
16
- assert_equal "NOT_STORED\r\n", dc.add('abc', 456, 5, true)
17
- assert_equal '123', dc.get('abc', true)
18
-
19
- assert_equal "STORED\r\n", dc.replace('abc', 456, 5, false)
20
- assert_equal 456, dc.get('abc', false)
21
-
22
- assert_equal "DELETED\r\n", dc.delete('abc')
23
- assert_equal "NOT_DELETED\r\n", dc.delete('abc')
24
- end
25
- end
26
-
27
- end
28
-
29
- after do
30
- Dalli::Client.compatibility_mode = false
31
- end
32
-
33
- end
@@ -1,175 +0,0 @@
1
- require 'helper'
2
- require 'memcached_mock'
3
- if defined?(RUBY_ENGINE) && RUBY_ENGINE != 'jruby'
4
- begin
5
- require 'em-spec/test'
6
-
7
- describe 'Synchrony' do
8
- include EM::TestHelper
9
-
10
- context 'using a live server' do
11
-
12
- should "support get/set" do
13
- em do
14
- memcached(19122,'',:async => true) do |dc|
15
- dc.flush
16
-
17
- val1 = "1234567890"*105000
18
- assert_error Dalli::DalliError, /too large/ do
19
- dc.set('a', val1)
20
- val2 = dc.get('a')
21
- assert_equal val1, val2
22
- end
23
-
24
- val1 = "1234567890"*100000
25
- dc.set('a', val1)
26
- val2 = dc.get('a')
27
- assert_equal val1, val2
28
-
29
- assert_equal true, dc.set('a', nil)
30
- assert_nil dc.get('a')
31
-
32
- done
33
- end
34
- end
35
- end
36
-
37
- should "support the fetch operation" do
38
- em do
39
- memcached(19122,'',:async => true) do |dc|
40
- dc.flush
41
-
42
- expected = { 'blah' => 'blerg!' }
43
- executed = false
44
- value = dc.fetch('fetch_key') do
45
- executed = true
46
- expected
47
- end
48
- assert_equal expected, value
49
- assert_equal true, executed
50
-
51
- executed = false
52
- value = dc.fetch('fetch_key') do
53
- executed = true
54
- expected
55
- end
56
- assert_equal expected, value
57
- assert_equal false, executed
58
-
59
- done
60
- end
61
- end
62
- end
63
-
64
- should "support multi-get" do
65
- em do
66
- memcached(19122,'',:async => true) do |dc|
67
- dc.close
68
- dc.flush
69
- resp = dc.get_multi(%w(a b c d e f))
70
- assert_equal({}, resp)
71
-
72
- dc.set('a', 'foo')
73
- dc.set('b', 123)
74
- dc.set('c', %w(a b c))
75
- resp = dc.get_multi(%w(a b c d e f))
76
- assert_equal({ 'a' => 'foo', 'b' => 123, 'c' => %w(a b c) }, resp)
77
-
78
- # Perform a huge multi-get with 10,000 elements.
79
- arr = []
80
- dc.multi do
81
- 10_000.times do |idx|
82
- dc.set idx, idx
83
- arr << idx
84
- end
85
- end
86
-
87
- result = dc.get_multi(arr)
88
- assert_equal(10_000, result.size)
89
- assert_equal(1000, result['1000'])
90
-
91
- done
92
- end
93
- end
94
- end
95
-
96
- should "pass a simple smoke test" do
97
- em do
98
- memcached(19122,'',:async => true) do |dc|
99
- resp = dc.flush
100
- assert_not_nil resp
101
- assert_equal [true, true], resp
102
-
103
- assert_equal true, dc.set(:foo, 'bar')
104
- assert_equal 'bar', dc.get(:foo)
105
-
106
- resp = dc.get('123')
107
- assert_equal nil, resp
108
-
109
- resp = dc.set('123', 'xyz')
110
- assert_equal true, resp
111
-
112
- resp = dc.get('123')
113
- assert_equal 'xyz', resp
114
-
115
- resp = dc.set('123', 'abc')
116
- assert_equal true, resp
117
-
118
- dc.prepend('123', '0')
119
- dc.append('123', '0')
120
-
121
- assert_raises Dalli::DalliError do
122
- resp = dc.get('123')
123
- end
124
-
125
- dc.close
126
- dc = nil
127
-
128
- dc = Dalli::Client.new('localhost:19122', :async => true)
129
-
130
- resp = dc.set('456', 'xyz', 0, :raw => true)
131
- assert_equal true, resp
132
-
133
- resp = dc.prepend '456', '0'
134
- assert_equal true, resp
135
-
136
- resp = dc.append '456', '9'
137
- assert_equal true, resp
138
-
139
- resp = dc.get('456', :raw => true)
140
- assert_equal '0xyz9', resp
141
-
142
- resp = dc.stats
143
- assert_equal Hash, resp.class
144
-
145
- dc.close
146
-
147
- done
148
- end
149
- end
150
- end
151
-
152
- context 'with compression' do
153
- should 'allow large values' do
154
- em do
155
- memcached(19122,'',:async => true) do |dc|
156
- dalli = Dalli::Client.new(dc.instance_variable_get(:@servers), :compression => true, :async => true)
157
-
158
- value = "0"*1024*1024
159
- assert_raises Dalli::DalliError, /too large/ do
160
- dc.set('verylarge', value)
161
- end
162
- dalli.set('verylarge', value)
163
- end
164
-
165
- done
166
- end
167
- end
168
- end
169
-
170
- end
171
- end
172
- rescue LoadError
173
- puts "Skipping em-synchrony tests"
174
- end
175
- end