def __init__(self, r: redis.client.Redis, expire=7 * 24 * 60 * 60, keys_key='bucket_keys'): super().__init__() self.r = r self.pipe = r.pipeline() self.expire = expire self.bucket_keys = set() self.keys_key = keys_key
def zrem_all(r: redis.client.Redis, ddict): try: p = r.pipeline() p.watch(*list(ddict.keys())) p.multi() for (topic, name) in ddict.items(): p.zrem(topic, name) p.execute() return True except redis.WatchError as e: print(e) return False
def remove_price_and_size(r: redis.client.Redis, price_topic, order_topic, account_name_topic, order_id): try: p = r.pipeline() p.watch(price_topic, order_topic) p.multi() p.zrem(price_topic, order_id) p.hdel(order_topic, order_id) p.hdel(account_name_topic, order_id) p.execute() return True except redis.WatchError as e: print(e) return False
def zpop(r: redis.client.Redis, name, desc): try: r.watch(name) zrange_result = r.zrange(name, 0, 0, desc=desc) if len(zrange_result) == 0: return (None, False) result = zrange_result[0] p = r.pipeline() p.watch(name) p.multi() p.zrem(name, result) p.execute() return (result, True) except redis.WatchError as e: print(e) return (None, False)