Just use redis.Redis
. It uses a connection pool under the hood, so you don't have to worry about managing at that level.
If you absolutely have to use a low level connection, you need to do the response handling that is normally done for you by redis.Redis
.
Here's an example of executing a single command using the low level connection:
def execute_low_level(command, *args, **kwargs):
connection = redis.Connection(**kwargs)
try:
connection.connect()
connection.send_command(command, *args)
response = connection.read_response()
if command in redis.Redis.RESPONSE_CALLBACKS:
return redis.Redis.RESPONSE_CALLBACKS[command](response)
return response
finally:
del connection
Example usage:
response = execute_low_level(
'HGET', 'redis:key', 'hash:key', host='localhost', port=6379)
But as I said before, redis.Redis
is the way to go in 99.9% of cases.
StrictRedis
doesn't implementclose
orquit
methods. – jonrsharpe Jul 21 '14 at 22:33r.client_kill
, but to find out, which client to kill, you have to list them byr.client_list()
. Checking$ netstat | grep 6379
I saw, the connection got into "closing" state. There is alsor.execute_command("QUIT")
. But I am still not sure, if it does, what you ask for. – Jan Vlcinsky Jul 21 '14 at 22:44