class SSDBHashMap(object, SSDBBase): def __init__(self, hashmap_name, host="127.0.0.1", port=8888, max_connections=10, timeout=60): self.hashmap_name = hashmap_name self.host = host self.port = port self.max_connections = max_connections self.timeout = timeout pool = BlockingConnectionPool(connection_class=Connection, max_connections=max_connections, timeout=timeout, host=host, port=port) self.ssdb = SSDB(connection_pool=pool) SSDBBase.__init__(self, self.ssdb) def set(self, key, value): return self.ssdb.hset(self.hashmap_name, key, value) def get(self, key): return self.ssdb.hget(self.hashmap_name, key) def delete(self, key): return self.ssdb.hdel(self.hashmap_name, key) def keys(self, name_start="", name_end="", limit=10): return self.ssdb.hkeys(self.hashmap_name, name_start, name_end, limit) def exists(self, key): return self.ssdb.hexists(self.hashmap_name, key) def size(self): return self.ssdb.hsize(self.hashmap_name) def list(self, name_start="", name_end="", limit=10): #列出名字处于区间 (name_start, name_end] 的 hashmap return self.ssdb.hlist(name_start, name_end, limit) def scan(self, key_start, key_end="", limit=10): return self.ssdb.hscan(self.hashmap_name, key_start, key_end, limit) def clear(self): return self.ssdb.hclear(self.hashmap_name)
class ssdb_proxy(object): def __init__(self, set_name, host, port, max_connections=2, timeout=60): """数据库初始化""" self.set_name = set_name self.host = host self.port = port self.max_connections = max_connections self.timeout = timeout pool = BlockingConnectionPool(connection_class=Connection, max_connections=max_connections, timeout=timeout, host=host, port=port) self.ssdb = SSDB(connection_pool=pool) pass def hset(self, key, value): """添加集合""" return self.ssdb.hset(self.set_name, key, value) def hget(self, key): """获取key所对应的值""" return self.ssdb.hget(self.set_name, key) def hgetall(self): """获取所有的数据""" return self.ssdb.hgetall(self.set_name) def hdel(self, key): """删除数据""" return self.ssdb.hdel(self.set_name, key) def hexists(self, key): """判断Key是否存在""" return self.ssdb.hexists(self.set_name, key) def size(self): """获取结合的大小""" return self.ssdb.hsize(self.set_name) def clean(self): """清楚所有数据""" return self.ssdb.hclear(self.set_name)