I am using Redis to store two databases : 0 and 1 via the Redis-py client library. I would like to create two connections for each database. Currently, I am doing this :
You really shouldn't create connections like that. Let me quote the redis-py documentation.
Behind the scenes, redis-py uses a connection pool to manage connections to a Redis server. By default, each Redis instance you create will in turn create its own connection pool. You can override this behavior and use an existing connection pool by passing an already created connection pool instance to the connection_pool argument of the Redis class. You may choose to do this in order to implement client side sharding or have finer grain control of how connections are managed.
>>> pool = redis.ConnectionPool(host='localhost', port=6379, db=0)
>>> r = redis.StrictRedis(connection_pool=pool)
You cannot specify a single connection to be used with the library. Each Redis instance will have its own connection pool. When execute_command() is called, it will pop a connection from a the pool(or open a new one) and use that connection. If you only want your client to have max one connection at a time, set max_connections to 1.