Exemple #1
0
    def read_stats(self, reader):
        response_line = reader.read_line()

        result = {}
        while True:
            response_line = reader.read_line()
            if response_line.startswith('STAT'):
                response_fields = response_line.split(' ')
                key = response_fields[1]
                value = response_fields[2]
                result[key] = value
            elif response_line == 'END':
                return MemcacheResult.OK, result
            else:
                return MemcacheResult.get(response_line), {}

        return MemcacheResult.OK, response_line
Exemple #2
0
 def read_get(self, reader, with_cas_unique = False):
     result = {}
     while True:
         response_line = reader.read_line()
         if response_line.startswith('VALUE'):
             response_fields = response_line.split(' ')
             key = response_fields[1]
             flags = int(response_fields[2])
             n = int(response_fields[3])
             if with_cas_unique:
                 cas_unique = int(response_fields[4])
             encoded_value = reader.read_bytes(n)
             reader.read_line() #\r\n
             if with_cas_unique:
                 result[key] = (self._codec.decode(flags, encoded_value), cas_unique)
             else:
                 result[key] = self._codec.decode(flags, encoded_value)
         elif response_line == 'END':
             return MemcacheResult.OK, result
         else:
             return MemcacheResult.get(response_line), {}
Exemple #3
0
 def read_version(self, reader):
     response_line = reader.read_line()
     if response_line.startswith('VERSION'):
         return MemcacheResult.OK, response_line[8:].strip()
     else:
         return MemcacheResult.get(response_line), None
Exemple #4
0
 def _read_result(self, reader, value = None):
     response_line = reader.read_line()
     return MemcacheResult.get(response_line), value
Exemple #5
0
 def _read_incdec(self, reader):
     response_line = reader.read_line()
     try:
         return MemcacheResult.OK, int(response_line)
     except ValueError:
         return MemcacheResult.get(response_line), None