How To Connect to a Redis Database Different ways to do it

Are you trying to establish connection to a Redis database?

This guide is for you.

With redis-cli, you can easily connect to a Redis database via the command line.

Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform database related tasks.

In this context, we shall look into the different methods to connect to a Redis database.

More information about Redis?

Redis is an open-source, in-memory key-value data store. A NoSQL database, Redis doesn't use structured query language, otherwise known as SQL. Redis instead comes with its own set of commands for managing and accessing data.

Basically, with its in-memory key-value data store, it can be used as a database, cache, and message broker.

Most times, users might need to connect to the Redis database if it installed locally or in a remote instance to perform most operations.

Here, you will learn how to connect to Redis from the command line, how to authenticate and test the connection, as well as how to close a Redis connection.

For instance, in Ubuntu 18.04 server running Redis version 4.0.9 using redis-cli can be done by following the process below.

How to connect to Redis Locally?

If you have Redis-server installed locally, we can connect to the Redis instance with the below command:


Basically, after running the above command we are in a Redis-cli’s interactive mode which presents with a read-eval-print loop (REPL) where we can run Redis’s built-in commands and receive replies.

In interactive mode, the command-line prompt will change to reflect the connection. The prompt indicates a connection to a Redis instance hosted locally ( and accessed over Redis’s default port (6379).>

Also, the alternative to running Redis commands in interactive mode is given below;

redis-cli redis_command

How to connect Redis Remotely ?

Similarly, the command that uses to connect to the remote Redis database;

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

Also, with a Redis password, clients will be able to connect to Redis even not include the -a flag in their redis-cli command. But, they not allowed to perform any actions like add, change, or query data until they authenticate. In order to authenticate after connecting, we use the below auth command followed by the password:> auth password

If the password is correct, it brings an OK message whereas it will return an error.

[Need urgent assistance with database administration tasks? – We're available 24*7. ]


This article will guide you on the steps to connect to a #Redis #database using different commands like redis-cli using #commands.

Running redis-cli followed by a command name and its arguments will send this command to the Redis instance running on localhost at port 6379. You can change the host and #port used by redis-cli, just try the --help option to check the usage information.