Skip to content

Commit

Permalink
Revert "Add support to remove the key of table entry (sonic-net#15)" (s…
Browse files Browse the repository at this point in the history
…onic-net#24)

This reverts commit 993d961.
  • Loading branch information
lguohan authored Dec 5, 2017
1 parent 993d961 commit c289190
Showing 1 changed file with 4 additions and 12 deletions.
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

0 comments on commit c289190

Please sign in to comment.