Skip to content

Commit

Permalink
Add delete() and delete_all_by_pattern() methods to DBInterface class (
Browse files Browse the repository at this point in the history
  • Loading branch information
jleveque authored Feb 21, 2018
1 parent f0980a0 commit ca540c9
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/swsssdk/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,26 @@ def set(self, db_name, _hash, key, val):
client = self.redis_clients[db_name]
return client.hset(_hash, key, val)

@blockable
def delete(self, db_name, key):
"""
Delete %key from DB %db_name
Parameter %blocking indicates whether to retry in case of failure
"""
client = self.redis_clients[db_name]
return client.delete(key)

@blockable
def delete_all_by_pattern(self, db_name, pattern):
"""
Delete all keys which match %pattern from DB %db_name
Parameter %blocking indicates whether to retry in case of failure
"""
client = self.redis_clients[db_name]
keys = client.keys(pattern)
for key in keys:
client.delete(key)

def _unavailable_data_handler(self, db_name, data):
"""
When the queried config is not available in Redis--wait until it is available.
Expand Down

0 comments on commit ca540c9

Please sign in to comment.