@quark-fw/plugin-redis 0.1.26 → 0.1.28
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/README.md +29 -0
- package/package.json +4 -4
package/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# @quark-fw/plugin-redis
|
|
2
|
+
|
|
3
|
+
Redis (ioredis) client for Quark apps: `quark.redis.client` is an atom holding a lazily connected `Redis` instance, `quark.redis.config` an atom with the connection URL. Sessions (`plugin-auth`), cron locks, the jobs queue, rate limiters and the threads event bridge all share this client.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm i @quark-fw/plugin-redis
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Peer: `@quark-fw/core`. `ioredis` is a dependency.
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import "@quark-fw/plugin-redis"; // provides quark.redis
|
|
17
|
+
|
|
18
|
+
const redis = quark.redis.client.value; // ioredis instance
|
|
19
|
+
await redis.set("key", "value", "EX", 60);
|
|
20
|
+
|
|
21
|
+
// switch connection at runtime: a new client is created, the old one is quit
|
|
22
|
+
quark.redis.config.value = { url: "redis://cache:6379" };
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
How it works: the client is created with `lazyConnect: true` (no connection until the first command), `maxRetriesPerRequest: null`, `family: 4` and a `retryStrategy` of `min(times * 200, 2000)` ms. Read `quark.redis.client.value` where you use it rather than caching it: when `config` changes the plugin replaces the atom value with a new client and quits the old one. `onDestroy` quits the client (falls back to `disconnect()`).
|
|
26
|
+
|
|
27
|
+
Env: `REDIS_URL` (default `redis://127.0.0.1:6379`; in production the internal URL of the Redis service).
|
|
28
|
+
|
|
29
|
+
Part of the [Quark framework](https://www.npmjs.com/package/@quark-fw/core).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quark-fw/plugin-redis",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.28",
|
|
4
4
|
"main": "src/index.ts",
|
|
5
5
|
"types": "src/index.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -21,11 +21,11 @@
|
|
|
21
21
|
"access": "public"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@quark-fw/atom": "0.1.
|
|
25
|
-
"@quark-fw/plugin": "0.1.
|
|
24
|
+
"@quark-fw/atom": "0.1.28",
|
|
25
|
+
"@quark-fw/plugin": "0.1.28",
|
|
26
26
|
"ioredis": "^5.9.3"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
|
-
"@quark-fw/core": "0.1.
|
|
29
|
+
"@quark-fw/core": "0.1.28"
|
|
30
30
|
}
|
|
31
31
|
}
|