Allow multi/exec replies so transactions work.
This commit is contained in:
parent
033f2bbbf2
commit
8d1c4a23de
1 changed files with 13 additions and 2 deletions
|
|
@ -45,7 +45,7 @@ proc raiseInvalidReply(expected, got: char) =
|
||||||
[$expected, $got])
|
[$expected, $got])
|
||||||
|
|
||||||
proc raiseNoOK(status: string) =
|
proc raiseNoOK(status: string) =
|
||||||
if status != "OK":
|
if status != "QUEUED" and status != "OK":
|
||||||
raise newException(EInvalidReply, "Expected \"OK\" got \"$1\"" % status)
|
raise newException(EInvalidReply, "Expected \"OK\" got \"$1\"" % status)
|
||||||
|
|
||||||
proc parseStatus(r: TRedis): TRedisStatus =
|
proc parseStatus(r: TRedis): TRedisStatus =
|
||||||
|
|
@ -64,6 +64,10 @@ proc parseStatus(r: TRedis): TRedisStatus =
|
||||||
proc parseInteger(r: TRedis): TRedisInteger =
|
proc parseInteger(r: TRedis): TRedisInteger =
|
||||||
var line = ""
|
var line = ""
|
||||||
r.socket.readLine(line)
|
r.socket.readLine(line)
|
||||||
|
|
||||||
|
if line == "+QUEUED": # inside of multi
|
||||||
|
return -1
|
||||||
|
|
||||||
if line == "":
|
if line == "":
|
||||||
raise newException(ERedis, "Server closed connection prematurely")
|
raise newException(ERedis, "Server closed connection prematurely")
|
||||||
|
|
||||||
|
|
@ -85,6 +89,9 @@ proc parseBulk(r: TRedis, allowMBNil = False): TRedisString =
|
||||||
var line = ""
|
var line = ""
|
||||||
r.socket.readLine(line.TaintedString)
|
r.socket.readLine(line.TaintedString)
|
||||||
|
|
||||||
|
if line == "+QUEUED" or line == "+OK": # inside of a transaction (multi)
|
||||||
|
return nil
|
||||||
|
|
||||||
# Error.
|
# Error.
|
||||||
if line[0] == '-':
|
if line[0] == '-':
|
||||||
raise newException(ERedis, strip(line))
|
raise newException(ERedis, strip(line))
|
||||||
|
|
@ -108,6 +115,9 @@ proc parseMultiBulk(r: TRedis): TRedisList =
|
||||||
var line = TaintedString""
|
var line = TaintedString""
|
||||||
r.socket.readLine(line)
|
r.socket.readLine(line)
|
||||||
|
|
||||||
|
if line == "+QUEUED": # inside of a transaction (multi)
|
||||||
|
return nil
|
||||||
|
|
||||||
if line.string[0] != '*':
|
if line.string[0] != '*':
|
||||||
raiseInvalidReply('*', line.string[0])
|
raiseInvalidReply('*', line.string[0])
|
||||||
|
|
||||||
|
|
@ -722,6 +732,7 @@ proc discardMulti*(r: TRedis) =
|
||||||
proc exec*(r: TRedis): TRedisList =
|
proc exec*(r: TRedis): TRedisList =
|
||||||
## Execute all commands issued after MULTI
|
## Execute all commands issued after MULTI
|
||||||
r.sendCommand("EXEC")
|
r.sendCommand("EXEC")
|
||||||
|
|
||||||
return r.parseMultiBulk()
|
return r.parseMultiBulk()
|
||||||
|
|
||||||
proc multi*(r: TRedis) =
|
proc multi*(r: TRedis) =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue