redis-om / Client
A Client is the starting point for working with Redis OM. Clients manage the connection to Redis and provide limited functionality for executing Redis commands. Create a client and open it before you use it:
const client = new Client()
await client.open()
A Client is primarily used by a Repository which requires a client in its constructor.
Deprecated
Just use Node Redis client directly and pass it to the Repository.
• new Client()
• get redis(): undefined | RedisConnection
Returns the underlying Node Redis connection being used.
undefined | RedisConnection
▸ close(): Promise<void>
Close the connection to Redis.
Promise<void>
▸ fetchRepository<T>(schema): Repository<InferSchema<T>>
Creates a repository for the given schema.
| Name | Type |
|---|---|
T |
extends Schema<any, T> |
| Name | Type | Description |
|---|---|---|
schema |
T |
The schema. |
A repository for the provided schema.
▸ isOpen(): boolean
boolean
Whether a connection is already open.
▸ open(url?): Promise<Client>
Open a connection to Redis at the provided URL.
| Name | Type | Default value | Description |
|---|---|---|---|
url |
string |
'redis://localhost:6379' |
A URL to Redis as defined with the IANA. |
Promise<Client>
This Client instance.
▸ use(connection): Promise<Client>
Attaches an existing Node Redis connection to this Redis OM client. Closes any existing connection.
| Name | Type | Description |
|---|---|---|
connection |
RedisConnection |
An existing Node Redis client. |
Promise<Client>
This Client instance.
▸ useNoClose(connection): Client
Attaches an existing Node Redis connection to this Redis OM client. Does not close any existing connection.
| Name | Type | Description |
|---|---|---|
connection |
RedisConnection |
An existing Node Redis client. |
This Client instance.