summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorJason Livesay <ithkuil@gmail.com>2014-04-20 04:29:24 -0700
committerJason Livesay <ithkuil@gmail.com>2014-04-20 04:29:24 -0700
commitd7caba8b6510560930e76230624b7ff62f1cb15f (patch)
tree5947f3e7fb0a122ca94b82b6417b4bc7bae67bd9 /lib
parent7584d867e1740db3f95d0138c64baa89602efc91 (diff)
downloadNim-d7caba8b6510560930e76230624b7ff62f1cb15f.tar.gz
Use enum
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/redis.nim25
1 files changed, 14 insertions, 11 deletions
diff --git a/lib/pure/redis.nim b/lib/pure/redis.nim
index ae61a2b68..959f5c6ef 100644
--- a/lib/pure/redis.nim
+++ b/lib/pure/redis.nim
@@ -26,6 +26,10 @@ type
     expected: int ## number of replies expected if pipelined
 
 type
+  TSendMode = enum
+    normal, pipelined, multiple
+
+type
   TRedis* {.pure, final.} = object
     socket: TSocket
     connected: bool
@@ -978,15 +982,14 @@ iterator hPairs*(r: TRedis, key: string): tuple[key, value: string] =
       yield (k, i)
       k = ""
 
-proc someTests(r: TRedis, how: string):seq[string] =
+proc someTests(r: TRedis, how: TSendMode):seq[string] =
   var list:seq[string] = @[]
 
-  case how
-  of "pipelined":
+  if how == pipelined:
     r.startPipelining()
-  of "multi": 
+  elif how ==  multiple: 
     r.multi()
-
+    
   r.setk("nim:test", "Testing something.")
   r.setk("nim:utf8", "こんにちは")
   r.setk("nim:esc", "\\ths ągt\\")
@@ -1019,11 +1022,11 @@ proc someTests(r: TRedis, how: string):seq[string] =
   list.add(r.echoServ("BLAH"))
 
   case how
-  of "normal":
+  of normal:
     return list
-  of "pipelined":
+  of pipelined:
     return r.flushPipeline()
-  of "multi":
+  of multiple:
     return r.exec()
 
 proc assertListsIdentical(listA, listB: seq[string]) =
@@ -1038,12 +1041,12 @@ when isMainModule:
     var r = open()
 
     # Test with no pipelining
-    var listNormal = r.someTests("normal")
+    var listNormal = r.someTests(normal)
 
     # Test with pipelining enabled
-    var listPipelined = r.someTests("pipelined")
+    var listPipelined = r.someTests(pipelined)
     assertListsIdentical(listNormal, listPipelined)
 
     # Test with multi/exec() (automatic pipelining)
-    var listMulti = r.someTests("multi")
+    var listMulti = r.someTests(multiple)
     assertListsIdentical(listNormal, listMulti)