add contains to RedisQueue

This commit is contained in:
simon 2022-12-12 18:01:02 +07:00
parent 3b3d151ec3
commit 2753ce93a2
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4

View File

@ -114,6 +114,11 @@ class RedisQueue(RedisBase):
all_elements = [i.decode() for i in result] all_elements = [i.decode() for i in result]
return all_elements return all_elements
def contains(self, element):
"""check if element is in list"""
result = self.conn.execute_command("LPOS", self.key, element)
return result is not None
def add_list(self, to_add): def add_list(self, to_add):
"""add list to queue""" """add list to queue"""
self.conn.execute_command("RPUSH", self.key, *to_add) self.conn.execute_command("RPUSH", self.key, *to_add)