forked from renan-souza/flowcept
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #102 from ORNL/dev
Main < Dev: Context management
- Loading branch information
Showing
15 changed files
with
273 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from redis import Redis | ||
|
||
from flowcept.commons.flowcept_logger import FlowceptLogger | ||
from flowcept.configs import ( | ||
REDIS_HOST, | ||
REDIS_PORT, | ||
REDIS_PASSWORD, | ||
) | ||
|
||
|
||
class KeyValueDAO: | ||
def __init__(self, connection=None): | ||
self.logger = FlowceptLogger().get_logger() | ||
if connection is None: | ||
self._redis = Redis( | ||
host=REDIS_HOST, | ||
port=REDIS_PORT, | ||
db=0, | ||
password=REDIS_PASSWORD, | ||
) | ||
else: | ||
self._redis = connection | ||
|
||
def delete_set(self, set_name: str): | ||
self._redis.delete(set_name) | ||
|
||
def add_key_into_set(self, set_name: str, key): | ||
self._redis.sadd(set_name, key) | ||
|
||
def remove_key_from_set(self, set_name: str, key): | ||
self._redis.srem(set_name, key) | ||
|
||
def set_has_key(self, set_name: str, key) -> bool: | ||
return self._redis.sismember(set_name, key) | ||
|
||
def set_count(self, set_name: str): | ||
return self._redis.scard(set_name) | ||
|
||
def set_is_empty(self, set_name: str) -> bool: | ||
return self.set_count(set_name) == 0 | ||
|
||
def delete_all_matching_sets(self, key_pattern): | ||
matching_sets = self._redis.keys(key_pattern) | ||
for set_name in matching_sets: | ||
self.delete_set(set_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.