How to connect to remote Redis server?
Asked Answered
C

6

271

I have URL and PORT of remote Redis server. I am able to write into Redis from Scala. However I want to connect to remote Redis via terminal using redis-server or something similar in order to make several call of hget, get, etc. (I can do it with my locally installed Redis without any problem).

Corticate answered 18/11, 2016 at 13:54 Comment(0)
A
450
redis-cli -h XXX.XXX.XXX.XXX -p YYYY

xxx.xxx.xxx.xxx is the IP address and yyyy is the port

EXAMPLE from my dev environment

redis-cli -h 10.144.62.3 -p 30000

REDIS CLI COMMANDS

Host, port, password and database By default redis-cli connects to the server at 127.0.0.1 port 6379. As you can guess, you can easily change this using command line options. To specify a different host name or an IP address, use -h. In order to set a different port, use -p.

redis-cli -h redis15.localnet.org -p 6390 ping

Aborn answered 18/11, 2016 at 13:59 Comment(4)
It says Could not connect to Redis at -c:6379: Temporary failure in name resolutionCorticate
@ duckertito- ABle to solve this issue ? I'm also facing the sameDrawbridge
You can use redis-cli -u redis://user:pass@host:port as well if you don't feel like entering host and port separately..Mumbletypeg
The host has a changing IP address (or none if you have no network access). We recommend that you connect to the special DNS name host.docker.internal which resolves to the internal IP address used by the host So docker run -it --rm bitnami/redis:latest redis-cli -h host.docker.internal -p 6379 should workMetabolize
D
98

There are two ways to connect remote redis server using redis-cli:

1. Using host & port individually as options in command

redis-cli -h host -p port

If your instance is password protected

redis-cli -h host -p port -a password

e.g. if my-web.cache.amazonaws.com is the host url and 6379 is the port

Then this will be the command:

redis-cli -h my-web.cache.amazonaws.com -p 6379

if 92.101.91.8 is the host IP address and 6379 is the port:

redis-cli -h 92.101.91.8 -p 6379

command if the instance is protected with password pass123:

redis-cli -h my-web.cache.amazonaws.com -p 6379 -a pass123

2. Using single uri option in command

redis-cli -u redis://password@host:port

command in a single uri form with username & password

redis-cli -u redis://username:password@host:port

e.g. for the same above host - port configuration command would be

redis-cli -u redis://[email protected]:6379

command if username is also provided user123

redis-cli -u redis://user123:[email protected]:6379

This detailed answer was for those who wants to check all options. For more information check documentation: Redis command line usage

Desdamonna answered 31/3, 2020 at 15:3 Comment(3)
How to connect to redis that used ssl. when I tried this redis-cli -u rediss://default:[email protected]:25945, it throws Invalid URI scheme error.Sonya
@Sonya redis-cli does not support TLS connections, so you’ll need to use a different tool that supports the rediss protocol in order to connect with the URI. I’ll suggest using redli(github.com/IBM-Cloud/redli) and this command to connect: redli --tls -u rediss://default:[email protected]:25945. But if you’re bound to use redis-cli then you’ll be needed to do extra config for the same. Check: redis.io/topics/encryptionDesdamonna
For using single uri option in Java add database index at end: Example: if /0, then redis://user:password@host:port/0Tother
B
70

In Case of password also we need to pass one more parameter

redis-cli -h host -p port -a password
Braunstein answered 24/4, 2019 at 11:37 Comment(1)
Using a password on the command line can be insecure. A more secure version of this is to connect without the password. redis-cli -h host -p port And then authenticate. host:6379> AUTH abcdefgKrupp
R
15

One thing that confused me a little bit with this command is that if redis-cli fails to connect using the passed connection string it will still put you in the redis-cli shell, i.e:

redis-cli
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected> 

You'll then need to exit to get yourself out of the shell. I wasn't paying much attention here and kept passing in new redis-cli commands wondering why the command wasn't using my passed connection string.

Rote answered 29/9, 2020 at 22:45 Comment(0)
K
4

if you got Error: Server closed the connection try with --tls switch:

redis-cli --tls -h my-redis.redis.cache.windows.net -p 6379 -a myRedisPassword
  • h 👉 hostname
  • p 👉 port
  • a 👉 password
Krefetz answered 14/12, 2022 at 14:22 Comment(0)
B
1

If none of these responses are working then try:

redis-cli -u rediss://user:pass@host:port
Beef answered 23/8, 2023 at 10:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.