Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to retrieve a table without deserializing multi-keys #67

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src/swsssdk/configdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...}, ...}
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down