@enterprisestandard/redis 0.0.15-beta.20260407.1 → 0.0.16
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 +6 -6
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ bun add @enterprisestandard/redis
|
|
|
10
10
|
|
|
11
11
|
## Secret-backed reactive Redis
|
|
12
12
|
|
|
13
|
-
Use **`esRedis(path,
|
|
13
|
+
Use **`esRedis(path, source?)`** 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';
|
|
@@ -29,16 +29,16 @@ export const es = enterpriseStandard(envConfig(), {
|
|
|
29
29
|
userStore: new RedisUserStore({ redis }),
|
|
30
30
|
},
|
|
31
31
|
async afterChange(es) {
|
|
32
|
-
redis.configure(es.secrets);
|
|
32
|
+
redis.configure(es.secrets.redis);
|
|
33
33
|
},
|
|
34
34
|
});
|
|
35
35
|
```
|
|
36
36
|
|
|
37
37
|
Notes:
|
|
38
38
|
|
|
39
|
-
- The first argument is the **secret path**.
|
|
39
|
+
- The first argument is the **secret path**. Pass a specific `SecretsSource` as the optional second argument when you want the adapter configured immediately; otherwise call `redis.configure(es.secrets.redis)` (or another named handle) from `afterChange(...)`. By default the log label is **`redis`**; override that with `{ sourceName }` when needed.
|
|
40
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(
|
|
41
|
+
- `configure(source)` binds the adapter to one stable `SecretsSource` handle. 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
42
|
|
|
43
43
|
## Shared env-based adapter
|
|
44
44
|
|
|
@@ -67,7 +67,7 @@ import {
|
|
|
67
67
|
RedisMagicLinkStore,
|
|
68
68
|
RedisWorkloadTokenStore,
|
|
69
69
|
RedisGroupStore,
|
|
70
|
-
|
|
70
|
+
RedisSingleTenantStore,
|
|
71
71
|
} from '@enterprisestandard/redis';
|
|
72
72
|
|
|
73
73
|
const client = createClient({ url: process.env.REDIS_URL ?? 'redis://localhost:6379' });
|
|
@@ -79,7 +79,7 @@ const sessionStore = new RedisSessionStore({ redis });
|
|
|
79
79
|
const magicLinkStore = new RedisMagicLinkStore({ redis });
|
|
80
80
|
const workloadTokenStore = new RedisWorkloadTokenStore({ redis });
|
|
81
81
|
const groupStore = new RedisGroupStore({ redis });
|
|
82
|
-
const tenantStore = new
|
|
82
|
+
const tenantStore = new RedisSingleTenantStore({ redis });
|
|
83
83
|
```
|
|
84
84
|
|
|
85
85
|
## Usage (v4)
|
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, RedisSessionStore,
|
|
2
|
+
import { createReactiveRedis, getKeyPrefix, getLogger, isRedisVersionSupported, prefixedKey, ReactiveRedisAdapter as ReactiveRedisAdapter2, ReactiveRedisClient, ReactiveRedisOptions, RedisGroupStore, RedisMagicLinkStore, RedisMultiTenantStore, RedisSessionStore, RedisSingleTenantStore, RedisStoreOptions, RedisUserStore, RedisWorkloadTokenStore, supportsSortedSetList } from "@enterprisestandard/redis-core";
|
|
3
3
|
import { createClient } from "redis";
|
|
4
4
|
import { RedisAdapter } from "@enterprisestandard/redis-core";
|
|
5
5
|
/**
|
|
@@ -60,7 +60,7 @@ 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
|
-
import { Logger,
|
|
63
|
+
import { Logger, SecretsOperationOptions, SecretsSource } from "@enterprisestandard/core";
|
|
64
64
|
import { ReactiveRedisAdapter } from "@enterprisestandard/redis-core";
|
|
65
65
|
import { RedisClientOptions } from "redis";
|
|
66
66
|
type ESRedisSecret = RedisClientOptions & {
|
|
@@ -72,7 +72,7 @@ type ESRedisOptions = {
|
|
|
72
72
|
logger?: Logger;
|
|
73
73
|
secretOptions?: SecretsOperationOptions;
|
|
74
74
|
};
|
|
75
|
-
declare function esRedis(path: string,
|
|
75
|
+
declare function esRedis(path: string, source?: SecretsSource, 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, RedisStoreOptions, RedisSingleTenantStore, RedisSessionStore, RedisMultiTenantStore, 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 T,getKeyPrefix as K,getLogger as M,isRedisVersionSupported as j,prefixedKey as z,RedisGroupStore as D,RedisMagicLinkStore as G,RedisMultiTenantStore as W,RedisSessionStore as _,RedisSingleTenantStore as B,RedisUserStore as F,RedisWorkloadTokenStore as H,supportsSortedSetList as I}from"@enterprisestandard/redis-core";import{createClient as Q}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({path:o,source: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:o,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:6379",r=f({url:o});return await r.connect(),p(r)})(),n}export{I as supportsSortedSetList,z as prefixedKey,j as isRedisVersionSupported,A as getSharedRedisAdapter,M as getLogger,K as getKeyPrefix,C as esRedis,R as createRedisAdapterV4,p as createRedisAdapter,T as createReactiveRedis,Q as createClient,H as RedisWorkloadTokenStore,F as RedisUserStore,B as RedisSingleTenantStore,_ as RedisSessionStore,W as RedisMultiTenantStore,G as RedisMagicLinkStore,D 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.16",
|
|
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": "0.0.
|
|
24
|
+
"@enterprisestandard/redis-core": "^0.0.16",
|
|
25
25
|
"redis": "^5.10.0"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|