Closed spccold closed 6 years ago
def sizeof_string(self, string): # https://github.com/antirez/redis/blob/unstable/src/sds.h try: num = int(string) if num < REDIS_SHARED_INTEGERS : return 0 else : return 8 + self.robj_overhead() except ValueError: pass l = len(string) if self._redis_version < StrictVersion('3.2'): return self.malloc_overhead(l + 8 + 1) + self.robj_overhead() if l < 2**5: return self.malloc_overhead(l + 1 + 1) + self.robj_overhead() if l < 2**8: return self.malloc_overhead(l + 1 + 2 + 1) + self.robj_overhead() if l < 2**16: return self.malloc_overhead(l + 1 + 4 + 1) + self.robj_overhead() if l < 2**32: return self.malloc_overhead(l + 1 + 8 + 1) + self.robj_overhead() return self.malloc_overhead(l + 1 + 16 + 1) + self.robj_overhead()