Skip to content

Commit

Permalink
add opcode for notification of redis DB
Browse files Browse the repository at this point in the history
  • Loading branch information
batmancn committed Nov 27, 2018
1 parent cb4fec9 commit 8d589e5
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/swsssdk/configdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ def unsubscribe(self, table):
if self.handlers.has_key(table):
self.handlers.pop(table)

def __fire(self, table, key, data):
def __fire(self, table, key, data, op_str='add'):
if self.handlers.has_key(table):
handler = self.handlers[table]
handler(table, key, data)
handler(table, key, data, op_str)

def listen(self):
"""Start listen Redis keyspace events and will trigger corresponding handlers when content of a table changes.
Expand All @@ -94,7 +94,11 @@ def listen(self):
if self.handlers.has_key(table):
client = self.redis_clients[self.CONFIG_DB]
data = self.__raw_to_typed(client.hgetall(key))
self.__fire(table, row, data)
op = client.keys(key)
op_str = 'add'
if len(op) == 0:
op_str = 'del'
self.__fire(table, row, data, op_str)
except ValueError:
pass #Ignore non table-formated redis entries

Expand Down

0 comments on commit 8d589e5

Please sign in to comment.