To run Redis commands on a remote Redis server, you can use the Redis command-line interface (CLI) tool (redis-cli
) and specify the hostname and port of the remote server. Here are the steps:
Open a terminal or command prompt on your local machine.
Use the following command to connect to the remote Redis server:
redis-cli -h <hostname> -p <port>
Replace
<hostname>
and<port>
with the hostname and port number of the remote Redis server, respectively. For example:redis-cli -h 192.168.1.100 -p 6379
This command connects to the Redis server running on the IP address
192.168.1.100
on port6379
.Once connected, you can run Redis commands on the remote server just as you would on a local Redis server. For example:
192.168.1.100:6379> SET mykey "Hello Redis" OK 192.168.1.100:6379> GET mykey "Hello Redis"
This sets the value of the key
mykey
to"Hello Redis"
and retrieves its value.To disconnect from the remote Redis server, use the
QUIT
command:192.168.1.100:6379> QUIT
This terminates the Redis CLI session and returns you to the command prompt.
Note that you may need to configure your remote Redis server to allow remote connections and ensure that the necessary ports are open in your network firewall. Additionally, for security reasons, it's recommended to use Redis authentication and SSL encryption when connecting to a remote Redis server.
Comments
Post a Comment