def mget(self, keys): """返回一个或多个给定域的值 Args: keys: list 需获取值的key列表 Returns: 值的列表,顺序与传入参数顺序一致 """ if self.auto_slice and isinstance(keys, list): result = [] slice_list = sublist(keys, self.max_slice_size) for sli in slice_list: slice_li = self.client.hmget(self.name, sli) result.extend(slice_li) return result else: return self.client.hmget(self.name, keys)
def _slice(self, i, j): """执行List切片操作,i < j """ if self.auto_slice: result = [] slice_len = self.__len__() if j > slice_len: j = slice_len keys = range(i, j) slice_li = sublist(keys, self.max_slice_size) for sli in slice_li: start = sli[0] end = sli[-1] slice_li = self.client.lrange(self.name, start, end) result.extend(slice_li) return result else: return self.client.lrange(self.name, i, j - 1)
def zrange_slice(self, start=0, end=-1, desc=False, withscores=False): """切片后使用zrange """ if self.auto_slice: result = [] set_len = self.__len__() if end < 0: end = set_len + end + 1 if end > set_len: end = set_len keys = range(start, end) slice_li = sublist(keys, self.max_slice_size) for sli in slice_li: i = sli[0] j = sli[-1] slice_li = self.client.zrange(self.name, i, j, desc=desc, withscores=withscores) result.extend(slice_li) return result else: return self.client.zrange(self.name, start, end - 1, desc=desc, withscores=withscores)