Introduction

Connect to a local instance of Redis

redis-cli
127.0.0.1:6739>

The prompt indicates a connection to a Redis instance hosted locally (127.0.0.1) and accessed over Redis's default port (6739)

Connect to a remote instance of Redis

redis-cli -h <host> -p <port_number> -a <password>

If you’ve set a Redis password, clients will be able to connect to Redis even if they don’t include the -a flag in their redis-cli command. However, they won’t be able to add, change, or query data until they authenticate.

To authenticate after connecting, use the auth command followed by the password:

127.0.0.1:6739> auth <password>

If you’re working with a managed Redis database, your cloud provider may give you a URI that begins with redis:// or rediss:// which you can use to access your datastore.

  • If the connection string begins with redis://, you can include it as an argument to redis-cli to connect.

  • However, if you have a connection string that begins with rediss://, that means your managed database requires connections over TLS/SSL.

    • 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.

    • For Managed Databases, which require connections to be made over TLS, Redli to access the Redis instance.

redli --tls -u rediss://<connection_URI>
  • -tls option : specifies that the connection should be made over TLS

  • -u flag : for connection URI

If an attempt to connect to an unavailable instance, redis-cli will go into disconnected mode.

Testing Connection

Disconnecting from Redis

Both quit and exit will close the connection, but only as soon as all pending replies have been written to clients.

Last updated

Was this helpful?