This commit is contained in:
Jason Livesay 2014-04-20 04:29:24 -07:00
commit d7caba8b65

View file

@ -25,6 +25,10 @@ type
buffer: string buffer: string
expected: int ## number of replies expected if pipelined expected: int ## number of replies expected if pipelined
type
TSendMode = enum
normal, pipelined, multiple
type type
TRedis* {.pure, final.} = object TRedis* {.pure, final.} = object
socket: TSocket socket: TSocket
@ -978,15 +982,14 @@ iterator hPairs*(r: TRedis, key: string): tuple[key, value: string] =
yield (k, i) yield (k, i)
k = "" k = ""
proc someTests(r: TRedis, how: string):seq[string] = proc someTests(r: TRedis, how: TSendMode):seq[string] =
var list:seq[string] = @[] var list:seq[string] = @[]
case how if how == pipelined:
of "pipelined":
r.startPipelining() r.startPipelining()
of "multi": elif how == multiple:
r.multi() r.multi()
r.setk("nim:test", "Testing something.") r.setk("nim:test", "Testing something.")
r.setk("nim:utf8", "こんにちは") r.setk("nim:utf8", "こんにちは")
r.setk("nim:esc", "\\ths ągt\\") r.setk("nim:esc", "\\ths ągt\\")
@ -1019,11 +1022,11 @@ proc someTests(r: TRedis, how: string):seq[string] =
list.add(r.echoServ("BLAH")) list.add(r.echoServ("BLAH"))
case how case how
of "normal": of normal:
return list return list
of "pipelined": of pipelined:
return r.flushPipeline() return r.flushPipeline()
of "multi": of multiple:
return r.exec() return r.exec()
proc assertListsIdentical(listA, listB: seq[string]) = proc assertListsIdentical(listA, listB: seq[string]) =
@ -1038,12 +1041,12 @@ when isMainModule:
var r = open() var r = open()
# Test with no pipelining # Test with no pipelining
var listNormal = r.someTests("normal") var listNormal = r.someTests(normal)
# Test with pipelining enabled # Test with pipelining enabled
var listPipelined = r.someTests("pipelined") var listPipelined = r.someTests(pipelined)
assertListsIdentical(listNormal, listPipelined) assertListsIdentical(listNormal, listPipelined)
# Test with multi/exec() (automatic pipelining) # Test with multi/exec() (automatic pipelining)
var listMulti = r.someTests("multi") var listMulti = r.someTests(multiple)
assertListsIdentical(listNormal, listMulti) assertListsIdentical(listNormal, listMulti)