Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Server#multi_response_nonblock returns values as they are parsed

  • Loading branch information...
commit ec202d6969affec12f0677b1d9f65a2fe0f99c33 1 parent ca29d46
Aman Gupta authored
Showing with 18 additions and 12 deletions.
  1. +5 −4 lib/dalli/client.rb
  2. +13 −8 lib/dalli/server.rb
9 lib/dalli/client.rb
View
@@ -103,10 +103,11 @@ def get_multi(*keys)
server = sock.server
begin
- if ret = server.multi_response_nonblock
- ret.each do |key, value|
- values[key_without_namespace(key)] = value
- end
+ server.multi_response_nonblock.each do |key, value|
+ values[key_without_namespace(key)] = value
+ end
+
+ if server.multi_response_completed?
servers_in_use.delete(server)
end
rescue NetworkError => e
21 lib/dalli/server.rb
View
@@ -110,13 +110,17 @@ def compressor
def multi_response_start
write_noop
@multi_buffer = ''
- @multi_values = {}
@inprogress = true
end
+ def multi_response_completed?
+ @multi_buffer.nil?
+ end
+
def multi_response_nonblock
@multi_buffer << @sock.read_available
buf = @multi_buffer
+ values = {}
while buf.bytesize >= 24
header = buf.slice(0, 24)
@@ -124,10 +128,9 @@ def multi_response_nonblock
if key_length == 0
# all done!
- values = @multi_values
- @multi_buffer = @multi_values = nil
+ @multi_buffer = nil
@inprogress = false
- return values
+ break
elsif buf.bytesize >= (24 + body_length)
buf.slice!(0, 24)
@@ -136,21 +139,23 @@ def multi_response_nonblock
value = buf.slice!(0, body_length - key_length - 4) if body_length - key_length - 4 > 0
begin
- @multi_values[key] = deserialize(value, flags)
+ values[key] = deserialize(value, flags)
rescue DalliError => e
end
else
- # not enough data yet, keep waiting
- return nil
+ # not enough data yet, wait for more
+ break
end
end
+
+ values
rescue SystemCallError, Timeout::Error, EOFError
failure!
end
def multi_response_abort
- @multi_buffer = @multi_values = nil
+ @multi_buffer = nil
@inprogress = false
failure!
rescue NetworkError
Please sign in to comment.
Something went wrong with that request. Please try again.