Skip to content

Commit

Permalink
Return cas
Browse files Browse the repository at this point in the history
  • Loading branch information
grcooper committed Jan 7, 2025
1 parent 61943f6 commit 73798c1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
3 changes: 2 additions & 1 deletion lib/dalli/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ def get_multi(*keys, &)
pipelined_getter.process(keys, &)
else
{}.tap do |hash|
pipelined_getter.process(keys) { |k, data| hash[k] = data }
# Return Data.first to avoid returning the cas_id.
pipelined_getter.process(keys) { |k, data| hash[k] = data.first }
end
end
end
Expand Down
6 changes: 4 additions & 2 deletions lib/dalli/pipelined_getter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@ def abort_with_timeout(servers)

# Processes responses from a server. Returns true if there are no
# additional responses from this server.
#
# Yields key/value pairs. Value is an array: [value, cas_id]
def process_server(server)
server.pipelined_get_responses.each_pair do |key, value|
yield @key_manager.key_without_namespace(key), value
server.pipelined_get_responses.each_pair do |key, value_list|
yield @key_manager.key_without_namespace(key), value_list
end

!server.request_in_progress?
Expand Down
4 changes: 2 additions & 2 deletions lib/dalli/protocol/meta.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ def pipelined_get_responses
verify_pipelined_state
results = {}
loop do
key, value = response_processor.meta_get_pipelined_with_key_and_value
key, value_and_cas = response_processor.meta_get_pipelined_with_key_and_value_and_cas
# recieved a noop if key is nil
if key.nil?
@connection_manager.finish_request!
break
end

results[key] = value
results[key] = value_and_cas
# This is a bit of a hack. This is just checking if there is more data that has already been
# read from the socket. However, we don't actually know if there is more data to read because we could just
# have the header with the \r\n but no body. Instead, we probably should just be calling this method
Expand Down
10 changes: 8 additions & 2 deletions lib/dalli/protocol/meta/response_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,19 @@ def meta_get_without_value
tokens.first == EN ? nil : true
end

def meta_get_pipelined_with_key_and_value
def meta_get_pipelined_with_key_and_value_and_cas
tokens = error_on_unexpected!([VA, EN, HD, MN])
return [nil, nil] if tokens.first == MN
return [key_from_tokens(tokens), nil] if tokens.first == EN
return [key_from_tokens(tokens), true] unless tokens.first == VA

[key_from_tokens(tokens), @value_marshaller.retrieve(read_data(tokens[1].to_i), bitflags_from_tokens(tokens))]
[
key_from_tokens(tokens),
[
@value_marshaller.retrieve(read_data(tokens[1].to_i), bitflags_from_tokens(tokens)),
cas_from_tokens(tokens)
]
]
end

def meta_set_with_cas
Expand Down

0 comments on commit 73798c1

Please sign in to comment.