Skip to content

Commit

Permalink
[update] dbclient
Browse files Browse the repository at this point in the history
  • Loading branch information
jhao104 committed Nov 13, 2018
1 parent c1e74b4 commit e41a9cb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
10 changes: 4 additions & 6 deletions DB/DbClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class DbClient(object):
所有方法需要相应类去具体实现:
SSDB:SsdbClient.py
REDIS:RedisClient.py
REDIS:RedisClient.py 停用 统一使用SsdbClient.py
"""

Expand All @@ -66,7 +66,7 @@ def __initDbClient(self):
if "SSDB" == config.db_type:
__type = "SsdbClient"
elif "REDIS" == config.db_type:
__type = "RedisClient"
__type = "SsdbClient"
elif "MONGODB" == config.db_type:
__type = "MongodbClient"
else:
Expand Down Expand Up @@ -107,7 +107,5 @@ def getNumber(self):

if __name__ == "__main__":
account = DbClient()
print(account.get())
account.changeTable('use')
account.put('ac')
print(account.get())
account.changeTable('useful_proxy')
print(account.pop())
14 changes: 6 additions & 8 deletions DB/SsdbClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,13 @@ class SsdbClient(object):
验证后的代理存放在name为useful_proxy的hash中,key为代理的ip:port,value为一个计数,初始为1,每校验失败一次减1;
"""
# 为了保持DbClient的标准
# 在SsdbClient里面接受username参数, 但不进行使用.
# 因为不能将username通过kwargs传进redis.Redis里面, 会报错:
# TypeError: __init__() got an unexpected keyword argument 'username'
def __init__(self, name, username, **kwargs):
def __init__(self, name, **kwargs):
"""
init
:param name: hash name
:param host: ssdb host
:param port: ssdb port
:param host: host
:param port: port
:param password: password
:return:
"""
self.name = name
Expand Down Expand Up @@ -114,6 +111,7 @@ def getNumber(self):
def changeTable(self, name):
self.name = name


if __name__ == '__main__':
c = SsdbClient('useful_proxy', '118.24.52.95', 8899)
c = SsdbClient(name='useful_proxy', host='127.0.0.1', port=8899, password=None)
print(c.getAll())

0 comments on commit e41a9cb

Please sign in to comment.