forked from denodrivers/redis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod.ts
30 lines (27 loc) · 1016 Bytes
/
mod.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import type { Redis, RedisConnectOptions } from "../redis.ts";
import { create } from "../redis.ts";
import type { Connection } from "../connection.ts";
import { createRedisConnection } from "../connection.ts";
import { createDefaultPool } from "./default_pool.ts";
import { createPooledExecutor } from "./executor.ts";
export interface CreatePoolClientOptions {
connection: RedisConnectOptions;
maxConnections?: number;
}
export function createPoolClient(
options: CreatePoolClientOptions,
): Promise<Redis> {
const pool = createDefaultPool<Connection>({
acquire,
maxConnections: options.maxConnections ?? 8,
});
const executor = createPooledExecutor(pool);
const client = create(executor);
return Promise.resolve(client);
async function acquire(): Promise<Connection> {
const { hostname, port, ...connectionOptions } = options.connection;
const connection = createRedisConnection(hostname, port, connectionOptions);
await connection.connect();
return connection;
}
}