# Redis CLI Basics

> Basic usage and command calls for Redis from the command line.

- Canonical: https://dennisokeeffe.com/blog/2019-03-12-redis-cli-basics
- Published: 2019-03-12
- Updated: 2019-03-12

## tl;dr

### Hash Sets

| Command | Function                          | Example                                  |
| ------- | --------------------------------- | ---------------------------------------- |
| HGETALL | Get all fields and values in hash | HGETALL coin:btc                         |
| HKEYS   | Get all fields in hash            | HKEYS coin:btc                           |
| HGET    | Get value of hash field           | HGET coin:btc id                         |
| HMGET   | Multiple get value of hash field  | HGET coin:btc id buy sell                |
| HSET    | Set value of hash field           | HSET coin:btc id 1234                    |
| HMSET   | Multiple set value of hash field  | HSET coin:btc id ID1234 buy 123 sell 100 |

### Lists

| Command | Function                      | Example          |
| ------- | ----------------------------- | ---------------- |
| RPUSH   | Push elements onto a list     | RPUSH list "one" |
| LPOP    | Pop element from last on list | LPOP list        |
| LLEN    | Get list length               | LLEN list        |

### Run local server and attach

```shell
# terminal one
redis-server /usr/local/etc/redis.conf
# terminal two
redis-cli
```

## Command list

| Function             | Command                                                                     |
| -------------------- | --------------------------------------------------------------------------- |
| Install              | brew install redis                                                          |
| Run server           | redis-server /usr/local/etc/redis.conf                                      |
| Uninstall            | brew uninstall redis && rm ~/Library/LaunchAgents/homebrew.mxcl.redis.plist |
| Info                 | brew info redis                                                             |
| Run Redis CLI client | redis-cli                                                                   |

## Redis commands

A full list can be found at https://redis.io/commands.
