Skip to content

Commit e9ab1eb

Browse files
authored
Fix set multi namespace on single server (#47)
* we aren't setting the namespace correctly on single server optimized set_multi. * fix private constant as rubocop warns
1 parent 2351639 commit e9ab1eb

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

lib/dalli/protocol/base.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def initialize(attribs, client_options = {})
2424
hostname, port, socket_type, @weight, user_creds = ServerConfigParser.parse(attribs)
2525
@options = client_options.merge(user_creds)
2626
@value_marshaller = ValueMarshaller.new(@options)
27+
@key_manager = KeyManager.new(@options)
2728
@connection_manager = ConnectionManager.new(hostname, port, socket_type, @options)
2829
end
2930

@@ -151,9 +152,10 @@ def quiet?
151152

152153
# NOTE: Additional public methods should be overridden in Dalli::Threadsafe
153154

155+
ALLOWED_QUIET_OPS = %i[add replace set delete incr decr append prepend flush noop].freeze
156+
154157
private
155158

156-
ALLOWED_QUIET_OPS = %i[add replace set delete incr decr append prepend flush noop].freeze
157159
def verify_allowed_quiet!(opkey)
158160
return if ALLOWED_QUIET_OPS.include?(opkey)
159161

lib/dalli/protocol/meta.rb

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ def write_multi_storage_req(_mode, pairs, ttl = nil, _cas = nil, options = {})
3131
pairs.each do |key, raw_value|
3232
(value, bitflags) = @value_marshaller.store(key, raw_value, options)
3333
encoded_key, _base64 = KeyRegularizer.encode(key)
34+
encoded_key = @key_manager.validate_key(encoded_key)
35+
3436
value_bytesize = value.bytesize
3537
# if last pair of hash, add TERMINATOR
3638

test/integration/test_operations.rb

+22
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,28 @@
3535
end
3636
end
3737

38+
it 'set_multi respects namespaces when using raw single server' do
39+
memcached_persistent do |_, port|
40+
dc = Dalli::Client.new("localhost:#{port}", namespace: 'some:namspace', raw: true)
41+
dc.close
42+
dc.flush
43+
44+
pairs = { 'paira' => 'vala', 'pairb' => 'valb', 'pairc' => 'valc' }
45+
dc.set_multi(pairs, 5)
46+
47+
assert_equal pairs, dc.get_multi(pairs.keys)
48+
end
49+
end
50+
51+
it 'set_multi respects namespaces on multiple servers' do
52+
memcached_persistent do |dc, _port|
53+
pairs = { 'paira' => 'vala', 'pairb' => 'valb', 'pairc' => 'valc' }
54+
dc.set_multi(pairs, 5)
55+
56+
assert_equal pairs, dc.get_multi(pairs.keys)
57+
end
58+
end
59+
3860
it 'return the value that include TERMINATOR on a hit' do
3961
memcached_persistent do |dc|
4062
dc.flush

0 commit comments

Comments
 (0)