@enterprisestandard/redis 0.0.13 → 0.0.14-beta.20260331.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/README.md +43 -1
- package/dist/index.d.ts +18 -3
- package/dist/index.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @enterprisestandard/redis
|
|
2
2
|
|
|
3
|
-
redis (node-redis) adapter and Redis stores for Enterprise Standard. Includes **createRedisAdapter** (v5, default)
|
|
3
|
+
redis (node-redis) adapter and Redis stores for Enterprise Standard. Includes **createRedisAdapter** (v5, default), **createRedisAdapterV4** (v4), and **`esRedis(...)`** for secret-backed reactive Redis connections. Install this package; redis is included. You do not need to install `@enterprisestandard/redis-core` separately.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -8,6 +8,48 @@ redis (node-redis) adapter and Redis stores for Enterprise Standard. Includes **
|
|
|
8
8
|
bun add @enterprisestandard/redis
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
## Secret-backed reactive Redis
|
|
12
|
+
|
|
13
|
+
Use **`esRedis(path, secrets?)`** when the Redis connection details arrive from `es.secrets` and may rotate over time.
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { enterpriseStandard, envConfig } from '@enterprisestandard/server';
|
|
17
|
+
import { createValidators } from '@enterprisestandard/zod';
|
|
18
|
+
import { esRedis, RedisSessionStore, RedisUserStore } from '@enterprisestandard/redis';
|
|
19
|
+
|
|
20
|
+
const redis = esRedis('examples:sso:redis');
|
|
21
|
+
|
|
22
|
+
export const es = enterpriseStandard(envConfig(), {
|
|
23
|
+
validators: createValidators(),
|
|
24
|
+
secrets: {
|
|
25
|
+
redis: {},
|
|
26
|
+
},
|
|
27
|
+
stores: {
|
|
28
|
+
sessionStore: new RedisSessionStore({ redis }),
|
|
29
|
+
userStore: new RedisUserStore({ redis }),
|
|
30
|
+
},
|
|
31
|
+
async afterChange(es) {
|
|
32
|
+
redis.configure(es.secrets);
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Notes:
|
|
38
|
+
|
|
39
|
+
- The first argument is the **secret path**. By default `esRedis(...)` reads from the named secrets source **`redis`**; override that with `esRedis(path, secrets, { sourceName })` when needed.
|
|
40
|
+
- The secret payload should be a node-redis client options object. A top-level **`url`** or **`redisUrl`** field is the simplest shape.
|
|
41
|
+
- `configure(es.secrets)` re-subscribes to the latest secrets source instance. Store operations wait for the first configured connection, so you can construct stores synchronously and use `ready()` only when you want an explicit startup or health-check barrier.
|
|
42
|
+
|
|
43
|
+
## Shared env-based adapter
|
|
44
|
+
|
|
45
|
+
Use **`getSharedRedisAdapter()`** when you only want one process-wide adapter from `REDIS_URL` without secret reactivity:
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { getSharedRedisAdapter } from '@enterprisestandard/redis';
|
|
49
|
+
|
|
50
|
+
const redis = await getSharedRedisAdapter();
|
|
51
|
+
```
|
|
52
|
+
|
|
11
53
|
For **createRedisAdapterV4** only, also install redis v4:
|
|
12
54
|
|
|
13
55
|
```bash
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { RedisAdapter as
|
|
2
|
-
import { getKeyPrefix, getLogger, isRedisVersionSupported, prefixedKey, RedisGroupStore, RedisMagicLinkStore, RedisSessionStore, RedisStoreOptions, RedisTenantStore, RedisUserStore, RedisWorkloadTokenStore, supportsSortedSetList } from "@enterprisestandard/redis-core";
|
|
1
|
+
import { RedisAdapter as RedisAdapter3 } from "@enterprisestandard/redis-core";
|
|
2
|
+
import { createReactiveRedis, getKeyPrefix, getLogger, isRedisVersionSupported, prefixedKey, ReactiveRedisAdapter as ReactiveRedisAdapter2, ReactiveRedisClient, ReactiveRedisOptions, RedisGroupStore, RedisMagicLinkStore, RedisSessionStore, RedisStoreOptions, RedisTenantStore, RedisUserStore, RedisWorkloadTokenStore, supportsSortedSetList } from "@enterprisestandard/redis-core";
|
|
3
3
|
import { createClient } from "redis";
|
|
4
4
|
import { RedisAdapter } from "@enterprisestandard/redis-core";
|
|
5
5
|
/**
|
|
@@ -60,4 +60,19 @@ declare function createRedisAdapter(client: NodeRedisV5Client): RedisAdapter;
|
|
|
60
60
|
* Install redis@^4 if you use this. Prefer createRedisAdapter (v5) when possible.
|
|
61
61
|
*/
|
|
62
62
|
declare function createRedisAdapterV4(client: NodeRedisV4Client): RedisAdapter;
|
|
63
|
-
|
|
63
|
+
import { Logger, Secrets, SecretsOperationOptions } from "@enterprisestandard/core";
|
|
64
|
+
import { ReactiveRedisAdapter } from "@enterprisestandard/redis-core";
|
|
65
|
+
import { RedisClientOptions } from "redis";
|
|
66
|
+
type ESRedisSecret = RedisClientOptions & {
|
|
67
|
+
redisUrl?: string;
|
|
68
|
+
clientOptions?: RedisClientOptions;
|
|
69
|
+
};
|
|
70
|
+
type ESRedisOptions = {
|
|
71
|
+
sourceName?: string;
|
|
72
|
+
logger?: Logger;
|
|
73
|
+
secretOptions?: SecretsOperationOptions;
|
|
74
|
+
};
|
|
75
|
+
declare function esRedis(path: string, secrets?: Secrets, options?: ESRedisOptions): ReactiveRedisAdapter;
|
|
76
|
+
import { RedisAdapter as RedisAdapter2 } from "@enterprisestandard/redis-core";
|
|
77
|
+
declare function getSharedRedisAdapter(): Promise<RedisAdapter2>;
|
|
78
|
+
export { supportsSortedSetList, prefixedKey, isRedisVersionSupported, getSharedRedisAdapter, getLogger, getKeyPrefix, esRedis, createRedisAdapterV4, createRedisAdapter, createReactiveRedis, createClient, RedisWorkloadTokenStore, RedisUserStore, RedisTenantStore, RedisStoreOptions, RedisSessionStore, RedisMagicLinkStore, RedisGroupStore, RedisAdapter3 as RedisAdapter, ReactiveRedisOptions, ReactiveRedisClient, ReactiveRedisAdapter2 as ReactiveRedisAdapter, NodeRedisV5Client, NodeRedisV4Client, ESRedisSecret, ESRedisOptions };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getKeyPrefix as
|
|
1
|
+
import{createReactiveRedis as K,getKeyPrefix as T,getLogger as j,isRedisVersionSupported as z,prefixedKey as D,RedisGroupStore as G,RedisMagicLinkStore as M,RedisSessionStore as W,RedisTenantStore as _,RedisUserStore as B,RedisWorkloadTokenStore as F,supportsSortedSetList as H}from"@enterprisestandard/redis-core";import{createClient as J}from"redis";function s(o){if(typeof o==="string"){let r=/redis_version:([^\r\n]+)/.exec(o);return r?r[1].trim():null}if(o!=null&&typeof o==="object"&&"redis_version"in o){let r=o.redis_version;return typeof r==="string"?r.trim():null}return null}function p(o){return{async get(r){return o.get(r)},async set(r,t){await o.set(r,t)},async setex(r,t,d){await o.setEx(r,t,d)},async del(r){await o.del(r)},async sadd(r,...t){if(t.length>0)await o.sAdd(r,t)},async srem(r,...t){if(t.length>0)await o.sRem(r,t)},async smembers(r){let t=await o.sMembers(r);return Array.from(t)},async mget(r){if(r.length===0)return[];return(await o.mGet(r)).map((d)=>d??null)},async zadd(r,t,d){await o.zAdd(r,{score:t,value:d})},async zrem(r,...t){if(t.length>0)await o.zRem(r,t)},async zrange(r,t,d,i){let e=i?await o.zRange(r,t,d,{REV:!0}):await o.zRange(r,t,d);return Array.isArray(e)?e:[]},async zcard(r){return o.zCard(r)},async getRedisVersion(){let r=await o.info("server");return s(r)}}}function R(o){return{async get(r){return o.get(r)},async set(r,t){await o.set(r,t)},async setex(r,t,d){await o.setEx(r,t,d)},async del(r){await o.del(r)},async sadd(r,...t){if(t.length>0)await o.sAdd(r,t)},async srem(r,...t){if(t.length>0)await o.sRem(r,t)},async smembers(r){let t=await o.sMembers(r);return Array.from(t)},async mget(r){if(r.length===0)return[];return(await o.mGet(r)).map((d)=>d??null)},async zadd(r,t,d){await o.zAdd(r,{score:t,value:d})},async zrem(r,...t){if(t.length>0)await o.zRem(r,t)},async zrange(r,t,d,i){let e=i?await o.zRange(r,t,d,{REV:!0}):await o.zRange(r,t,d);return Array.isArray(e)?e:[]},async zcard(r){return o.zCard(r)},async getRedisVersion(){let r=await o.info("server");return s(r)}}}import{createReactiveRedis as a}from"@enterprisestandard/redis-core";import{createClient as S}from"redis";function g(o){return typeof o==="object"&&o!==null&&!Array.isArray(o)}function O(o){let r=g(o.clientOptions)?{...o.clientOptions}:{...o};delete r.redisUrl,delete r.clientOptions;let t=typeof o.redisUrl==="string"?o.redisUrl.trim():"";if(t)r.url=t;return r}async function u(o){if(typeof o.quit==="function"){await o.quit();return}if(typeof o.disconnect==="function"){await o.disconnect();return}o.destroy?.()}function C(o,r,t={}){return a({path:o,secrets:r,sourceName:t.sourceName,logger:t.logger,secretOptions:t.secretOptions,async createClient(d){let i=S(O(d.data));return i.on?.("error",(e)=>{t.logger?.warn?.("Reactive node-redis client error",{path:o,sourceName:t.sourceName??"redis",error:e.message})}),await i.connect(),{adapter:p(i),dispose:async()=>{await u(i)}}}})}import{createClient as f}from"redis";var n;async function A(){return n??=(async()=>{let o=process.env.REDIS_URL?.trim()||"redis://localhost:6379",r=f({url:o});return await r.connect(),p(r)})(),n}export{H as supportsSortedSetList,D as prefixedKey,z as isRedisVersionSupported,A as getSharedRedisAdapter,j as getLogger,T as getKeyPrefix,C as esRedis,R as createRedisAdapterV4,p as createRedisAdapter,K as createReactiveRedis,J as createClient,F as RedisWorkloadTokenStore,B as RedisUserStore,_ as RedisTenantStore,W as RedisSessionStore,M as RedisMagicLinkStore,G as RedisGroupStore};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enterprisestandard/redis",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14-beta.20260331.2",
|
|
4
4
|
"description": "redis (node-redis) adapter and Redis stores for Enterprise Standard. Includes createRedisAdapter (v5) and createRedisAdapterV4 (v4). Install this; redis is included.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "enterprisestandard",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"./package.json": "./package.json"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@enterprisestandard/redis-core": "
|
|
24
|
+
"@enterprisestandard/redis-core": "0.0.14-beta.20260331.2",
|
|
25
25
|
"redis": "^5.10.0"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|