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

lib/client/client.ts:70

Methods

close

close(): Promise<void>

Close the connection to Redis.

Returns

Promise<void>

Defined in

lib/client/client.ts:127


fetchRepository

fetchRepository<T>(schema): Repository<InferSchema<T>>

Creates a repository for the given schema.

Type parameters

NameType
Textends Schema<any, T>

Parameters

NameTypeDescription
schemaTThe schema.

Returns

Repository<InferSchema<T>>

A repository for the provided schema.

Defined in

lib/client/client.ts:119


isOpen

isOpen(): boolean

Returns

boolean

Whether a connection is already open.

Defined in

lib/client/client.ts:213


open

open(url?): Promise<Client>

Open a connection to Redis at the provided URL.

Parameters

NameTypeDefault valueDescription
urlstring'redis://localhost:6379'A URL to Redis as defined with the IANA.

Returns

Promise<Client>

This Client instance.

Defined in

lib/client/client.ts:104


use

use(connection): Promise<Client>

Attaches an existing Node Redis connection to this Redis OM client. Closes any existing connection.

Parameters

NameTypeDescription
connectionRedisConnectionAn existing Node Redis client.

Returns

Promise<Client>

This Client instance.

Defined in

lib/client/client.ts:81


useNoClose

useNoClose(connection): Client

Attaches an existing Node Redis connection to this Redis OM client. Does not close any existing connection.

Parameters

NameTypeDescription
connectionRedisConnectionAn existing Node Redis client.

Returns

Client

This Client instance.

Defined in

lib/client/client.ts:93