diff options
author | Dominik Picheta <dominikpicheta@googlemail.com> | 2013-06-27 15:06:30 +0100 |
---|---|---|
committer | Dominik Picheta <dominikpicheta@googlemail.com> | 2013-06-27 15:06:30 +0100 |
commit | a9f2c3ffaf0959be03c290f9e72ed71495b156aa (patch) | |
tree | 805694fe2a43d23464e6a8274f4647ab7ae8d792 /lib/pure/redis.nim | |
parent | 3ff572ffcd9ec38bc4e7ba08f97a60053f59d838 (diff) | |
download | Nim-a9f2c3ffaf0959be03c290f9e72ed71495b156aa.tar.gz |
Fixed OSError + recvLine deprecation warnings.
Diffstat (limited to 'lib/pure/redis.nim')
-rw-r--r-- | lib/pure/redis.nim | 59 |
1 files changed, 26 insertions, 33 deletions
diff --git a/lib/pure/redis.nim b/lib/pure/redis.nim index bb6ea6768..8171dc12b 100644 --- a/lib/pure/redis.nim +++ b/lib/pure/redis.nim @@ -36,7 +36,7 @@ proc open*(host = "localhost", port = 6379.TPort): TRedis = ## Opens a connection to the redis server. result.socket = socket(buffered = false) if result.socket == InvalidSocket: - OSError() + OSError(OSLastError()) result.socket.connect(host, port) proc raiseInvalidReply(expected, got: char) = @@ -50,34 +50,31 @@ proc raiseNoOK(status: string) = proc parseStatus(r: TRedis): TRedisStatus = var line = "" - if r.socket.recvLine(line): - if line == "": - raise newException(ERedis, "Server closed connection prematurely") + r.socket.readLine(line) + if line == "": + raise newException(ERedis, "Server closed connection prematurely") + + if line[0] == '-': + raise newException(ERedis, strip(line)) + if line[0] != '+': + raiseInvalidReply('+', line[0]) - if line[0] == '-': - raise newException(ERedis, strip(line)) - if line[0] != '+': - raiseInvalidReply('+', line[0]) - - return line.substr(1) # Strip '+' - else: - OSError() + return line.substr(1) # Strip '+' proc parseInteger(r: TRedis): TRedisInteger = 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() + r.socket.readLine(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.") proc recv(sock: TSocket, size: int): TaintedString = result = newString(size).TaintedString @@ -86,8 +83,7 @@ proc recv(sock: TSocket, size: int): TaintedString = proc parseBulk(r: TRedis, allowMBNil = False): TRedisString = var line = "" - if not r.socket.recvLine(line.TaintedString): - raise newException(EInvalidReply, "recvLine failed") + r.socket.readLine(line.TaintedString) # Error. if line[0] == '-': @@ -110,8 +106,7 @@ proc parseBulk(r: TRedis, allowMBNil = False): TRedisString = proc parseMultiBulk(r: TRedis): TRedisList = var line = TaintedString"" - if not r.socket.recvLine(line): - raise newException(EInvalidReply, "recvLine failed") + r.socket.readLine(line) if line.string[0] != '*': raiseInvalidReply('*', line.string[0]) @@ -848,10 +843,8 @@ proc shutdown*(r: TRedis) = ## Synchronously save the dataset to disk and then shut down the server r.sendCommand("SHUTDOWN") var s = "".TaintedString - if r.socket.recvLine(s): - if s.string.len != 0: raise newException(ERedis, s.string) - else: - OSError() + r.socket.readLine(s) + if s.string.len != 0: raise newException(ERedis, s.string) proc slaveof*(r: TRedis, host: string, port: string) = ## Make the server a slave of another instance, or promote it as master |