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).
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
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://pass123#my-web.cache.amazonaws.com:6379
command if username is also provided user123
redis-cli -u redis://user123:pass123#my-web.cache.amazonaws.com:6379
This detailed answer was for those who wants to check all options.
For more information check documentation: Redis command line usage
In Case of password also we need to pass one more parameter
redis-cli -h host -p port -a password
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.
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
Related
Redis monitor cmd is not working with authentication:
Cmd: redis-cli -h <redis_endpoint> -p <port> -n <database> -a <password> monitor
error: (error) ERR wrong number of arguments for 'MONITOR' command
But the same works with Redis without authentication:
redis-cli -h <redis_endpoint> -p 6379 monitor
Can someone help with correct redis-cli monitor cmd that works with database and password.
I am using redis 2.4 . When I change the port in "redis.conf" file to another port redis-cli stops working. It shows
Could not connect to Redis at 127.0.0.1:6379: Unknown error not
connected>
The redis.conf file dictates the server's behavior. To tell the command line interface to connect to your newly-defined-non-default port, use the -p switch, e.g.:
$ redis-cli -p 12758
I have an ansible playbook which connects to a virtual machine via a non-standard ssh port (forwarded to localhost) and a different user than the host user (vagrant).
The ssh port is specified in the ansible inventory:
[vms]
localhost:2222
The username given on the command line to ansible-playbook:
ansible-playbook -i <inventory from above> <some playbook> -u vagrant
The communication with the VM works correctly, however, %p always expands to 22 and %r to the host username.
Consequently, I cannot flush the SSH connection (for the user's changed group membership to take effect) like this:
- name: flush the ssh connection
command: ssh -o ControlPath="~/.ansible/cp/ansible-ssh-%h-%p-%r" -O stop {{inventory_hostname}}
delegate_to: 127.0.0.1
Am I making a silly mistake somewhere? Alternatively, is there a different way to flush the SSH connection?
The percent expand is not expanded by ansible, but by ssh later on.
Sorry, forgot to add the most important part
Using
command: ssh -o ControlPath=[...] -O stop {{inventory_hostname}}
will use default port, because you didn't specify it on the command-line. You would have to specify also the port to "flush" the connection this way:
command: ssh -o ControlPath=[...] -O stop -p {{inventory_port}} {{inventory_hostname}}
But I don't think it is needed. Ansible should clean up the connections when the playbook ends and I don't see any different reason why to do that.
I have been struggling with setting up a ProxyCommand to ssh through multiple hops. The issue I am having is integrating arguments in my normal ssh statement into the config file. I want to connect to IP2 via IP1. My username is greg and I am connecting using rsa. This is the one liner that will connect me:
ssh -A -t -p 22 -i ~/.ssh/private_key greg#IP1 ssh -A -t greg#IP2
I have tried a bunch of different config set ups and currently I am using:
Host ezConnect
ProxyCommand ssh %h nc IP2 22
HostKeyAlias IP2
HostName IP1
User greg
I know the issue is that it does not include the arguments I need, but wherever I try to put them it seems to break.
The reason I'm doing this is because I need to use a db GUI (navicat) to connect through a gateway server and the UI doesn't support a strait up ssh command.
Any help would be appreciated.
I figured it out so here is the correct config fie:
Host ezCon
Hostname **IP2**
User greg
ProxyCommand ssh -l greg -p 22 -i ~/.ssh/private_key **IP1** -W %h:%p
I know if I do redis-cli -h {ip_address} -p {port} I can connect to a specific port/ip but I've set my instance to not listen to any tcp/ip ports instead it listens to local socket.
How can I establish a socket connection with the redis client?
You can connect from redis-cli or redis-benchmark simply by using the -s option and providing the path of your unix domain socket.
For instance:
redis-cli -s /tmp/redis.sock
redis-benchmark -q -n 10000 -s /tmp/redis.sock