Permalink
Browse files

more efficient reads

  • Loading branch information...
1 parent 2db7c35 commit d0763171ff42e042a08f44eab43b4682595cf531 Ezra Zygmuntowicz committed Feb 26, 2009
Showing with 12 additions and 3 deletions.
  1. +12 −3 redis.rb
View
@@ -23,8 +23,11 @@ def []=(key, val)
def [](key)
write "GET #{key}\r\n"
- if read_data != "nil"
- read_data
+ res = read_data
+ if res != "nil"
+ val = read(res.to_i)
+ nibble_end
+ val
else
nil
end
@@ -48,7 +51,9 @@ def keys(glob)
write "KEYS #{glob}\r\n"
res = read_data
if res
- read_data.split(" ")
+ keys = read(res.to_i).split(" ")
+ nibble_end
+ keys
end
end
@@ -98,6 +103,10 @@ def write(data)
end
end
+ def nibble_end
+ read(2)
+ end
+
def read_data
buff = ""
while (char = read(1))

0 comments on commit d076317

Please sign in to comment.