Skip to content

Redis CLI basic operations

The redis-cli tool is the command-line interface used to interact with a [[Redis]] server. Once a server instance is running, users can connect and execute commands to manage data and system states^[600-developer-big-data-redis-redis-01-install.md].

Basic Connection and Interaction

To start an interactive session, the redis-cli command is executed from the src directory (or wherever the binaries are installed). Once inside the CLI, the connection to the server can be verified using the PING command, which expects a PONG response^[600-developer-big-data-redis-redis-01-install.md].

String Operations

Redis CLI supports standard data structure manipulation. For string values, the most common operations are setting and retrieving values^[600-developer-big-data-redis-redis-01-install.md]:

  • Set a value: Use SET key value. For example, SET foo bar stores the string "bar" at the key "foo".^[600-developer-big-data-redis-redis-01-install.md]
  • Get a value: Use GET key. For example, GET foo retrieves "bar".^[600-developer-big-data-redis-redis-01-install.md]
  • Increment: The INCR key command increments the integer value stored at a key by 1.^[600-developer-big-data-redis-redis-01-install.md]

Database Management

Redis includes support for multiple logical databases within a single server instance^[600-developer-big-data-redis-redis-01-install.md].

  • Switch Database: The SELECT index command allows the user to switch to a specific database (e.g., SELECT 0, SELECT 1).^[600-developer-big-data-redis-redis-01-install.md]
  • Check Size: DBSIZE returns the number of keys stored in the currently selected database^[600-developer-big-data-redis-redis-01-install.md].

Danger Zone: Data Deletion

Commands that delete data are irreversible and should be used with caution^[600-developer-big-data-redis-redis-01-install.md].

  • Flush Current Database: FLUSHDB removes all keys from the currently selected database^[600-developer-big-data-redis-redis-01-install.md].
  • Flush All Databases: FLUSHALL clears all keys in every database on the server^[600-developer-big-data-redis-redis-01-install.md].

Sources

^[600-developer-big-data-redis-redis-01-install.md]