Skip to content

Commit f0980a0

Browse files
authored
Add support for deleting table (#31)
1 parent 93010e1 commit f0980a0

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/swsssdk/configdb.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,18 @@ def get_table(self, table):
238238
pass #Ignore non table-formated redis entries
239239
return data
240240

241+
def delete_table(self, table):
242+
"""Delete an entire table from config db.
243+
Args:
244+
table: Table name.
245+
"""
246+
client = self.redis_clients[self.CONFIG_DB]
247+
pattern = '{}{}*'.format(table.upper(), self.TABLE_NAME_SEPARATOR)
248+
keys = client.keys(pattern)
249+
data = {}
250+
for key in keys:
251+
client.delete(key)
252+
241253
def mod_config(self, data):
242254
"""Write multiple tables into config db.
243255
Extra entries/fields in the db which are not in the data are kept.

0 commit comments

Comments
 (0)