Connect to a database
After you have Set up a cluster and created a Redis database, you can connect to your database.
To connect to your database, you need the database endpoint, which includes the cluster name (FQDN) and the database port. Select the Configuration tab in the database screen to find the database endpoint.
If you try to connect with the FQDN, and the database does not respond, try connecting with the IP address. If this succeeds, DNS is not properly configured. To set up DNS, see Configure cluster DNS.
If you want to secure your connection, set up TLS.
Connect to a database
Use one of the following connection methods to connect to your database:
-
redis-cli
utility -
Redis client for your preferred programming language
redis-cli
The redis-cli
utility is installed when you install Redis. It provides a command-line interface that lets you work with your database using core Redis commands.
redis-cli
is located in /opt/redislabs/bin/
on a node with Redis Enterprise installed. To connect to the database from a node in the cluster, run redis-cli
with the database port.
$ sudo /opt/redislabs/bin/redis-cli -p <port>
To connect using redis-cli
from outside of the cluster, run redis-cli
with the database hostname and port.
$ sudo /opt/redislabs/bin/redis-cli -h <host> -p <port>
Redis client
Different programming languages use different connection clients to interact with Redis databases, and each client has its own syntax and installation process. For help with a specific client, see the client’s documentation.
See the client list to view all Redis clients by language.
You can’t use client libraries to configure Redis Enterprise Software. Instead, use:
- The Redis Software admin console
- The REST API
- Command-line utilities, such as
rladmin
Code example (Python)
A simple python application can also connect to the database.
-
Create a new file called
redis_test.py
:import redis r = redis.StrictRedis(host='<host>', port=<port>) print ("set key1 123") print (r.set('key1', '123')) print ("get key1") print(r.get('key1'))
Replace
<host>
and<port>
with the hostname and port for your database. -
Run the redis_test.py application to store and retrieve a key:
$ python redis_test.py
If the connection is successful, the output of the application looks like this:
set key1 123
True
get key1
123
RedisInsight
RedisInsight is a free Redis GUI that is available for MacOS, Windows, and Linux.
-
Open RedisInsight and select Add Redis Database.
-
Enter the host and port in the Host and Port fields.
-
Select Use TLS if TLS is set up.
-
Select Add Redis Database to connect to the database.
See the RedisInsight documentation for more information.