Skip to content

Commit

Permalink
[swsssdk] update DBInterface redis_client index from db_id to db_name (
Browse files Browse the repository at this point in the history
…sonic-net#87)

* [swsssdk] update DBInterface redis_client index to db_name
  • Loading branch information
dzhangalibaba authored Sep 30, 2020
1 parent 91cc6c6 commit 3ef02a1
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 98 deletions.
35 changes: 12 additions & 23 deletions src/swsssdk/dbconnector.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,10 @@ def connect(self, db_name, retry_on=True):
self.dbintf.redis_kwargs["port"] = self.get_db_port(db_name)
self.dbintf.redis_kwargs["unix_socket_path"] = None
db_id = self.get_dbid(db_name)
self.dbintf.connect(db_id, retry_on)
self.dbintf.connect(db_id, db_name, retry_on)

def close(self, db_name):
db_id = self.get_dbid(db_name)
self.dbintf.close(db_id)
self.dbintf.close(db_name)

def get_db_list(self):
return SonicDBConfig.get_dblist(self.namespace)
Expand All @@ -275,43 +274,33 @@ def get_db_separator(self, db_name):
return SonicDBConfig.get_separator(db_name, self.namespace)

def get_redis_client(self, db_name):
db_id = self.get_dbid(db_name)
return self.dbintf.get_redis_client(db_id)
return self.dbintf.get_redis_client(db_name)

def publish(self, db_name, channel, message):
db_id = self.get_dbid(db_name)
return self.dbintf.publish(db_id, channel, message)
return self.dbintf.publish(db_name, channel, message)

def expire(self, db_name, key, timeout_sec):
db_id = self.get_dbid(db_name)
return self.dbintf.expire(db_id, key, timeout_sec)
return self.dbintf.expire(db_name, key, timeout_sec)

def exists(self, db_name, key):
db_id = self.get_dbid(db_name)
return self.dbintf.exists(db_id, key)
return self.dbintf.exists(db_name, key)

def keys(self, db_name, pattern='*', *args, **kwargs):
db_id = self.get_dbid(db_name)
return self.dbintf.keys(db_id, pattern, *args, **kwargs)
return self.dbintf.keys(db_name, pattern, *args, **kwargs)

def get(self, db_name, _hash, key, *args, **kwargs):
db_id = self.get_dbid(db_name)
return self.dbintf.get(db_id, _hash, key, *args, **kwargs)
return self.dbintf.get(db_name, _hash, key, *args, **kwargs)

def get_all(self, db_name, _hash, *args, **kwargs):
db_id = self.get_dbid(db_name)
return self.dbintf.get_all(db_id, _hash, *args, **kwargs)
return self.dbintf.get_all(db_name, _hash, *args, **kwargs)

def set(self, db_name, _hash, key, val, *args, **kwargs):
db_id = self.get_dbid(db_name)
return self.dbintf.set(db_id, _hash, key, val, *args, **kwargs)
return self.dbintf.set(db_name, _hash, key, val, *args, **kwargs)

def delete(self, db_name, key, *args, **kwargs):
db_id = self.get_dbid(db_name)
return self.dbintf.delete(db_id, key, *args, **kwargs)
return self.dbintf.delete(db_name, key, *args, **kwargs)

def delete_all_by_pattern(self, db_name, pattern, *args, **kwargs):
db_id = self.get_dbid(db_name)
self.dbintf.delete_all_by_pattern(db_id, pattern, *args, **kwargs)
self.dbintf.delete_all_by_pattern(db_name, pattern, *args, **kwargs)

pass
Loading

0 comments on commit 3ef02a1

Please sign in to comment.