@wild-framework/cache-redis 0.0.0-stage → 0.2.2
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 +21 -0
- package/README.md +34 -2
- package/dist/driver.d.ts +42 -0
- package/dist/driver.d.ts.map +1 -0
- package/dist/driver.js +92 -0
- package/dist/driver.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/provider.d.ts +24 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +38 -0
- package/dist/provider.js.map +1 -0
- package/package.json +41 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Wild Framework contributors
|
|
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
CHANGED
|
@@ -1,3 +1,35 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @wild-framework/cache-redis
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Redis driver for [Wild Framework](https://github.com/KhandaSoftware/wild-framework)'s cache package.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @wild-framework/cache-redis
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { RedisCacheProvider } from "@wild-framework/cache-redis";
|
|
15
|
+
|
|
16
|
+
RedisCacheProvider.url = process.env.REDIS_URL ?? "redis://localhost:6379";
|
|
17
|
+
RedisCacheProvider.keyPrefix = "app:"; // optional
|
|
18
|
+
|
|
19
|
+
app.register(RedisCacheProvider);
|
|
20
|
+
// … cache is now Redis-backed, resolved via app.resolve(Cache)
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Values are JSON-serialized on write and parsed on read. TTL is in milliseconds.
|
|
24
|
+
|
|
25
|
+
## Integration test
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
REDIS_URL='redis://localhost:6379' pnpm --filter @wild-framework/cache-redis test
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Skips automatically when `REDIS_URL` is not set.
|
|
32
|
+
|
|
33
|
+
## License
|
|
34
|
+
|
|
35
|
+
MIT
|
package/dist/driver.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { CacheDriver } from "@wild-framework/cache";
|
|
2
|
+
import { createClient } from "redis";
|
|
3
|
+
/** A connected node-redis client (or any compatible client). */
|
|
4
|
+
export type RedisClient = ReturnType<typeof createClient>;
|
|
5
|
+
/**
|
|
6
|
+
* Configuration for the Redis cache driver.
|
|
7
|
+
*/
|
|
8
|
+
export interface RedisCacheConfig {
|
|
9
|
+
/** Redis connection string (e.g. `redis://localhost:6379` or `rediss://…`). */
|
|
10
|
+
url?: string;
|
|
11
|
+
/** A pre-connected client — for advanced use or tests. */
|
|
12
|
+
client?: RedisClient;
|
|
13
|
+
/** Optional prefix prepended to every key. */
|
|
14
|
+
keyPrefix?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Redis-backed cache driver implementing `CacheDriver`.
|
|
18
|
+
*
|
|
19
|
+
* Values are serialized to JSON on write and parsed on read, so any
|
|
20
|
+
* JSON-serializable value round-trips. Call `connect()` before use —
|
|
21
|
+
* `RedisCacheProvider` does this on boot.
|
|
22
|
+
*/
|
|
23
|
+
export declare class RedisCacheDriver implements CacheDriver {
|
|
24
|
+
private config;
|
|
25
|
+
private client;
|
|
26
|
+
private connected;
|
|
27
|
+
private ownsClient;
|
|
28
|
+
constructor(config?: RedisCacheConfig);
|
|
29
|
+
connect(): Promise<void>;
|
|
30
|
+
close(): Promise<void>;
|
|
31
|
+
isConnected(): boolean;
|
|
32
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
33
|
+
set<T>(key: string, value: T, ttlMs?: number): Promise<void>;
|
|
34
|
+
delete(key: string): Promise<void>;
|
|
35
|
+
has(key: string): Promise<boolean>;
|
|
36
|
+
flush(): Promise<void>;
|
|
37
|
+
private requireClient;
|
|
38
|
+
private applyPrefix;
|
|
39
|
+
private serialize;
|
|
40
|
+
private deserialize;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=driver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"driver.d.ts","sourceRoot":"","sources":["../src/driver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAErC,gEAAgE;AAChE,MAAM,MAAM,WAAW,G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ON on write and parsed on read, so any
|
|
6
|
+
* JSON-serializable value round-trips. Call `connect()` before use —
|
|
7
|
+
* `RedisCacheProvider` does this on boot.
|
|
8
|
+
*/
|
|
9
|
+
export class RedisCacheDriver {
|
|
10
|
+
config;
|
|
11
|
+
client = null;
|
|
12
|
+
connected = false;
|
|
13
|
+
ownsClient = false;
|
|
14
|
+
constructor(config = {}) {
|
|
15
|
+
this.config = config;
|
|
16
|
+
}
|
|
17
|
+
async connect() {
|
|
18
|
+
if (this.connected)
|
|
19
|
+
return;
|
|
20
|
+
if (this.config.client) {
|
|
21
|
+
this.client = this.config.client;
|
|
22
|
+
this.ownsClient = false;
|
|
23
|
+
if (!this.client.isOpen) {
|
|
24
|
+
await this.client.connect();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
this.client = createClient({ url: this.config.url ?? "redis://localhost:6379" });
|
|
29
|
+
this.ownsClient = true;
|
|
30
|
+
await this.client.connect();
|
|
31
|
+
}
|
|
32
|
+
this.connected = true;
|
|
33
|
+
}
|
|
34
|
+
async close() {
|
|
35
|
+
// Only close clients we created — an injected client is the caller's.
|
|
36
|
+
if (this.client && this.ownsClient && this.client.isOpen) {
|
|
37
|
+
await this.client.quit();
|
|
38
|
+
}
|
|
39
|
+
this.client = null;
|
|
40
|
+
this.connected = false;
|
|
41
|
+
}
|
|
42
|
+
isConnected() {
|
|
43
|
+
return this.connected;
|
|
44
|
+
}
|
|
45
|
+
async get(key) {
|
|
46
|
+
const raw = await this.requireClient().get(this.applyPrefix(key));
|
|
47
|
+
if (raw === null)
|
|
48
|
+
return undefined;
|
|
49
|
+
return this.deserialize(raw);
|
|
50
|
+
}
|
|
51
|
+
async set(key, value, ttlMs) {
|
|
52
|
+
const raw = this.serialize(value);
|
|
53
|
+
const client = this.requireClient();
|
|
54
|
+
if (ttlMs !== undefined) {
|
|
55
|
+
await client.set(this.applyPrefix(key), raw, { PX: ttlMs });
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
await client.set(this.applyPrefix(key), raw);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
async delete(key) {
|
|
62
|
+
await this.requireClient().del(this.applyPrefix(key));
|
|
63
|
+
}
|
|
64
|
+
async has(key) {
|
|
65
|
+
const count = await this.requireClient().exists(this.applyPrefix(key));
|
|
66
|
+
return count === 1;
|
|
67
|
+
}
|
|
68
|
+
async flush() {
|
|
69
|
+
await this.requireClient().flushDb();
|
|
70
|
+
}
|
|
71
|
+
requireClient() {
|
|
72
|
+
if (!this.client || !this.connected) {
|
|
73
|
+
throw new Error("Cache is not connected. Call connect() first.");
|
|
74
|
+
}
|
|
75
|
+
return this.client;
|
|
76
|
+
}
|
|
77
|
+
applyPrefix(key) {
|
|
78
|
+
return this.config.keyPrefix ? `${this.config.keyPrefix}${key}` : key;
|
|
79
|
+
}
|
|
80
|
+
serialize(value) {
|
|
81
|
+
return JSON.stringify(value) ?? "null";
|
|
82
|
+
}
|
|
83
|
+
deserialize(raw) {
|
|
84
|
+
try {
|
|
85
|
+
return JSON.parse(raw);
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return raw;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=driver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"driver.js","sourceRoot":"","sources":["../src/driver.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAiBrC;;;;;;GAMG;AACH,MAAM,OAAO,gBAAgB;IAKL;IAJZ,MAAM,GAAuB,IAAI,CAAC;IAClC,SAAS,GAAG,KAAK,CAAC;IAClB,UAAU,GAAG,KAAK,CAAC;IAE3B,YAAoB,SAA2B,EAAE;QAA7B,WAAM,GAAN,MAAM,CAAuB;IAAG,CAAC;IAErD,KAAK,CAAC,OAAO;QACT,IAAI,IAAI,CAAC,SAAS;YAAE,OAAO;QAE3B,IAAI,IA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,CAAC,MAAM,CAAC,SAAS,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;IAC1E,CAAC;IAEO,SAAS,CAAC,KAAc;QAC5B,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC;IAC3C,CAAC;IAEO,WAAW,CAAI,GAAW;QAC9B,IAAI,CAAC;YACD,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAM,CAAC;QAChC,CAAC;QAAC,MAAM,CAAC;YACL,OAAO,GAAmB,CAAC;QAC/B,CAAC;IACL,CAAC;CACJ"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Provider, Application } from "@wild-framework/core";
|
|
2
|
+
/**
|
|
3
|
+
* Registers a Redis-backed cache with the application.
|
|
4
|
+
*
|
|
5
|
+
* Static configuration (no-arg constructor requirement):
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* RedisCacheProvider.url = process.env.REDIS_URL ?? "redis://localhost:6379";
|
|
9
|
+
* RedisCacheProvider.keyPrefix = "app:";
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* Connects on boot and disconnects on shutdown.
|
|
13
|
+
*/
|
|
14
|
+
export declare class RedisCacheProvider implements Provider {
|
|
15
|
+
/** Redis connection string. Defaults to `redis://localhost:6379`. */
|
|
16
|
+
static url: string | undefined;
|
|
17
|
+
/** Optional prefix prepended to every key. */
|
|
18
|
+
static keyPrefix: string | undefined;
|
|
19
|
+
private driver;
|
|
20
|
+
register(app: Application): void;
|
|
21
|
+
boot(): Promise<void>;
|
|
22
|
+
shutdown(): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAKlE;;;;;;;;;;;GAWG;AACH,qBAAa,kBAAmB,YAAW,QAAQ;IAC/C,qEAAqE;IACrE,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,8CAA8C;IAC9C,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAErC,OAAO,CAAC,MAAM,CAA+B;IAE7C,QAAQ,CAAC,GAAG,EAAE,WAAW,GAAG,IAAI;IAY1B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAIrB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAGlC"}
|
package/dist/provider.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Container } from "@wild-framework/container";
|
|
2
|
+
import { Cache } from "@wild-framework/cache";
|
|
3
|
+
import { RedisCacheDriver } from "./driver.js";
|
|
4
|
+
/**
|
|
5
|
+
* Registers a Redis-backed cache with the application.
|
|
6
|
+
*
|
|
7
|
+
* Static configuration (no-arg constructor requirement):
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* RedisCacheProvider.url = process.env.REDIS_URL ?? "redis://localhost:6379";
|
|
11
|
+
* RedisCacheProvider.keyPrefix = "app:";
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* Connects on boot and disconnects on shutdown.
|
|
15
|
+
*/
|
|
16
|
+
export class RedisCacheProvider {
|
|
17
|
+
/** Redis connection string. Defaults to `redis://localhost:6379`. */
|
|
18
|
+
static url;
|
|
19
|
+
/** Optional prefix prepended to every key. */
|
|
20
|
+
static keyPrefix;
|
|
21
|
+
driver;
|
|
22
|
+
register(app) {
|
|
23
|
+
const container = app.resolve(Container);
|
|
24
|
+
const driver = new RedisCacheDriver({
|
|
25
|
+
url: RedisCacheProvider.url,
|
|
26
|
+
keyPrefix: RedisCacheProvider.keyPrefix,
|
|
27
|
+
});
|
|
28
|
+
this.driver = driver;
|
|
29
|
+
container.singleton(Cache, () => new Cache(driver));
|
|
30
|
+
}
|
|
31
|
+
async boot() {
|
|
32
|
+
await this.driver?.connect();
|
|
33
|
+
}
|
|
34
|
+
async shutdown() {
|
|
35
|
+
await this.driver?.close();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,kBAAkB;IAC3B,qEAAqE;IACrE,MAAM,CAAC,GAAG,CAAqB;IAC/B,8CAA8C;IAC9C,MAAM,CAAC,SAAS,CAAqB;IAE7B,MAAM,CAA+B;IAE7C,QAAQ,CAAC,GAAgB;QACrB,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAEzC,MAAM,MAAM,GAAG,IAAI,gBAAgB,CAAC;YAChC,GAAG,EAAE,kBAAkB,CAAC,GAAG;YAC3B,SAAS,EAAE,kBAAkB,CAAC,SAAS;SAC1C,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,SAAS,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IACxD,CAAC;IAED,KAAK,CAAC,IAAI;QACN,MAAM,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC;IACjC,CAAC;IAED,KAAK,CAAC,QAAQ;QACV,MAAM,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC;IAC/B,CAAC;CACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wild-framework/cache-redis",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"author": "Sphah",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/Khandasoftware/wild-framework.git"
|
|
24
|
+
},
|
|
25
|
+
"description": "Redis cache driver for Wild Framework's cache package (node-redis).",
|
|
26
|
+
"keywords": [
|
|
27
|
+
"wild",
|
|
28
|
+
"framework",
|
|
29
|
+
"cache",
|
|
30
|
+
"redis",
|
|
31
|
+
"ttl"
|
|
32
|
+
],
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"redis": "^4.7.0",
|
|
35
|
+
"@wild-framework/container": "0.2.2",
|
|
36
|
+
"@wild-framework/core": "0.2.2",
|
|
37
|
+
"@wild-framework/cache": "0.2.2"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsc",
|
|
41
|
+
"clean": "rm -rf dist",
|
|
42
|
+
"test": "vitest run"
|
|
43
|
+
}
|
|
6
44
|
}
|