Class: Client
August 11, 2024 · View on GitHub
redis-om / Client
Class: 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.
Table of contents
Constructors
Accessors
Methods
Constructors
constructor
• new Client()
Accessors
redis
• get redis(): undefined | RedisConnection
Returns the underlying Node Redis connection being used.
Returns
undefined | RedisConnection
Defined in
Methods
close
▸ close(): Promise<void>
Close the connection to Redis.
Returns
Promise<void>
Defined in
fetchRepository
▸ fetchRepository<T>(schema): Repository<InferSchema<T>>
Creates a repository for the given schema.
Type parameters
| Name | Type |
|---|---|
T | extends Schema<any, T> |
Parameters
| Name | Type | Description |
|---|---|---|
schema | T | The schema. |
Returns
A repository for the provided schema.
Defined in
isOpen
▸ isOpen(): boolean
Returns
boolean
Whether a connection is already open.
Defined in
open
▸ open(url?): Promise<Client>
Open a connection to Redis at the provided URL.
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
url | string | 'redis://localhost:6379' | A URL to Redis as defined with the IANA. |
Returns
Promise<Client>
This Client instance.
Defined in
use
▸ use(connection): Promise<Client>
Attaches an existing Node Redis connection to this Redis OM client. Closes any existing connection.
Parameters
| Name | Type | Description |
|---|---|---|
connection | RedisConnection | An existing Node Redis client. |
Returns
Promise<Client>
This Client instance.
Defined in
useNoClose
▸ useNoClose(connection): Client
Attaches an existing Node Redis connection to this Redis OM client. Does not close any existing connection.
Parameters
| Name | Type | Description |
|---|---|---|
connection | RedisConnection | An existing Node Redis client. |
Returns
This Client instance.