lib/protocol/redis/connection.rb in protocol-redis-0.1.0 vs lib/protocol/redis/connection.rb in protocol-redis-0.2.0
- old
+ new
@@ -16,11 +16,11 @@
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
-require 'async/io/protocol/line'
+require_relative 'error'
module Protocol
module Redis
class Connection
CRLF = "\r\n".freeze
@@ -47,11 +47,11 @@
@stream.closed?
end
# The redis server doesn't want actual objects (e.g. integers) but only bulk strings. So, we inline it for performance.
def write_request(arguments)
- write_lines("*#{arguments.count}")
+ write_lines("*#{arguments.size}")
arguments.each do |argument|
string = argument.to_s
write_lines("$#{string.bytesize}", string)
@@ -79,10 +79,11 @@
return buffer
end
def read_object
- line = read_line
+ line = read_line or raise EOFError
+
token = line.slice!(0, 1)
case token
when '$'
length = line.to_i