@enterprisestandard/redis 0.0.16 → 0.0.17-beta.20260501.1
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 +13 -16
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -10,35 +10,32 @@ bun add @enterprisestandard/redis
|
|
|
10
10
|
|
|
11
11
|
## Secret-backed reactive Redis
|
|
12
12
|
|
|
13
|
-
Use **`esRedis(path,
|
|
13
|
+
Use **`esRedis(source, path, options?)`** when the Redis connection details arrive from `es.secrets` and may rotate over time.
|
|
14
14
|
|
|
15
15
|
```ts
|
|
16
16
|
import { enterpriseStandard, envConfig } from '@enterprisestandard/server';
|
|
17
17
|
import { createValidators } from '@enterprisestandard/zod';
|
|
18
18
|
import { esRedis, RedisSessionStore, RedisUserStore } from '@enterprisestandard/redis';
|
|
19
19
|
|
|
20
|
-
const redis = esRedis('examples:sso:redis');
|
|
21
|
-
|
|
22
20
|
export const es = enterpriseStandard(envConfig(), {
|
|
23
21
|
validators: createValidators(),
|
|
24
22
|
secrets: {
|
|
25
23
|
redis: {},
|
|
26
24
|
},
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
},
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const redis = esRedis(es.secrets.redis, 'examples:sso:redis');
|
|
28
|
+
es.setStores({
|
|
29
|
+
sessionStore: new RedisSessionStore({ redis }),
|
|
30
|
+
userStore: new RedisUserStore({ redis }),
|
|
34
31
|
});
|
|
35
32
|
```
|
|
36
33
|
|
|
37
34
|
Notes:
|
|
38
35
|
|
|
39
|
-
- The first argument is
|
|
36
|
+
- The first argument is a stable `SecretsSource` handle (for example `es.secrets.redis`) and the second is the **secret path**. By default the log label is **`redis`**; override that with `{ sourceName }` when needed.
|
|
40
37
|
- The secret payload should be a node-redis client options object. A top-level **`url`** or **`redisUrl`** field is the simplest shape.
|
|
41
|
-
-
|
|
38
|
+
- The adapter is source-bound at creation time. 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. If the named source is replaced during reconfigure, the adapter closes the old Redis client and reconnects through the updated source handle.
|
|
42
39
|
|
|
43
40
|
## Shared env-based adapter
|
|
44
41
|
|
|
@@ -67,10 +64,10 @@ import {
|
|
|
67
64
|
RedisMagicLinkStore,
|
|
68
65
|
RedisWorkloadTokenStore,
|
|
69
66
|
RedisGroupStore,
|
|
70
|
-
|
|
67
|
+
RedisTenantStore,
|
|
71
68
|
} from '@enterprisestandard/redis';
|
|
72
69
|
|
|
73
|
-
const client = createClient({ url: process.env.REDIS_URL ?? 'redis://localhost:
|
|
70
|
+
const client = createClient({ url: process.env.REDIS_URL ?? 'redis://localhost:3503' });
|
|
74
71
|
await client.connect();
|
|
75
72
|
const redis = createRedisAdapter(client);
|
|
76
73
|
|
|
@@ -79,7 +76,7 @@ const sessionStore = new RedisSessionStore({ redis });
|
|
|
79
76
|
const magicLinkStore = new RedisMagicLinkStore({ redis });
|
|
80
77
|
const workloadTokenStore = new RedisWorkloadTokenStore({ redis });
|
|
81
78
|
const groupStore = new RedisGroupStore({ redis });
|
|
82
|
-
const tenantStore = new
|
|
79
|
+
const tenantStore = new RedisTenantStore({ redis });
|
|
83
80
|
```
|
|
84
81
|
|
|
85
82
|
## Usage (v4)
|
|
@@ -95,7 +92,7 @@ import {
|
|
|
95
92
|
// ...
|
|
96
93
|
} from '@enterprisestandard/redis';
|
|
97
94
|
|
|
98
|
-
const client = createClient({ url: process.env.REDIS_URL ?? 'redis://localhost:
|
|
95
|
+
const client = createClient({ url: process.env.REDIS_URL ?? 'redis://localhost:3503' });
|
|
99
96
|
await client.connect();
|
|
100
97
|
const redis = createRedisAdapterV4(client);
|
|
101
98
|
// ... same store setup
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RedisAdapter as RedisAdapter3 } from "@enterprisestandard/redis-core";
|
|
2
|
-
import { createReactiveRedis, getKeyPrefix, getLogger, isRedisVersionSupported, prefixedKey, ReactiveRedisAdapter as ReactiveRedisAdapter2, ReactiveRedisClient, ReactiveRedisOptions, RedisGroupStore, RedisMagicLinkStore,
|
|
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
|
/**
|
|
@@ -72,7 +72,7 @@ type ESRedisOptions = {
|
|
|
72
72
|
logger?: Logger;
|
|
73
73
|
secretOptions?: SecretsOperationOptions;
|
|
74
74
|
};
|
|
75
|
-
declare function esRedis(
|
|
75
|
+
declare function esRedis(source: SecretsSource, path: string, options?: ESRedisOptions): ReactiveRedisAdapter;
|
|
76
76
|
import { RedisAdapter as RedisAdapter2 } from "@enterprisestandard/redis-core";
|
|
77
77
|
declare function getSharedRedisAdapter(): Promise<RedisAdapter2>;
|
|
78
|
-
export { supportsSortedSetList, prefixedKey, isRedisVersionSupported, getSharedRedisAdapter, getLogger, getKeyPrefix, esRedis, createRedisAdapterV4, createRedisAdapter, createReactiveRedis, createClient, RedisWorkloadTokenStore, RedisUserStore,
|
|
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{createReactiveRedis 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 u(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 O(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({source:o,path:r,sourceName:t.sourceName,logger:t.logger,secretOptions:t.secretOptions,async createClient(d){let i=S(u(d.data));return i.on?.("error",(e)=>{t.logger?.warn?.("Reactive node-redis client error",{path:r,sourceName:t.sourceName??"redis",error:e.message})}),await i.connect(),{adapter:p(i),dispose:async()=>{await O(i)}}}})}import{createClient as f}from"redis";var n;async function A(){return n??=(async()=>{let o=process.env.REDIS_URL?.trim()||"redis://localhost:3503",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.17-beta.20260501.1",
|
|
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.17-beta.20260501.1",
|
|
25
25
|
"redis": "^5.10.0"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|