redis-py: redis exceptions Connection Error: Connection closed by server

Redis config file: redis_conf.txt

Here is an exception: exception

I run latest version of redis in container:

redis: image: redis:latest container_name: redis ports: - 6379:6379 volumes: - ./config/redis.conf:/redis.conf command: [ “redis-server”, “/redis.conf” ]

The application is written in Python ver 3.9

`import redis

pool = redis.ConnectionPool(host=‘localhost’, port=6379, db=0) r = redis.Redis(connection_pool=pool)

r.set(‘foo’, ‘bar’) value = r.get(‘foo’) print(value)`

As you see it is very basic. I had more complicated code that I tried to run at the beginning where I communicated with redis in multithread. Later this code caused a problem so that I am not able even to start with the above simple code no matter what I do: restart the computer, restart container, reinstall redis module. nothing helps I send commands in redis cli and it works. But python throws an exception:

Please help me stay with redis!

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 18 (8 by maintainers)

Most upvoted comments

I found the problem and it made me embarrassed. The bind IP connection definition was wrong, redis was bound to IP of local host instead of container IP. The second I changed it code started running properly.

On Mon, Jan 18, 2021 at 4:31 PM Robert Geislinger notifications@github.com wrote:

I have the same issue with two virtual machines. I run various skripts on both machines using redis and the only connection that throws this error (quite often) is the one reading binary data from the redis database.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/andymccurdy/redis-py/issues/1445#issuecomment-762286445, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMYDWWPSRAWZIKCFBS6YYBDS2RA4PANCNFSM4WCA4MQQ .

For those from google, maybe --tls flag (or rediss:// with double s) is missing from your redis-cli command.

I found the problem and it made me embarrassed. The bind IP connection definition was wrong, redis was bound to IP of local host instead of container IP. The second I changed it code started running properly.

Hey @Alexander770 , I’m facing the same issue (I think), can you share the conf file you used?