I have two questions about this.
create a global instance and reuse in each thread or create a new instance in each thread?
use
pool = redis.ConnectionPool(host='localhost', port=6379, db=0)
r = redis.Redis(connection_pool=pool)or
r = redis.StrictRedis(host='localhost', port=6379, db=0)
document says about ConnectionPool:
You may choose to do this in order to implement client side sharding or have finer grain control of how connections are managed.But I can't understand what isclient side sharingrefer to .
update
if use ConnectionPool, which way below is right ?
A:
pool = redis.ConnectionPool(host='localhost', port=6379, db=0) class DownloadThread(threading.Thread): def __init__(self,pool): threading.Thread.__init__(self) self.r = redis.Redis(connection_pool=pool) def run(self): while True: self.r ..... B:
pool = redis.ConnectionPool(host='localhost', port=6379, db=0) r = redis.Redis(connection_pool=pool) class DownloadThread(threading.Thread): def __init__(self,r): threading.Thread.__init__(self) self.r = r def run(self): while True: self.r .....