def get_task_item(self, item_index, hash_key=None, key=None, sub_key=None): item_key = self._task_item_key(item_index, key, sub_key) if hash_key is None: item = self.redis_man.hgetall(item_key) for key in item.keys(): item[key] = StringData.unpack_data(item[key]) return item return StringData.unpack_data(self.redis_man.hget(item_key, hash_key))
def set_task_item(self, item_index, hash_key, hash_value, key=None, sub_key=None, nx=False): item_key = self._task_item_key(item_index, key, sub_key) if nx is True: return self.redis_man.hsetnx(item_key, hash_key, StringData.package_data(hash_value)) self.redis_man.hset(item_key, hash_key, StringData.package_data(hash_value))
def get(self, name): if self.key_prefix is None: return None name = self.key_prefix + name v = Redis.get(self, name) v = StringData.unpack_data(v) return v
def get_dirty_item(self, work_tag): k_l = [self.queue_prefix_key, work_tag, "*"] key_prefix = StringTool.join_decode(k_l, "_") prefix_len = len(key_prefix) - 1 hs = self.redis_man.keys(key_prefix) all_keys = dict() find_sub_key = re.compile("_(\d+)$") for item in hs: if self.redis_man.type(item) != "hash": continue search_r = find_sub_key.search(item) if search_r is None: continue sub_key = search_r.groups()[0] p = item[:0 - len(sub_key) - 1] if p in all_keys: all_keys[p].append(sub_key) else: all_keys[p] = [sub_key] delete_items = [] # 删除 没有任务描述的零散任务 for key in all_keys.keys(): union_key = key[prefix_len:] if "0" not in all_keys[key]: delete_items.append( dict(prefix=union_key, sub_keys=all_keys[key], message="未发现pipeline信息")) continue task_len = StringData.unpack_data( self.redis_man.hget(key + "_0", "task_len")) if task_len is None: delete_items.append( dict(prefix=union_key, sub_keys=all_keys[key], message="pipeline信息未发现task_len")) continue for i in range(task_len): if "%s" % i not in all_keys[key]: delete_items.append( dict(prefix=union_key, sub_keys=all_keys[key], message="缺少子任务%s的信息" % i)) return delete_items
def list_task_item(self, work_tag, key, sub_key=None): k_l = [self.queue_prefix_key, work_tag, key] if sub_key is not None: k_l.append(sub_key) task_item_compile = re.compile( re.escape(StringTool.join_decode(k_l, "_")) + "_(\\d+)$") get_key = StringTool.join_decode([k_l], "_") k_l.append("*") key_prefix = StringTool.join_decode(k_l, "_") hs = self.redis_man.keys(key_prefix) task_items = dict(sub=dict(), values=dict()) for item in hs: if self.redis_man.type(item) != "hash": continue m_r = task_item_compile.match(item) if m_r is None: continue task_items["sub"][m_r.groups()[0]] = item if self.redis_man.type(get_key) == "hash": item = self.redis_man.hgetall(get_key) for key in item.keys(): task_items["values"][key] = StringData.unpack_data(item[key]) return task_items
def setex(self, name, value, time): if self.key_prefix is None: return None value = StringData.package_data(value) name = self.key_prefix + name return Redis.setex(self, name, value, time)
def set(self, name, value, ex=None, px=None, nx=False, xx=False): if self.key_prefix is None: return None value = StringData.package_data(value) name = self.key_prefix + name return Redis.set(self, name, value, ex=ex, px=px, nx=nx, xx=xx)