Don't need ref string; use PPipeline instead of ref TPipeline
This commit is contained in:
parent
5da463e1f7
commit
9a728b15a2
1 changed files with 77 additions and 77 deletions
|
|
@ -20,16 +20,16 @@ const
|
|||
redisNil* = "\0\0"
|
||||
|
||||
type
|
||||
TPipeline = object
|
||||
PPipeline = ref object
|
||||
enabled: bool
|
||||
buffer: ref string
|
||||
buffer: string
|
||||
expected: int ## number of replies expected if pipelined
|
||||
|
||||
type
|
||||
TRedis* {.pure, final.} = object
|
||||
socket: TSocket
|
||||
connected: bool
|
||||
pipeline: ref TPipeline
|
||||
pipeline: PPipeline
|
||||
|
||||
TRedisStatus* = string
|
||||
TRedisInteger* = biggestInt
|
||||
|
|
@ -39,10 +39,9 @@ type
|
|||
EInvalidReply* = object of ESynch ## Invalid reply from redis
|
||||
ERedis* = object of ESynch ## Error in redis
|
||||
|
||||
proc newPipeline(): ref TPipeLine =
|
||||
proc newPipeline(): PPipeline =
|
||||
new(result)
|
||||
result.buffer = new string
|
||||
result.buffer[] = ""
|
||||
result.buffer = ""
|
||||
result.enabled = false
|
||||
result.expected = 0
|
||||
|
||||
|
|
@ -180,9 +179,9 @@ proc parseNext(r: TRedis): TRedisList =
|
|||
|
||||
proc flushPipeline*(r: TRedis, wasMulti = false): TRedisList =
|
||||
## Send buffered commands, clear buffer, return results
|
||||
if r.pipeline.buffer[].len > 0:
|
||||
r.socket.send(r.pipeline.buffer[])
|
||||
r.pipeline.buffer[] = ""
|
||||
if r.pipeline.buffer.len > 0:
|
||||
r.socket.send(r.pipeline.buffer)
|
||||
r.pipeline.buffer = ""
|
||||
|
||||
var prevState = r.pipeline.enabled
|
||||
r.pipeline.enabled = false
|
||||
|
|
@ -201,7 +200,7 @@ proc flushPipeline*(r: TRedis, wasMulti = false): TRedisList =
|
|||
r.pipeline.expected = 0
|
||||
r.pipeline.enabled = prevState
|
||||
|
||||
proc setPipeline*(r: TRedis, state: bool) =
|
||||
proc sePPipeline*(r: TRedis, state: bool) =
|
||||
## Enable or disable command pipelining (reduces network roundtrips).
|
||||
## Note that when enabled, you must call flushPipeline to actually send commands, except
|
||||
## for multi/exec() which enable and flush the pipeline automatically.
|
||||
|
|
@ -219,7 +218,7 @@ proc sendCommand(r: TRedis, cmd: string, args: varargs[string]) =
|
|||
request.add(i & "\c\L")
|
||||
|
||||
if r.pipeline.enabled:
|
||||
r.pipeline.buffer[].add(request)
|
||||
r.pipeline.buffer.add(request)
|
||||
r.pipeline.expected += 1
|
||||
else:
|
||||
r.socket.send(request)
|
||||
|
|
@ -237,7 +236,7 @@ proc sendCommand(r: TRedis, cmd: string, arg1: string,
|
|||
|
||||
if r.pipeline.enabled:
|
||||
r.pipeline.expected += 1
|
||||
r.pipeline.buffer[].add(request)
|
||||
r.pipeline.buffer.add(request)
|
||||
else:
|
||||
r.socket.send(request)
|
||||
|
||||
|
|
@ -830,9 +829,10 @@ proc exec*(r: TRedis): TRedisList =
|
|||
# between, then with the results
|
||||
return r.flushPipeline(true)
|
||||
|
||||
|
||||
proc multi*(r: TRedis) =
|
||||
## Mark the start of a transaction block
|
||||
r.setPipeline(true)
|
||||
r.sePPipeline(true)
|
||||
r.sendCommand("MULTI")
|
||||
raiseNoOK(r.parseStatus())
|
||||
|
||||
|
|
@ -1015,10 +1015,10 @@ when false:
|
|||
echo()
|
||||
echo("Testing with pipelining.")
|
||||
echo()
|
||||
r.setPipeline(true)
|
||||
r.sePPipeline(true)
|
||||
r.someTests()
|
||||
var list = r.flushPipeline()
|
||||
r.setPipeline(false)
|
||||
r.sePPipeline(false)
|
||||
echo("-- list length is " & $list.len & " --")
|
||||
for item in list:
|
||||
if not isNil(item):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue