Ejemplo n.º 1
0
 def SET(self):
     key = self.arguments[0]
     value = self.arguments[1]
     options = self.arguments[2:]
     mode = None
     expire = None
     for option in options:
         if mode == 'EX':
             expire = int(time.time()) + int(option)
         mode = option
     setattr(self.datastore, key, (value, expire))
     return (0, serialize_string('OK'))
Ejemplo n.º 2
0
 def FLUSHALL(self):
     return (20, serialize_string('OK'))
Ejemplo n.º 3
0
 def FLUSHDB(self):
     self.datastore.flush()
     return (0, serialize_string('OK'))
Ejemplo n.º 4
0
 def SELECT(self):
     db = int(self.arguments[0])
     if db > self.num_databases:
         return (0, serialize_error('ERR DB index is out of range'))
     else:
         return (10 + db, serialize_string('OK'))
Ejemplo n.º 5
0
 def PING(self):
     if self.arguments:
         return (0, serialize_string('{}'.format(' '.join(self.arguments))))
     else:
         return (0, serialize_string('PONG'))
Ejemplo n.º 6
0
 def MSET(self):
     arguments = iter(self.arguments)
     for key in arguments:
         setattr(self.datastore, key, (next(arguments), None))
     return (0, serialize_string('OK'))
Ejemplo n.º 7
0
 def QUIT(self):
     return (1, serialize_string('OK'))