diff options
author | Dominik Picheta <dominikpicheta@googlemail.com> | 2012-12-23 14:05:16 +0000 |
---|---|---|
committer | Dominik Picheta <dominikpicheta@googlemail.com> | 2012-12-23 14:05:16 +0000 |
commit | da609fc4454a8e57cbdd9d0415bb7fed1f7d1ce1 (patch) | |
tree | 9c99a32ed669e5b59bb32b37dca641f0cb6be58b /lib/pure/redis.nim | |
parent | 3cbac135465d63a320ff5fcdb5d3ba4ba89da4c8 (diff) | |
download | Nim-da609fc4454a8e57cbdd9d0415bb7fed1f7d1ce1.tar.gz |
Fixed many deprecation warnings. asyncio.recvLine now throws an
exception when an error occurs. Added sockets.SocketError.
Diffstat (limited to 'lib/pure/redis.nim')
-rwxr-xr-x | lib/pure/redis.nim | 50 |
1 files changed, 31 insertions, 19 deletions
diff --git a/lib/pure/redis.nim b/lib/pure/redis.nim index 921f9a3d8..bb6ea6768 100755 --- a/lib/pure/redis.nim +++ b/lib/pure/redis.nim @@ -49,26 +49,35 @@ proc raiseNoOK(status: string) = raise newException(EInvalidReply, "Expected \"OK\" got \"$1\"" % status) proc parseStatus(r: TRedis): TRedisStatus = - var line = r.socket.recv.string - - if line[0] == '-': - raise newException(ERedis, strip(line)) - if line[0] != '+': - raiseInvalidReply('+', line[0]) + var line = "" + if r.socket.recvLine(line): + if line == "": + raise newException(ERedis, "Server closed connection prematurely") - return line.substr(1, line.len-3) # Strip '+' and \c\L. + if line[0] == '-': + raise newException(ERedis, strip(line)) + if line[0] != '+': + raiseInvalidReply('+', line[0]) + + return line.substr(1) # Strip '+' + else: + OSError() proc parseInteger(r: TRedis): TRedisInteger = - var line = r.socket.recv.string - - if line[0] == '-': - raise newException(ERedis, strip(line)) - if line[0] != ':': - raiseInvalidReply(':', line[0]) - - # Strip ':' and \c\L. - if parseBiggestInt(line, result, 1) == 0: - raise newException(EInvalidReply, "Unable to parse integer.") + var line = "" + if r.socket.recvLine(line): + if line == "": + raise newException(ERedis, "Server closed connection prematurely") + + if line[0] == '-': + raise newException(ERedis, strip(line)) + if line[0] != ':': + raiseInvalidReply(':', line[0]) + + # Strip ':' + if parseBiggestInt(line, result, 1) == 0: + raise newException(EInvalidReply, "Unable to parse integer.") + else: OSError() proc recv(sock: TSocket, size: int): TaintedString = result = newString(size).TaintedString @@ -838,8 +847,11 @@ proc save*(r: TRedis) = proc shutdown*(r: TRedis) = ## Synchronously save the dataset to disk and then shut down the server r.sendCommand("SHUTDOWN") - var s = r.socket.recv() - if s.string.len != 0: raise newException(ERedis, s.string) + var s = "".TaintedString + if r.socket.recvLine(s): + if s.string.len != 0: raise newException(ERedis, s.string) + else: + OSError() proc slaveof*(r: TRedis, host: string, port: string) = ## Make the server a slave of another instance, or promote it as master |