From 69e52ebb944f6aa89b6d66d5587adf5b4237af00 Mon Sep 17 00:00:00 2001 From: Rajendra Dendukuri Date: Thu, 16 Apr 2020 13:20:15 -0700 Subject: [PATCH] Option to retrieve a table without deserializing multi-keys --- src/swsssdk/configdb.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/swsssdk/configdb.py b/src/swsssdk/configdb.py index c2420906e..6a17551a0 100644 --- a/src/swsssdk/configdb.py +++ b/src/swsssdk/configdb.py @@ -240,10 +240,11 @@ def get_keys(self, table, split=True): pass #Ignore non table-formated redis entries return data - def get_table(self, table): + def get_table(self, table, split_keys=True): """Read an entire table from config db. Args: table: Table name. + split_keys: split the keys if it is a multi-key table Returns: Table data in a dictionary form of { 'row_key': {'column_key': value, ...}, ...} @@ -261,10 +262,16 @@ def get_table(self, table): if PY3K: key = key.decode('utf-8') (_, row) = key.split(self.TABLE_NAME_SEPARATOR, 1) - data[self.deserialize_key(row)] = entry + if split_keys: + data[self.deserialize_key(row)] = entry + else: + data[row] = entry else: (_, row) = key.split(self.TABLE_NAME_SEPARATOR, 1) - data[self.deserialize_key(row)] = entry + if split_keys: + data[self.deserialize_key(row)] = entry + else: + data[row] = entry except ValueError: pass #Ignore non table-formated redis entries return data @@ -300,7 +307,9 @@ def mod_config(self, data): for key in table_data: self.mod_entry(table_name, key, table_data[key]) - def get_config(self): + def get_config(self, split_keys=True): + Args: + split_keys: split the keys of multi-key tables """Read all config data. Returns: Config data in a dictionary form of @@ -320,7 +329,10 @@ def get_config(self): (table_name, row) = key.split(self.TABLE_NAME_SEPARATOR, 1) entry = self.__raw_to_typed(client.hgetall(key)) if entry != None: - data.setdefault(table_name, {})[self.deserialize_key(row)] = entry + if split_keys: + data.setdefault(table_name, {})[self.deserialize_key(row)] = entry + else: + data.setdefault(table_name, {})[row] = entry except ValueError: pass #Ignore non table-formated redis entries return data