# Connect a Redis client

> Authenticate with redis-cli or a driver, then write and read a key.

---

LLMS index: [llms.txt](/llms.txt)

---

Complete [Quick start](/docs/redis/quickstart/) first. This tutorial uses `redis-cli`, the `pgredis_app` role and the `pgredis_demo` database with the gateway listening on `127.0.0.1:6379` (or `56379` if started with the default `-listen` flag).

## Open a RESP2 session {#connect}

Connect with `redis-cli` and authenticate as `pgredis_app`:

```sh
redis-cli -h 127.0.0.1 -p 6379 --user pgredis_app --askpass
```

Enter the password for the `pgredis_app` PostgreSQL role, then run the following commands at the prompt:

```text
> PING
PONG
> SET pgredis:demo:client ready
OK
> GET pgredis:demo:client
"ready"
> SELECT 1
OK
> EXISTS pgredis:demo:client
(integer) 0
> SELECT 0
OK
> DEL pgredis:demo:client
(integer) 1
> QUIT
OK
```

`SELECT 1` switches the current connection to logical database `1`. Because `pgredis:demo:client` was created in logical database `0`, `EXISTS` in database `1` returns `0`. Switching back to `SELECT 0` finds and deletes the key.

## Use RESP3 {#resp3}

The gateway supports both RESP2 and RESP3 on the same listener. Pass `-3` to `redis-cli` (or send `HELLO 3`) to negotiate RESP3:

```sh
redis-cli -3 -h 127.0.0.1 -p 6379 --user pgredis_app --askpass
```

Both protocol versions read and write the same PostgreSQL tables.

## Handle lost responses {#failures}

Each standalone command commits in PostgreSQL before the gateway writes the reply to the client socket. If the network drops after PostgreSQL commits but before the client reads the reply, the write has already taken effect. Do not blindly retry non-idempotent commands such as `INCR` or `LPUSH`; see [Disconnects and unknown outcomes](/docs/redis/compatibility/#failure).

---

Backlinks:

- [Tutorials](/docs/redis/tutorial/)
