Chapter 2. Clients

In this chapter, we’ll look into some of the ways you can connect to Redis. We’ll begin with the most basic option: Redis’s command-line client, the redis-cli command. Then we’ll look at ways to integrate Redis with common programming languages such as Ruby and Python.

Using Redis from the Command Line

Problem

Often you might find yourself in need of firing a simple Redis query, either to set or change a variable, flush a database, or perhaps take a look at your data. With Redis you can achieve this directly from the command line.

Solution

Redis ships with a command line client: redis-cli. Redis-cli is a fully featured interactive client, supporting line editing, history, and tab completion. By using help followed by a Redis command, you can also get help on how each command works.

You can use redis-cli to connect to a local or remote host Redis server and call commands by passing them as arguments (or piping them in) or by using its interactive mode.

Discussion

You can get a list of the command line options by typing:

redis-cli -h

The most typical usage scenarios would be something like the following, to connect to a remote server in interactive mode:

redis-cli -h serverip

The following connects to a local server running on a nondefault port in interactive mode:

redis-cli -p 6380

The following connects to a local server on the default port (6379), executes the INFO command, and returns you to your original shell:

redis-cli INFO

You can also use pipes and output redirection for ...

Get Redis Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.