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

Revert "Add support to remove the key of table entry" #24

Merged
merged 1 commit into from
Dec 5, 2017
Merged
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
16 changes: 4 additions & 12 deletions src/swsssdk/configdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,17 @@ def __raw_to_typed(self, raw_data):

def __typed_to_raw(self, typed_data):
if typed_data == None:
return None, None
return None
elif typed_data == {}:
return { "NULL": "NULL" }, None
return { "NULL": "NULL" }
raw_data = {}
del_data = []
for key in typed_data:
value = typed_data[key]
if type(value) is list:
raw_data[key+'@'] = ','.join(value)
elif value is None:
del_data.append(key)
else:
raw_data[key] = value
return raw_data, del_data
return raw_data

@staticmethod
def serialize_key(key):
Expand All @@ -153,19 +150,14 @@ def set_entry(self, table, key, data):
data: Table row data in a form of dictionary {'column_key': 'value', ...}.
Pass {} as data will create an entry with no column if not already existed.
Pass None as data will delete the entry.
Pass {'column_key': None, ...} as data will delete the key which value is None.
"""
key = self.serialize_key(key)
client = self.redis_clients[self.CONFIG_DB]
_hash = '{}{}{}'.format(table.upper(), self.TABLE_NAME_SEPARATOR, key)
if data == None:
client.delete(_hash)
else:
raw_data, del_data = self.__typed_to_raw(data)
if del_data:
client.hdel(_hash, *del_data)
if raw_data:
client.hmset(_hash, raw_data)
client.hmset(_hash, self.__typed_to_raw(data))

def get_entry(self, table, key):
"""Read a table entry from config db.
Expand Down