@tekir/redis 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 tekir
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,31 @@
1
+ <p align="center">
2
+ <img src="https://tekir.io/logo.svg" width="80" alt="tekir" />
3
+ </p>
4
+
5
+ <h1 align="center">@tekir/redis</h1>
6
+
7
+ <p align="center">Redis connection and client management</p>
8
+
9
+ <p align="center">
10
+ <a href="https://www.npmjs.com/package/@tekir/redis"><img src="https://img.shields.io/npm/v/@tekir/redis.svg" alt="npm version" /></a>
11
+ <a href="https://www.npmjs.com/package/@tekir/redis"><img src="https://img.shields.io/npm/dm/@tekir/redis.svg" alt="npm downloads" /></a>
12
+ <a href="https://github.com/tekir-io/tekir/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/@tekir/redis.svg" alt="license" /></a>
13
+ </p>
14
+
15
+ <p align="center">
16
+ <a href="https://tekir.io">Website</a> · <a href="https://docs.tekir.io">Documentation</a> · <a href="https://github.com/tekir-io/tekir">GitHub</a>
17
+ </p>
18
+
19
+ ---
20
+
21
+ ## Installation
22
+
23
+ ```bash
24
+ bun add @tekir/redis
25
+ ```
26
+
27
+ For full usage and configuration, see the [documentation](https://docs.tekir.io/advanced/redis).
28
+
29
+ ## License
30
+
31
+ MIT
@@ -0,0 +1,4 @@
1
+ export { Redis } from './redis';
2
+ export { RedisManager } from './manager';
3
+ export { RedisProvider } from './provider';
4
+ export type { RedisConfig, RedisConnectionConfig } from './types';
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { Redis } from './redis';
2
+ export { RedisManager } from './manager';
3
+ export { RedisProvider } from './provider';
@@ -0,0 +1,121 @@
1
+ import type { RedisConfig } from './types';
2
+ import { Redis } from './redis';
3
+ /**
4
+ * Manages multiple named Redis connections with lazy initialization.
5
+ *
6
+ * Provides proxy methods that delegate to the default connection for convenience,
7
+ * while also allowing access to any named connection via {@link RedisManager.connection}.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * const manager = new RedisManager({
12
+ * default: 'cache',
13
+ * connections: {
14
+ * cache: { url: 'redis://localhost:6379/0' },
15
+ * session: { url: 'redis://localhost:6379/1' },
16
+ * },
17
+ * })
18
+ * await manager.set('key', 'value') // uses 'cache'
19
+ * await manager.connection('session').set('k', 'v') // uses 'session'
20
+ * ```
21
+ */
22
+ export declare class RedisManager {
23
+ private _connections;
24
+ private _defaultName;
25
+ private _config;
26
+ /**
27
+ * Create a new RedisManager.
28
+ *
29
+ * @param config - Redis configuration with optional named connections.
30
+ */
31
+ constructor(config?: RedisConfig);
32
+ /**
33
+ * Get a named Redis connection. The connection is lazy-initialized on first access.
34
+ *
35
+ * @param name - The connection name. Defaults to the configured default connection.
36
+ * @returns The {@link Redis} instance for the named connection.
37
+ * @throws If the named connection is not configured.
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * const cache = manager.connection('cache')
42
+ * await cache.get('key')
43
+ * ```
44
+ */
45
+ connection(name?: string): Redis;
46
+ /**
47
+ * List all configured connection names.
48
+ *
49
+ * @returns An array of connection name strings.
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * manager.connectionNames // ['cache', 'session']
54
+ * ```
55
+ */
56
+ get connectionNames(): string[];
57
+ /**
58
+ * Close a specific named connection, or all connections if no name is given.
59
+ *
60
+ * @param name - The connection name to close. Omit to close all connections.
61
+ *
62
+ * @example
63
+ * ```ts
64
+ * manager.close('session') // close one connection
65
+ * manager.close() // close all connections
66
+ * ```
67
+ */
68
+ close(name?: string): void;
69
+ /** @see {@link Redis.get} */
70
+ get(key: string): Promise<string | null>;
71
+ /** @see {@link Redis.set} */
72
+ set(key: string, value: string | number): Promise<void>;
73
+ /** @see {@link Redis.del} */
74
+ del(...keys: string[]): Promise<void>;
75
+ /** @see {@link Redis.exists} */
76
+ exists(key: string): Promise<boolean>;
77
+ /** @see {@link Redis.incr} */
78
+ incr(key: string): Promise<number>;
79
+ /** @see {@link Redis.decr} */
80
+ decr(key: string): Promise<number>;
81
+ /** @see {@link Redis.expire} */
82
+ expire(key: string, seconds: number): Promise<void>;
83
+ /** @see {@link Redis.ttl} */
84
+ ttl(key: string): Promise<number>;
85
+ /** @see {@link Redis.hget} */
86
+ hget(key: string, field: string): Promise<string | null>;
87
+ /** @see {@link Redis.hmset} */
88
+ hmset(key: string, fields: string[]): Promise<void>;
89
+ /** @see {@link Redis.hmget} */
90
+ hmget(key: string, fields: string[]): Promise<(string | null)[]>;
91
+ /** @see {@link Redis.hincrby} */
92
+ hincrby(key: string, field: string, increment: number): Promise<number>;
93
+ /** @see {@link Redis.sadd} */
94
+ sadd(key: string, ...members: string[]): Promise<number>;
95
+ /** @see {@link Redis.srem} */
96
+ srem(key: string, ...members: string[]): Promise<number>;
97
+ /** @see {@link Redis.sismember} */
98
+ sismember(key: string, member: string): Promise<boolean>;
99
+ /** @see {@link Redis.smembers} */
100
+ smembers(key: string): Promise<string[]>;
101
+ /** @see {@link Redis.publish} */
102
+ publish(channel: string, message: string): Promise<void>;
103
+ /** @see {@link Redis.subscribe} */
104
+ subscribe(channel: string, callback: (message: string, channel: string) => void): Promise<void>;
105
+ /** @see {@link Redis.unsubscribe} */
106
+ unsubscribe(channel?: string): Promise<void>;
107
+ /** @see {@link Redis.send} */
108
+ send(command: string, args?: string[]): Promise<any>;
109
+ /** @see {@link Redis.getJSON} */
110
+ getJSON<T = any>(key: string): Promise<T | null>;
111
+ /** @see {@link Redis.setJSON} */
112
+ setJSON(key: string, value: any, expireSeconds?: number): Promise<void>;
113
+ /** @see {@link Redis.remember} */
114
+ remember<T>(key: string, seconds: number, callback: () => Promise<T>): Promise<T>;
115
+ /** @see {@link Redis.flushdb} */
116
+ flushdb(): Promise<void>;
117
+ /** @see {@link Redis.connected} */
118
+ get connected(): boolean;
119
+ /** @see {@link Redis.getClient} */
120
+ getClient(): any;
121
+ }
@@ -0,0 +1,153 @@
1
+ import { Redis } from './redis';
2
+ /**
3
+ * Manages multiple named Redis connections with lazy initialization.
4
+ *
5
+ * Provides proxy methods that delegate to the default connection for convenience,
6
+ * while also allowing access to any named connection via {@link RedisManager.connection}.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * const manager = new RedisManager({
11
+ * default: 'cache',
12
+ * connections: {
13
+ * cache: { url: 'redis://localhost:6379/0' },
14
+ * session: { url: 'redis://localhost:6379/1' },
15
+ * },
16
+ * })
17
+ * await manager.set('key', 'value') // uses 'cache'
18
+ * await manager.connection('session').set('k', 'v') // uses 'session'
19
+ * ```
20
+ */
21
+ export class RedisManager {
22
+ _connections = new Map();
23
+ _defaultName;
24
+ _config;
25
+ /**
26
+ * Create a new RedisManager.
27
+ *
28
+ * @param config - Redis configuration with optional named connections.
29
+ */
30
+ constructor(config = {}) {
31
+ this._config = config;
32
+ this._defaultName = config.default || 'default';
33
+ // If no connections map, treat the whole config as a single connection
34
+ if (!config.connections) {
35
+ this._connections.set(this._defaultName, new Redis(config));
36
+ }
37
+ }
38
+ /**
39
+ * Get a named Redis connection. The connection is lazy-initialized on first access.
40
+ *
41
+ * @param name - The connection name. Defaults to the configured default connection.
42
+ * @returns The {@link Redis} instance for the named connection.
43
+ * @throws If the named connection is not configured.
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * const cache = manager.connection('cache')
48
+ * await cache.get('key')
49
+ * ```
50
+ */
51
+ connection(name) {
52
+ const connName = name || this._defaultName;
53
+ if (!this._connections.has(connName)) {
54
+ const connConfig = this._config.connections?.[connName];
55
+ if (!connConfig) {
56
+ throw new Error(`[@tekir/redis] Connection "${connName}" is not configured. ` +
57
+ `Available: ${this.connectionNames.join(', ')}`);
58
+ }
59
+ this._connections.set(connName, new Redis(connConfig));
60
+ }
61
+ return this._connections.get(connName);
62
+ }
63
+ /**
64
+ * List all configured connection names.
65
+ *
66
+ * @returns An array of connection name strings.
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * manager.connectionNames // ['cache', 'session']
71
+ * ```
72
+ */
73
+ get connectionNames() {
74
+ if (this._config.connections)
75
+ return Object.keys(this._config.connections);
76
+ return [this._defaultName];
77
+ }
78
+ /**
79
+ * Close a specific named connection, or all connections if no name is given.
80
+ *
81
+ * @param name - The connection name to close. Omit to close all connections.
82
+ *
83
+ * @example
84
+ * ```ts
85
+ * manager.close('session') // close one connection
86
+ * manager.close() // close all connections
87
+ * ```
88
+ */
89
+ close(name) {
90
+ if (name) {
91
+ this._connections.get(name)?.close();
92
+ this._connections.delete(name);
93
+ }
94
+ else {
95
+ for (const [, conn] of this._connections)
96
+ conn.close();
97
+ this._connections.clear();
98
+ }
99
+ }
100
+ // ─── Proxy methods delegating to the default connection ───
101
+ /** @see {@link Redis.get} */
102
+ get(key) { return this.connection().get(key); }
103
+ /** @see {@link Redis.set} */
104
+ set(key, value) { return this.connection().set(key, value); }
105
+ /** @see {@link Redis.del} */
106
+ del(...keys) { return this.connection().del(...keys); }
107
+ /** @see {@link Redis.exists} */
108
+ exists(key) { return this.connection().exists(key); }
109
+ /** @see {@link Redis.incr} */
110
+ incr(key) { return this.connection().incr(key); }
111
+ /** @see {@link Redis.decr} */
112
+ decr(key) { return this.connection().decr(key); }
113
+ /** @see {@link Redis.expire} */
114
+ expire(key, seconds) { return this.connection().expire(key, seconds); }
115
+ /** @see {@link Redis.ttl} */
116
+ ttl(key) { return this.connection().ttl(key); }
117
+ /** @see {@link Redis.hget} */
118
+ hget(key, field) { return this.connection().hget(key, field); }
119
+ /** @see {@link Redis.hmset} */
120
+ hmset(key, fields) { return this.connection().hmset(key, fields); }
121
+ /** @see {@link Redis.hmget} */
122
+ hmget(key, fields) { return this.connection().hmget(key, fields); }
123
+ /** @see {@link Redis.hincrby} */
124
+ hincrby(key, field, increment) { return this.connection().hincrby(key, field, increment); }
125
+ /** @see {@link Redis.sadd} */
126
+ sadd(key, ...members) { return this.connection().sadd(key, ...members); }
127
+ /** @see {@link Redis.srem} */
128
+ srem(key, ...members) { return this.connection().srem(key, ...members); }
129
+ /** @see {@link Redis.sismember} */
130
+ sismember(key, member) { return this.connection().sismember(key, member); }
131
+ /** @see {@link Redis.smembers} */
132
+ smembers(key) { return this.connection().smembers(key); }
133
+ /** @see {@link Redis.publish} */
134
+ publish(channel, message) { return this.connection().publish(channel, message); }
135
+ /** @see {@link Redis.subscribe} */
136
+ subscribe(channel, callback) { return this.connection().subscribe(channel, callback); }
137
+ /** @see {@link Redis.unsubscribe} */
138
+ unsubscribe(channel) { return this.connection().unsubscribe(channel); }
139
+ /** @see {@link Redis.send} */
140
+ send(command, args = []) { return this.connection().send(command, args); }
141
+ /** @see {@link Redis.getJSON} */
142
+ getJSON(key) { return this.connection().getJSON(key); }
143
+ /** @see {@link Redis.setJSON} */
144
+ setJSON(key, value, expireSeconds) { return this.connection().setJSON(key, value, expireSeconds); }
145
+ /** @see {@link Redis.remember} */
146
+ remember(key, seconds, callback) { return this.connection().remember(key, seconds, callback); }
147
+ /** @see {@link Redis.flushdb} */
148
+ flushdb() { return this.connection().flushdb(); }
149
+ /** @see {@link Redis.connected} */
150
+ get connected() { return this.connection().connected; }
151
+ /** @see {@link Redis.getClient} */
152
+ getClient() { return this.connection().getClient(); }
153
+ }
@@ -0,0 +1,20 @@
1
+ import type { App } from '@tekir/core';
2
+ /**
3
+ * Service provider that reads the `redis` configuration and registers
4
+ * a {@link RedisManager} instance in the application container.
5
+ */
6
+ export declare class RedisProvider {
7
+ /**
8
+ * Register the Redis manager into the application container.
9
+ *
10
+ * @param app - The Tekir application instance.
11
+ * @returns A promise that resolves once registration is complete.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * // In your providers list:
16
+ * app.register(new RedisProvider())
17
+ * ```
18
+ */
19
+ register(app: App): Promise<void>;
20
+ }
@@ -0,0 +1,25 @@
1
+ import { RedisManager } from './manager';
2
+ /**
3
+ * Service provider that reads the `redis` configuration and registers
4
+ * a {@link RedisManager} instance in the application container.
5
+ */
6
+ export class RedisProvider {
7
+ /**
8
+ * Register the Redis manager into the application container.
9
+ *
10
+ * @param app - The Tekir application instance.
11
+ * @returns A promise that resolves once registration is complete.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * // In your providers list:
16
+ * app.register(new RedisProvider())
17
+ * ```
18
+ */
19
+ async register(app) {
20
+ const config = app.use('config');
21
+ if (!config('redis'))
22
+ return;
23
+ app.instance('redis', new RedisManager(config('redis')));
24
+ }
25
+ }
@@ -0,0 +1,272 @@
1
+ import type { RedisConnectionConfig } from './types';
2
+ /**
3
+ * Redis client wrapper around Bun's native RedisClient.
4
+ *
5
+ * Provides a high-level API for string, hash, set, and pub/sub operations,
6
+ * plus JSON helpers and a cache-aside `remember` method.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * const redis = new Redis({ url: 'redis://localhost:6379', prefix: 'app:' })
11
+ * await redis.set('greeting', 'hello')
12
+ * const val = await redis.get('greeting') // 'hello'
13
+ * ```
14
+ */
15
+ export declare class Redis {
16
+ private client;
17
+ private prefix;
18
+ private config;
19
+ /**
20
+ * @param config - Redis connection configuration.
21
+ */
22
+ constructor(config?: RedisConnectionConfig);
23
+ private key;
24
+ /**
25
+ * Open the connection to the Redis server.
26
+ *
27
+ * @returns A promise that resolves once the connection is established.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * await redis.connect()
32
+ * ```
33
+ */
34
+ connect(): Promise<void>;
35
+ /**
36
+ * Close the connection to the Redis server.
37
+ */
38
+ close(): void;
39
+ /**
40
+ * Whether the client is currently connected to Redis.
41
+ *
42
+ * @returns `true` if the connection is active.
43
+ */
44
+ get connected(): boolean;
45
+ /**
46
+ * Get the value of a key.
47
+ *
48
+ * @param key - The key to retrieve.
49
+ * @returns The string value, or `null` if the key does not exist.
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * const val = await redis.get('name') // 'Alice' | null
54
+ * ```
55
+ */
56
+ get(key: string): Promise<string | null>;
57
+ /**
58
+ * Set the value of a key.
59
+ *
60
+ * @param key - The key to set.
61
+ * @param value - The string or numeric value to store.
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * await redis.set('counter', 42)
66
+ * ```
67
+ */
68
+ set(key: string, value: string | number): Promise<void>;
69
+ /**
70
+ * Delete one or more keys.
71
+ *
72
+ * @param keys - The keys to delete.
73
+ *
74
+ * @example
75
+ * ```ts
76
+ * await redis.del('key1', 'key2')
77
+ * ```
78
+ */
79
+ del(...keys: string[]): Promise<void>;
80
+ /**
81
+ * Check whether a key exists.
82
+ *
83
+ * @param key - The key to check.
84
+ * @returns `true` if the key exists.
85
+ */
86
+ exists(key: string): Promise<boolean>;
87
+ /**
88
+ * Increment the integer value of a key by one.
89
+ *
90
+ * @param key - The key to increment.
91
+ * @returns The new value after incrementing.
92
+ */
93
+ incr(key: string): Promise<number>;
94
+ /**
95
+ * Decrement the integer value of a key by one.
96
+ *
97
+ * @param key - The key to decrement.
98
+ * @returns The new value after decrementing.
99
+ */
100
+ decr(key: string): Promise<number>;
101
+ /**
102
+ * Set a timeout on a key (in seconds).
103
+ *
104
+ * @param key - The key to set the expiry on.
105
+ * @param seconds - Time-to-live in seconds.
106
+ */
107
+ expire(key: string, seconds: number): Promise<void>;
108
+ /**
109
+ * Get the remaining time-to-live of a key in seconds.
110
+ *
111
+ * @param key - The key to query.
112
+ * @returns Remaining TTL in seconds, `-1` if no expiry is set, `-2` if the key does not exist.
113
+ */
114
+ ttl(key: string): Promise<number>;
115
+ /**
116
+ * Get the value of a single field in a hash.
117
+ *
118
+ * @param key - The hash key.
119
+ * @param field - The field name within the hash.
120
+ * @returns The field value, or `null` if the field or key does not exist.
121
+ */
122
+ hget(key: string, field: string): Promise<string | null>;
123
+ /**
124
+ * Set multiple field-value pairs in a hash.
125
+ *
126
+ * @param key - The hash key.
127
+ * @param fields - An array of alternating field names and values (e.g. `['f1', 'v1', 'f2', 'v2']`).
128
+ */
129
+ hmset(key: string, fields: string[]): Promise<void>;
130
+ /**
131
+ * Get the values of multiple fields in a hash.
132
+ *
133
+ * @param key - The hash key.
134
+ * @param fields - An array of field names to retrieve.
135
+ * @returns An array of values corresponding to the requested fields (`null` for missing fields).
136
+ */
137
+ hmget(key: string, fields: string[]): Promise<(string | null)[]>;
138
+ /**
139
+ * Increment a numeric field in a hash by a given amount.
140
+ *
141
+ * @param key - The hash key.
142
+ * @param field - The field name to increment.
143
+ * @param increment - The integer amount to add.
144
+ * @returns The new value of the field after incrementing.
145
+ */
146
+ hincrby(key: string, field: string, increment: number): Promise<number>;
147
+ /**
148
+ * Add one or more members to a set.
149
+ *
150
+ * @param key - The set key.
151
+ * @param members - The members to add.
152
+ * @returns The number of members that were added (excluding already-present members).
153
+ */
154
+ sadd(key: string, ...members: string[]): Promise<number>;
155
+ /**
156
+ * Remove one or more members from a set.
157
+ *
158
+ * @param key - The set key.
159
+ * @param members - The members to remove.
160
+ * @returns The number of members that were removed.
161
+ */
162
+ srem(key: string, ...members: string[]): Promise<number>;
163
+ /**
164
+ * Check whether a value is a member of a set.
165
+ *
166
+ * @param key - The set key.
167
+ * @param member - The value to check for.
168
+ * @returns `true` if the member exists in the set.
169
+ */
170
+ sismember(key: string, member: string): Promise<boolean>;
171
+ /**
172
+ * Get all members of a set.
173
+ *
174
+ * @param key - The set key.
175
+ * @returns An array of all members in the set.
176
+ */
177
+ smembers(key: string): Promise<string[]>;
178
+ /**
179
+ * Publish a message to a channel.
180
+ *
181
+ * @param channel - The channel name.
182
+ * @param message - The message string to publish.
183
+ */
184
+ publish(channel: string, message: string): Promise<void>;
185
+ /**
186
+ * Subscribe to a channel and receive messages via a callback.
187
+ *
188
+ * @param channel - The channel name to subscribe to.
189
+ * @param callback - Invoked for each message received on the channel.
190
+ *
191
+ * @example
192
+ * ```ts
193
+ * await redis.subscribe('events', (msg, ch) => {
194
+ * console.log(`Received on ${ch}: ${msg}`)
195
+ * })
196
+ * ```
197
+ */
198
+ subscribe(channel: string, callback: (message: string, channel: string) => void): Promise<void>;
199
+ /**
200
+ * Unsubscribe from a channel, or from all channels if none is specified.
201
+ *
202
+ * @param channel - The channel to unsubscribe from. Omit to unsubscribe from all.
203
+ */
204
+ unsubscribe(channel?: string): Promise<void>;
205
+ /**
206
+ * Send a raw Redis command.
207
+ *
208
+ * @param command - The Redis command string (e.g. `'PING'`, `'INFO'`).
209
+ * @param args - Arguments for the command.
210
+ * @returns The raw response from Redis.
211
+ *
212
+ * @example
213
+ * ```ts
214
+ * const pong = await redis.send('PING') // 'PONG'
215
+ * ```
216
+ */
217
+ send(command: string, args?: string[]): Promise<any>;
218
+ /**
219
+ * Get a value from Redis and parse it as JSON.
220
+ *
221
+ * @param key - The key to retrieve.
222
+ * @returns The parsed object, or `null` if the key does not exist or parsing fails.
223
+ *
224
+ * @example
225
+ * ```ts
226
+ * const user = await redis.getJSON<{ name: string }>('user:1')
227
+ * ```
228
+ */
229
+ getJSON<T = any>(key: string): Promise<T | null>;
230
+ /**
231
+ * Serialize a value as JSON and store it in Redis, with an optional TTL.
232
+ *
233
+ * @param key - The key to store the value under.
234
+ * @param value - The value to JSON-serialize and store.
235
+ * @param expireSeconds - Optional time-to-live in seconds.
236
+ *
237
+ * @example
238
+ * ```ts
239
+ * await redis.setJSON('user:1', { name: 'Alice' }, 3600)
240
+ * ```
241
+ */
242
+ setJSON(key: string, value: any, expireSeconds?: number): Promise<void>;
243
+ /**
244
+ * Cache-aside helper: return the cached value if it exists, otherwise execute
245
+ * the callback, store the result in Redis with a TTL, and return it.
246
+ *
247
+ * @param key - The cache key.
248
+ * @param seconds - Time-to-live in seconds for the cached value.
249
+ * @param callback - Async function invoked to compute the value on a cache miss.
250
+ * @returns The cached or freshly computed value.
251
+ *
252
+ * @example
253
+ * ```ts
254
+ * const users = await redis.remember('all-users', 60, async () => {
255
+ * return db.query('SELECT * FROM users')
256
+ * })
257
+ * ```
258
+ */
259
+ remember<T>(key: string, seconds: number, callback: () => Promise<T>): Promise<T>;
260
+ /**
261
+ * Delete all keys in the currently selected database.
262
+ *
263
+ * @returns A promise that resolves once the database has been flushed.
264
+ */
265
+ flushdb(): Promise<void>;
266
+ /**
267
+ * Get the underlying Bun `RedisClient` instance for advanced operations.
268
+ *
269
+ * @returns The raw Bun RedisClient.
270
+ */
271
+ getClient(): any;
272
+ }