1. Reid Draper
  2. tornadis

Commits

Reid Draper  committed 0827d5a

start writing the multi-bulk key maker

  • Participants
  • Parent commits 6139714
  • Branches default

Comments (0)

Files changed (1)

File redis.py

View file
  • Ignore whitespace
             if num_bytes < 1:
                 callback(None)
                 self.waiting = False
-                # ioloop.IOLoop.instance().add_callback(_work)
                 self._work()
                 return
             response = yield lambda cb : self.stream.read_bytes(num_bytes + self.DELBYTES, cb)
             callback(response[:-2])
             self._waiting = False
-            # ioloop.IOLoop.instance().add_callback(_work)
             self._work()
             return
             
         elif response[0] == '+':
             callback(True)
             self._waiting = False
-            # ioloop.IOLoop.instance().add_callback(_work)
             self._work()
             return
         
         elif response[0] == '-':
             callback(False)
             self._waiting = False
-            # ioloop.IOLoop.instance().add_callback(_work)
             self._work()
             return
+
+    def _cmd_creator(self, command, args):
+        num_args    = len(args) + 1 # add one for the command
+        args_string = ''.join(['$%d\r\n%s\r\n' % (len(arg), arg) for arg in args])
+        cmd = '*%d\r\n$%d\r\n%s\r\n%s' % (num_args, len(command), command, args_string)
+        return cmd
         
     def set(self, key, value, callback = None):
-        cmd = '%s %s %s\r\n%s\r\n' % ('SET', key, len(value), value)
+        cmd = self._cmd_creator('SET', [key, value])
         self._queue.append((cmd, callback))
         if not self._waiting:
             self._work()
         
     def get(self, key, callback = None):
-        cmd = 'GET %s\r\n' % key
+        cmd = self._cmd_creator('GET', [key])
         self._queue.append((cmd, callback))
         if not self._waiting:
             self._work()