> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-8c05c8a2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> This table function allows integrating ClickHouse with Redis.

# redis

This table function allows integrating ClickHouse with [Redis](https://redis.io/).

<h2 id="syntax">
  Syntax
</h2>

```sql theme={null}
redis(host:port, key, structure[, db_index[, password[, pool_size]]])
```

<h2 id="arguments">
  Arguments
</h2>

| Argument    | Description                                                                                                                     |
| ----------- | ------------------------------------------------------------------------------------------------------------------------------- |
| `host:port` | Redis server address, you can ignore port and default Redis port 6379 will be used.                                             |
| `key`       | any column name in the column list.                                                                                             |
| `structure` | The schema for the ClickHouse table returned from this function.                                                                |
| `db_index`  | Redis db index range from 0 to 15, default is 0.                                                                                |
| `password`  | User password, default is blank string.                                                                                         |
| `pool_size` | Redis max connection pool size, default is 16.                                                                                  |
| `primary`   | must be specified, it supports only one column in the primary key. The primary key will be serialized in binary as a Redis key. |

* columns other than the primary key will be serialized in binary as Redis value in corresponding order.
* queries with key equals or in filtering will be optimized to multi keys lookup from Redis. If queries without filtering key full table scan will happen which is a heavy operation.

[Named collections](/concepts/features/configuration/server-config/named-collections) are not supported for `redis` table function at the moment.

<h2 id="returned_value">
  Returned value
</h2>

A table object with key as Redis key, other columns packaged together as Redis value.

<h2 id="usage-example">
  Usage Example
</h2>

Read from Redis:

```sql theme={null}
SELECT * FROM redis(
    'redis1:6379',
    'key',
    'key String, v1 String, v2 UInt32'
)
```

Insert into Redis:

```sql theme={null}
INSERT INTO TABLE FUNCTION redis(
    'redis1:6379',
    'key',
    'key String, v1 String, v2 UInt32') values ('1', '1', 1);
```

<h2 id="related">
  Related
</h2>

* [The `Redis` table engine](/reference/engines/table-engines/integrations/redis)
* [Using redis as a dictionary source](/reference/statements/create/dictionary/sources/redis)
