0

I have a remote Linux Redis 7.0 server which I reach through a spiped tunnel.

Launch spiped locally:

spiped -F -e -s 127.0.0.1:6379 -t REMOTESERVER:6379 -k /etc/spiped/redis.key

and as expected I can connect to the remote Redis server via the command line utility:

(redis_test) bob@Roberts-Mac-mini redis_test % redis-cli      
127.0.0.1:6379> AUTH myverysecretpassphrase
OK
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> keys *
1) "test"
127.0.0.1:6379> exit

So all as expected. So tried the very simple python program:

import redis

r = redis.Redis(host='MYSERVERIP', port=6379, password='myverysecretpassphrase')

r.set('foo', 'bar')
value = r.get('foo')
print(value)

but get a long error trace:

(redis_test) bob@Roberts-Mac-mini redis_test % python test1.py 
Traceback (most recent call last):
  File "/Users/bob/Documents/work/redis_test/test1.py", line 8, in <module>
    r.set('foo', 'bar')
  File "/Users/bob/opt/miniconda3/envs/redis_test/lib/python3.11/site-packages/redis/commands/core.py", line 2238, in set
    return self.execute_command("SET", *pieces, **options)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bob/opt/miniconda3/envs/redis_test/lib/python3.11/site-packages/redis/client.py", line 1255, in execute_command
    conn = self.connection or pool.get_connection(command_name, **options)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bob/opt/miniconda3/envs/redis_test/lib/python3.11/site-packages/redis/connection.py", line 1389, in get_connection
    connection.connect()
  File "/Users/bob/opt/miniconda3/envs/redis_test/lib/python3.11/site-packages/redis/connection.py", line 610, in connect
    self.on_connect()
  File "/Users/bob/opt/miniconda3/envs/redis_test/lib/python3.11/site-packages/redis/connection.py", line 701, in on_connect
    auth_response = self.read_response()
                    ^^^^^^^^^^^^^^^^^^^^
  File "/Users/bob/opt/miniconda3/envs/redis_test/lib/python3.11/site-packages/redis/connection.py", line 812, in read_response
    response = self._parser.read_response(disable_decoding=disable_decoding)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bob/opt/miniconda3/envs/redis_test/lib/python3.11/site-packages/redis/connection.py", line 318, in read_response
    raw = self._buffer.readline()
          ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bob/opt/miniconda3/envs/redis_test/lib/python3.11/site-packages/redis/connection.py", line 249, in readline
    self._read_from_socket()
  File "/Users/bob/opt/miniconda3/envs/redis_test/lib/python3.11/site-packages/redis/connection.py", line 195, in _read_from_socket
    raise ConnectionError(SERVER_CLOSED_CONNECTION_ERROR)
redis.exceptions.ConnectionError: Connection closed by server.

Here is my environment:

# packages in environment at /Users/bob/opt/miniconda3/envs/redis_test:
redis-py                  4.4.0              pyhd8ed1ab_0    conda-forge
(redis_test) bob@Roberts-Mac-mini redis_test % python --version
Python 3.11.0

1 Answer 1

1

Just to exclude typos, are you actually replacing MYSERVERIP with 127.0.0.1? If not, that may be the cause of the issue - as the remote Redis server would be tunneled through 127.0.0.1:6379, according to your spiped command line.

So that should read instead:

r = redis.Redis(host='127.0.0.1', port=6379, password='myverysecretpassphrase')
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much @efran, you correctly spotted my mistake. I got confused by the spiped syntax :) Take care all good now.
while mine is already correct, i encounter the same issue, now i cant find a proper answer because of this

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.