# Connect to Redis
Source: https://docs.infraista.com/en/data-storage/redis/connect-to-redis



Open the database and select **Connection**. It shows the **Host**, **Port**, **User**, **Password**
(select **Show** to reveal it), the **Connection URL**, and command-line and client examples with your
details filled in.

<Shot name="data-storage/redis/connection" alt="A Redis database's Connection tab with host, port, user, password, connection URL, command line and client examples" />

**TLS is required.** Use `rediss://` URLs (note the double s) or your client's TLS option; plain
connections are refused. Any Redis client works.

In the examples, replace the host, port and password with yours. The user is usually `default`.

## Connection URL [#connection-url]

```bash
REDIS_URL=rediss://default:<password>@<host>:<port>
```

## Command line [#command-line]

```bash
valkey-cli --tls -h <host> -p <port> --user default --pass <password>
# or with the URL:
redis-cli -u 'rediss://default:<password>@<host>:<port>' --tls
```

## Node.js (ioredis) [#nodejs-ioredis]

```js
import Redis from 'ioredis'

const redis = new Redis({
  host: '<host>',
  port: <port>,
  username: 'default',
  password: process.env.REDIS_PASSWORD,
  tls: {},
})

await redis.set('hello', 'world')
```

## Python (redis-py) [#python-redis-py]

```python
import os
import redis

r = redis.Redis(
    host="<host>",
    port=<port>,
    username="default",
    password=os.environ["REDIS_PASSWORD"],
    ssl=True,
)

r.set("hello", "world")
```

## PHP [#php]

```php
// Predis
$client = new Predis\Client([
    'scheme'   => 'tls',
    'host'     => '<host>',
    'port'     => <port>,
    'username' => 'default',
    'password' => getenv('REDIS_PASSWORD'),
]);

// phpredis
$redis = new Redis();
$redis->connect('tls://<host>', <port>);
$redis->auth(['default', getenv('REDIS_PASSWORD')]);
```

Keep the password in an environment variable or your platform's secret store, not in code.

## Rotate the password [#rotate-the-password]

If the password may have leaked, select **Rotate password** and confirm. A new password is created and
clients using the old one are disconnected: update your apps right after.

## If something goes wrong [#if-something-goes-wrong]

* **The connection is reset or times out**: you're connecting without TLS, or your address isn't in the
  [trusted sources](/en/data-storage/redis/trusted-sources).
* **`WRONGPASS` or `NOAUTH`**: the password changed. Copy the current one from the Connection tab.
* **`OOM command not allowed`**: memory is full and the eviction policy is `noeviction`. Move to a bigger
  plan or change the policy in [Settings](/en/data-storage/redis/settings-and-metrics).

## Related [#related]

* [Trusted sources](/en/data-storage/redis/trusted-sources)
