@postgresx/noredis 0.6.1 → 0.7.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 CHANGED
@@ -140,6 +140,18 @@ await cache.persist("token:abc");
140
140
  await cache.touch("token:abc");
141
141
  ```
142
142
 
143
+ Cache, counter, collection, and rate-limit schemas default to PostgreSQL
144
+ `UNLOGGED` tables. They survive a clean restart, but PostgreSQL truncates them
145
+ after crash recovery and does not replicate them to standbys. Use
146
+ `ensureSchema({ unlogged: false })` when those values require WAL-backed
147
+ persistence. The unified client applies the option to every cache-style schema:
148
+
149
+ ```ts
150
+ await pg.ensureSchema({ unlogged: false });
151
+ ```
152
+
153
+ The durable outbox remains logged regardless of this option.
154
+
143
155
  Use `serializer` when values need an application envelope before they are stored
144
156
  as JSONB:
145
157
 
@@ -517,7 +529,7 @@ outbox/stream, list blocking-pop helpers, production metrics, Redis-style
517
529
  aliases, web adapters, and expanded KV write semantics.
518
530
 
519
531
  Follow-up documentation and benchmark candidates are tracked in
520
- the [repository migration examples](https://github.com/zuohuadong/postgresx/blob/main/docs/redis-migration-examples.md):
532
+ the [repository migration examples](https://github.com/vibeunion/postgresx/blob/main/docs/redis-migration-examples.md):
521
533
 
522
534
  1. Redis Streams consumer-group migration patterns for `XREADGROUP`, pending entries, and retries.
523
535
  2. Framework-specific session middleware examples built on the web adapter.
@@ -673,6 +685,16 @@ await cache.persist("token:abc");
673
685
  await cache.touch("token:abc");
674
686
  ```
675
687
 
688
+ 缓存、计数器、集合和限流 schema 默认使用 PostgreSQL `UNLOGGED` 表。它们能在正常重启后保留,
689
+ 但 PostgreSQL 会在崩溃恢复时清空这些表,而且不会把它们复制到备库。需要 WAL 持久化时,请使用
690
+ `ensureSchema({ unlogged: false })`。统一客户端会把该选项应用到全部缓存类 schema:
691
+
692
+ ```ts
693
+ await pg.ensureSchema({ unlogged: false });
694
+ ```
695
+
696
+ durable outbox 不受该选项影响,始终保持 logged。
697
+
676
698
  ## 统一客户端
677
699
 
678
700
  ```ts
@@ -1003,7 +1025,7 @@ Redis 在核心数据类型、服务器操作、可编程性、集群、模块
1003
1025
  10. ~~子模块入口~~ — `kv`、`hash`、`set`、`sorted-set`、`list`、`pubsub` 子路径导出类型化原语。
1004
1026
 
1005
1027
  后续迁移文档和 benchmark 候选项记录在
1006
- [仓库迁移示例](https://github.com/zuohuadong/postgresx/blob/main/docs/redis-migration-examples.md) 中:
1028
+ [仓库迁移示例](https://github.com/vibeunion/postgresx/blob/main/docs/redis-migration-examples.md) 中:
1007
1029
  Redis Streams consumer-group 迁移、session middleware 示例、SQL adapter
1008
1030
  retry/backoff 边界、outbox/list/pipeline benchmark,以及明确非目标。
1009
1031
 
@@ -1,4 +1,4 @@
1
- import { Q as PgredisClient, _ as PipelineFacade, U as PgredisMigrationAliases } from '../client-DP3ssToT.js';
1
+ import { Q as PgredisClient, $ as PipelineFacade, U as PgredisMigrationAliases } from '../client-ChVkyyno.js';
2
2
  import '../kv-cache.js';
3
3
  import '../pubsub-index.js';
4
4
  import '../sql-DKf2TDlu.js';
@@ -1,4 +1,4 @@
1
- import { Q as PgredisClient, _ as PipelineFacade, U as PgredisMigrationAliases } from '../client-DP3ssToT.js';
1
+ import { Q as PgredisClient, $ as PipelineFacade, U as PgredisMigrationAliases } from '../client-ChVkyyno.js';
2
2
  import '../kv-cache.js';
3
3
  import '../pubsub-index.js';
4
4
  import '../sql-DKf2TDlu.js';
@@ -471,6 +471,10 @@ interface PgredisOptions {
471
471
  tableName?: string;
472
472
  };
473
473
  }
474
+ interface PgredisSchemaOptions {
475
+ /** Controls cache-style primitives; the durable outbox always remains logged. */
476
+ unlogged?: boolean;
477
+ }
474
478
  interface PgredisClient {
475
479
  cache: PgKvCache;
476
480
  counter: PgCounter;
@@ -502,8 +506,8 @@ interface PgredisClient {
502
506
  limit?: number;
503
507
  onError?: (error: unknown) => void;
504
508
  }): () => void;
505
- ensureSchema(): Promise<void>;
509
+ ensureSchema(options?: PgredisSchemaOptions): Promise<void>;
506
510
  }
507
511
  declare function createPgredis(options: PgredisOptions): PgredisClient;
508
512
 
509
- export { type RedisSetAliasOptions as $, type PgOutboxStreamSchemaOptions as A, type PgOutboxTrimOptions as B, type PgRateLimitBlockOptions as C, type PgRateLimitHitOptions as D, type PgRateLimitResult as E, type PgRateLimitSchemaOptions as F, type PgRateLimitStateOptions as G, type PgRateLimiterOptions as H, PgSlidingWindowRateLimiter as I, type PgSlidingWindowRateLimiterOptions as J, PgTokenBucketRateLimiter as K, type PgTokenBucketRateLimiterOptions as L, type PgTokenBucketResult as M, type PgredisBatchOperation as N, type PgredisCleanupMetrics as O, PgAdvisoryLockBusyError as P, type PgredisClient as Q, type PgredisListenerMetrics as R, type PgredisMetrics as S, type PgredisMetricsOptions as T, type PgredisMigrationAliases as U, type PgredisOptions as V, PgredisPipeline as W, type PgredisQueueMetrics as X, type PgredisTableMetrics as Y, type PipelineCommand as Z, type PipelineFacade as _, type PgAdvisoryLockKey as a, advisoryLockKeyToSqlArgs as a0, collectPgredisMetrics as a1, createPgAdvisoryLocker as a2, createPgBossJobQueue as a3, createPgCounter as a4, createPgFixedWindowRateLimiter as a5, createPgOutboxStream as a6, createPgSlidingWindowRateLimiter as a7, createPgTokenBucketRateLimiter as a8, createPgredis as a9, createPgredisMigrationAliases as aa, withPgAdvisoryLock as ab, type PgAdvisoryLockOptions as b, PgAdvisoryLocker as c, type PgBossJob as d, PgBossJobQueue as e, type PgBossLike as f, type PgBossOptions as g, type PgBossQueueDefinition as h, type PgBossQueueMap as i, type PgBossQueueOptions as j, type PgBossQueueResult as k, type PgBossSendOptions as l, type PgBossWorkHandler as m, type PgBossWorkOptions as n, PgCounter as o, type PgCounterOptions as p, type PgCounterSchemaOptions as q, type PgCounterSetOptions as r, PgFixedWindowRateLimiter as s, type PgOutboxAppendOptions as t, type PgOutboxClaimOptions as u, type PgOutboxMessage as v, type PgOutboxPendingSummary as w, type PgOutboxReadOptions as x, PgOutboxStream as y, type PgOutboxStreamOptions as z };
513
+ export { type PipelineFacade as $, type PgOutboxStreamSchemaOptions as A, type PgOutboxTrimOptions as B, type PgRateLimitBlockOptions as C, type PgRateLimitHitOptions as D, type PgRateLimitResult as E, type PgRateLimitSchemaOptions as F, type PgRateLimitStateOptions as G, type PgRateLimiterOptions as H, PgSlidingWindowRateLimiter as I, type PgSlidingWindowRateLimiterOptions as J, PgTokenBucketRateLimiter as K, type PgTokenBucketRateLimiterOptions as L, type PgTokenBucketResult as M, type PgredisBatchOperation as N, type PgredisCleanupMetrics as O, PgAdvisoryLockBusyError as P, type PgredisClient as Q, type PgredisListenerMetrics as R, type PgredisMetrics as S, type PgredisMetricsOptions as T, type PgredisMigrationAliases as U, type PgredisOptions as V, PgredisPipeline as W, type PgredisQueueMetrics as X, type PgredisSchemaOptions as Y, type PgredisTableMetrics as Z, type PipelineCommand as _, type PgAdvisoryLockKey as a, type RedisSetAliasOptions as a0, advisoryLockKeyToSqlArgs as a1, collectPgredisMetrics as a2, createPgAdvisoryLocker as a3, createPgBossJobQueue as a4, createPgCounter as a5, createPgFixedWindowRateLimiter as a6, createPgOutboxStream as a7, createPgSlidingWindowRateLimiter as a8, createPgTokenBucketRateLimiter as a9, createPgredis as aa, createPgredisMigrationAliases as ab, withPgAdvisoryLock as ac, type PgAdvisoryLockOptions as b, PgAdvisoryLocker as c, type PgBossJob as d, PgBossJobQueue as e, type PgBossLike as f, type PgBossOptions as g, type PgBossQueueDefinition as h, type PgBossQueueMap as i, type PgBossQueueOptions as j, type PgBossQueueResult as k, type PgBossSendOptions as l, type PgBossWorkHandler as m, type PgBossWorkOptions as n, PgCounter as o, type PgCounterOptions as p, type PgCounterSchemaOptions as q, type PgCounterSetOptions as r, PgFixedWindowRateLimiter as s, type PgOutboxAppendOptions as t, type PgOutboxClaimOptions as u, type PgOutboxMessage as v, type PgOutboxPendingSummary as w, type PgOutboxReadOptions as x, PgOutboxStream as y, type PgOutboxStreamOptions as z };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { BunSqlLike, PgKvCache, PgKvCacheInvalidationOptions, PgKvCacheL1Options, PgKvCacheListenerFactory, PgKvCacheListenerFactoryOptions, PgKvCacheNotifyOptions, PgKvCacheOptions, PgKvCacheStats, PgKvNotification, PgKvSchemaOptions, PgKvSetOptions, createPgKvCache } from './kv-cache.js';
2
- export { d as Job, P as PgAdvisoryLockBusyError, a as PgAdvisoryLockKey, b as PgAdvisoryLockOptions, c as PgAdvisoryLocker, f as PgBoss, d as PgBossJob, e as PgBossJobQueue, f as PgBossLike, g as PgBossOptions, h as PgBossQueueDefinition, i as PgBossQueueMap, j as PgBossQueueOptions, k as PgBossQueueResult, l as PgBossSendOptions, m as PgBossWorkHandler, n as PgBossWorkOptions, o as PgCounter, p as PgCounterOptions, q as PgCounterSchemaOptions, r as PgCounterSetOptions, s as PgFixedWindowRateLimiter, t as PgOutboxAppendOptions, u as PgOutboxClaimOptions, v as PgOutboxMessage, w as PgOutboxPendingSummary, x as PgOutboxReadOptions, y as PgOutboxStream, z as PgOutboxStreamOptions, A as PgOutboxStreamSchemaOptions, B as PgOutboxTrimOptions, C as PgRateLimitBlockOptions, D as PgRateLimitHitOptions, E as PgRateLimitResult, F as PgRateLimitSchemaOptions, G as PgRateLimitStateOptions, H as PgRateLimiterOptions, I as PgSlidingWindowRateLimiter, J as PgSlidingWindowRateLimiterOptions, K as PgTokenBucketRateLimiter, L as PgTokenBucketRateLimiterOptions, M as PgTokenBucketResult, N as PgredisBatchOperation, O as PgredisCleanupMetrics, Q as PgredisClient, R as PgredisListenerMetrics, S as PgredisMetrics, T as PgredisMetricsOptions, U as PgredisMigrationAliases, V as PgredisOptions, W as PgredisPipeline, X as PgredisQueueMetrics, Y as PgredisTableMetrics, Z as PipelineCommand, _ as PipelineFacade, h as Queue, k as QueueResult, $ as RedisSetAliasOptions, l as SendOptions, m as WorkHandler, n as WorkOptions, a0 as advisoryLockKeyToSqlArgs, a1 as collectPgredisMetrics, a2 as createPgAdvisoryLocker, a3 as createPgBossJobQueue, a4 as createPgCounter, a5 as createPgFixedWindowRateLimiter, a6 as createPgOutboxStream, a7 as createPgSlidingWindowRateLimiter, a8 as createPgTokenBucketRateLimiter, a9 as createPgredis, aa as createPgredisMigrationAliases, ab as withPgAdvisoryLock } from './client-DP3ssToT.js';
2
+ export { d as Job, P as PgAdvisoryLockBusyError, a as PgAdvisoryLockKey, b as PgAdvisoryLockOptions, c as PgAdvisoryLocker, f as PgBoss, d as PgBossJob, e as PgBossJobQueue, f as PgBossLike, g as PgBossOptions, h as PgBossQueueDefinition, i as PgBossQueueMap, j as PgBossQueueOptions, k as PgBossQueueResult, l as PgBossSendOptions, m as PgBossWorkHandler, n as PgBossWorkOptions, o as PgCounter, p as PgCounterOptions, q as PgCounterSchemaOptions, r as PgCounterSetOptions, s as PgFixedWindowRateLimiter, t as PgOutboxAppendOptions, u as PgOutboxClaimOptions, v as PgOutboxMessage, w as PgOutboxPendingSummary, x as PgOutboxReadOptions, y as PgOutboxStream, z as PgOutboxStreamOptions, A as PgOutboxStreamSchemaOptions, B as PgOutboxTrimOptions, C as PgRateLimitBlockOptions, D as PgRateLimitHitOptions, E as PgRateLimitResult, F as PgRateLimitSchemaOptions, G as PgRateLimitStateOptions, H as PgRateLimiterOptions, I as PgSlidingWindowRateLimiter, J as PgSlidingWindowRateLimiterOptions, K as PgTokenBucketRateLimiter, L as PgTokenBucketRateLimiterOptions, M as PgTokenBucketResult, N as PgredisBatchOperation, O as PgredisCleanupMetrics, Q as PgredisClient, R as PgredisListenerMetrics, S as PgredisMetrics, T as PgredisMetricsOptions, U as PgredisMigrationAliases, V as PgredisOptions, W as PgredisPipeline, X as PgredisQueueMetrics, Y as PgredisSchemaOptions, Z as PgredisTableMetrics, _ as PipelineCommand, $ as PipelineFacade, h as Queue, k as QueueResult, a0 as RedisSetAliasOptions, l as SendOptions, m as WorkHandler, n as WorkOptions, a1 as advisoryLockKeyToSqlArgs, a2 as collectPgredisMetrics, a3 as createPgAdvisoryLocker, a4 as createPgBossJobQueue, a5 as createPgCounter, a6 as createPgFixedWindowRateLimiter, a7 as createPgOutboxStream, a8 as createPgSlidingWindowRateLimiter, a9 as createPgTokenBucketRateLimiter, aa as createPgredis, ab as createPgredisMigrationAliases, ac as withPgAdvisoryLock } from './client-ChVkyyno.js';
3
3
  export { PgHash, PgHashOptions, PgHashScanResult, PgHashSchemaOptions, createPgHash } from './hash-index.js';
4
4
  export { PgList, PgListBlockingPopOptions, PgListBlockingPopResult, PgListOptions, PgListScanResult, PgListSchemaOptions, createPgList } from './list-index.js';
5
5
  export { NotifyHandler, PgListenerEvents, PgListenerHandle, PgListenerHealth, PgListenerOptions, PgNotifyPayload, PgPublisher, createBunPgListener, createPgListener, createPgPublisher, publishPgNotify } from './pubsub-index.js';
package/dist/index.js CHANGED
@@ -1159,15 +1159,15 @@ function createPgredis(options) {
1159
1159
  }, intervalMs);
1160
1160
  return () => clearInterval(timer);
1161
1161
  },
1162
- async ensureSchema() {
1163
- await cache.ensureSchema();
1164
- await counter.ensureSchema();
1165
- await hash.ensureSchema();
1166
- await set.ensureSchema();
1167
- await list.ensureSchema();
1168
- await sortedSet.ensureSchema();
1162
+ async ensureSchema(schemaOptions = {}) {
1163
+ await cache.ensureSchema(schemaOptions);
1164
+ await counter.ensureSchema(schemaOptions);
1165
+ await hash.ensureSchema(schemaOptions);
1166
+ await set.ensureSchema(schemaOptions);
1167
+ await list.ensureSchema(schemaOptions);
1168
+ await sortedSet.ensureSchema(schemaOptions);
1169
1169
  await outbox.ensureSchema();
1170
- if (rateLimit) await rateLimit.ensureSchema();
1170
+ if (rateLimit) await rateLimit.ensureSchema(schemaOptions);
1171
1171
  }
1172
1172
  };
1173
1173
  client.redis = createPgredisMigrationAliases(client);
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@postgresx/noredis",
3
- "version": "0.6.1",
3
+ "version": "0.7.1",
4
4
  "description": "PostgreSQL-backed Redis feature replacement toolkit: KV/TTL cache, pub/sub, advisory locks, rate limiting, and pg-boss queues",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "https://github.com/zuohuadong/postgresx",
9
+ "url": "https://github.com/vibeunion/postgresx",
10
10
  "directory": "packages/pgredis"
11
11
  },
12
12
  "sideEffects": false,
@@ -92,7 +92,7 @@
92
92
  "@types/bun": "^1.3.14",
93
93
  "@types/node": "^25.0.0",
94
94
  "@types/pg": "^8.16.0",
95
- "@postgresx/bun-listen": "^0.3.1",
95
+ "@postgresx/bun-listen": "^0.3.2",
96
96
  "tsup": "^8.5.0",
97
97
  "typescript": "^6.0.3"
98
98
  }