@owlmeans/redis-resource 0.1.18-rc.2 → 0.1.18-rc.20
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 +74 -27
- package/agent-meta/manifest.json +2 -2
- package/agent-meta/skills/redis-resource/SKILL.md +96 -31
- package/build/consts.d.ts +20 -1
- package/build/consts.d.ts.map +1 -1
- package/build/consts.js +20 -1
- package/build/consts.js.map +1 -1
- package/build/resource.d.ts +11 -2
- package/build/resource.d.ts.map +1 -1
- package/build/resource.js +243 -217
- package/build/resource.js.map +1 -1
- package/build/types.d.ts +27 -12
- package/build/types.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/consts.ts +27 -2
- package/src/resource.ts +289 -233
- package/src/types.ts +28 -18
- package/build/.gitkeep +0 -0
- package/build/utils/index.d.ts +0 -2
- package/build/utils/index.d.ts.map +0 -1
- package/build/utils/index.js +0 -2
- package/build/utils/index.js.map +0 -1
- package/build/utils/options.d.ts +0 -3
- package/build/utils/options.d.ts.map +0 -1
- package/build/utils/options.js +0 -17
- package/build/utils/options.js.map +0 -1
- package/src/utils/index.ts +0 -2
- package/src/utils/options.ts +0 -17
package/README.md
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
# @owlmeans/redis-resource
|
|
2
2
|
|
|
3
|
-
Redis-backed resource with pub/sub and
|
|
3
|
+
Redis-backed resource with pub/sub, keyspace watching and streams for real-time features.
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
|
-
- `makeRedisResource(alias, dbAlias?)` — creates a Redis resource
|
|
8
|
-
- `RedisResource<T>` —
|
|
7
|
+
- `makeRedisResource(alias, dbAlias?, serviceAlias?)` — creates a Redis resource
|
|
8
|
+
- `RedisResource<T>` — `Resource<T>` composed with `PubSubResource`, `WatchableResource` and
|
|
9
|
+
`StreamResource`
|
|
10
|
+
- One JSON document per namespaced key: `resource.key(id)` → `<schema>-<alias>:<id>`
|
|
9
11
|
- Used for authentication caches, pub/sub channels, and async event streams
|
|
10
12
|
|
|
11
13
|
## Installation
|
|
12
14
|
|
|
13
15
|
```bash
|
|
14
|
-
bun add @owlmeans/redis-resource
|
|
16
|
+
bun add @owlmeans/redis-resource@^0.1.18-rc.11
|
|
15
17
|
```
|
|
16
18
|
|
|
17
19
|
## Usage
|
|
@@ -27,65 +29,110 @@ context.registerResource(makeRedisResource(AGENT_THINKING_STREAM))
|
|
|
27
29
|
context.registerResource(makeRedisResource(AGENT_WATCHER_PUBSUB))
|
|
28
30
|
```
|
|
29
31
|
|
|
30
|
-
|
|
32
|
+
Type the resource once, at the point it is taken out of the context:
|
|
31
33
|
|
|
32
34
|
```typescript
|
|
33
35
|
import type { RedisResource } from '@owlmeans/redis-resource'
|
|
34
36
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
const cache = context.resource<RedisResource<SessionData>>(AUTH_CACHE)
|
|
38
|
+
|
|
39
|
+
await cache.create({ id, token }, { ttl: 3600 }) // seconds, or a Date
|
|
40
|
+
const session = await cache.load({ token }) // criteria, not just an id
|
|
41
|
+
await cache.take(id) // delete-and-return
|
|
37
42
|
```
|
|
38
43
|
|
|
39
44
|
Publish and subscribe:
|
|
40
45
|
|
|
41
46
|
```typescript
|
|
42
|
-
const pubsub = context.resource<
|
|
47
|
+
const pubsub = context.resource<RedisResource<AgentWatcherEvent>>(AGENT_WATCHER_PUBSUB)
|
|
43
48
|
|
|
44
|
-
|
|
45
|
-
await pubsub.publish({ type: 'update', payload: data })
|
|
49
|
+
await pubsub.publish({ type: 'update', payload: data }, channel)
|
|
46
50
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
const unsubscribe = await pubsub.subscribe(
|
|
52
|
+
event => handleEvent(event), { channel, once: true }
|
|
53
|
+
)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Watch one record for changes (keyspace notifications):
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
const unwatch = await cache.watch(id, record => {
|
|
60
|
+
// `null` once the key is gone — deleted or expired
|
|
61
|
+
render(record)
|
|
62
|
+
}, { once: true })
|
|
51
63
|
```
|
|
52
64
|
|
|
53
65
|
Stream events (Redis Streams):
|
|
54
66
|
|
|
55
67
|
```typescript
|
|
56
|
-
const stream = context.resource<
|
|
68
|
+
const stream = context.resource<RedisResource<AgentThinkingEvent>>(AGENT_THINKING_STREAM)
|
|
57
69
|
|
|
58
|
-
// Producer
|
|
59
70
|
await stream.stream('thinking-key', { step: 'reasoning', content: text })
|
|
60
71
|
|
|
61
|
-
|
|
62
|
-
for await (const event of stream.consume('thinking-key', 'workers', 'worker-1')) {
|
|
72
|
+
for await (const event of stream.consume('thinking-key', { group: 'workers', consumer: 'worker-1' })) {
|
|
63
73
|
process(event)
|
|
64
74
|
}
|
|
65
75
|
```
|
|
66
76
|
|
|
77
|
+
## Reads
|
|
78
|
+
|
|
79
|
+
`load(id)` / `get(id)` / `delete(id)` / `take(id)` are O(1) commands on one key. `load({ ... })`,
|
|
80
|
+
`get({ ... })`, `list`, `count` and `purge` walk this resource's **own namespace** with `SCAN`
|
|
81
|
+
(never `KEYS`, which blocks the server for the whole sweep), read the values with `MGET`, and
|
|
82
|
+
evaluate the criteria in memory. That is O(N) over the namespace: right for a small namespaced set
|
|
83
|
+
— a session cache, an adapter store — and wrong for anything unbounded or on a hot path. A
|
|
84
|
+
resource that needs real queries belongs in `@owlmeans/mongo-resource` or
|
|
85
|
+
`@owlmeans/postgres-resource`.
|
|
86
|
+
|
|
87
|
+
Redis is **unpaged**: `list(where)` with no `size` returns every match, and `list(where, { page })`
|
|
88
|
+
without a `size` throws `UnsupportedArgumentError('page-without-size')`. `ListResult.total` always
|
|
89
|
+
counts every match.
|
|
90
|
+
|
|
91
|
+
The namespace walk reaches one server, so `list` / `count` / `purge` are not cluster-safe — in a
|
|
92
|
+
clustered deployment use the by-id operations only.
|
|
93
|
+
|
|
94
|
+
## TTL
|
|
95
|
+
|
|
96
|
+
| `opts.ttl` | Meaning | Command |
|
|
97
|
+
|---|---|---|
|
|
98
|
+
| `number` | seconds from now | `EXPIRE` |
|
|
99
|
+
| `Date` | the absolute instant to expire at | `PEXPIREAT` (milliseconds — what `Date.getTime()` gives) |
|
|
100
|
+
| omitted | persistent (`PTTL` reports `-1`) | — |
|
|
101
|
+
|
|
102
|
+
A `Date` already in the past drops the record immediately. `update` and `save` rewrite the key, so
|
|
103
|
+
a renewal has to pass its TTL again — otherwise the record becomes persistent.
|
|
104
|
+
|
|
67
105
|
## API
|
|
68
106
|
|
|
69
|
-
### `makeRedisResource(alias, dbAlias?): RedisResource<
|
|
107
|
+
### `makeRedisResource<R>(alias, dbAlias?, serviceAlias?): RedisResource<R>`
|
|
70
108
|
|
|
71
|
-
Creates a Redis resource.
|
|
109
|
+
Creates a Redis resource. Both alias arguments default to `DEFAULT_DB_ALIAS` (`'redis'`).
|
|
72
110
|
|
|
73
111
|
### `RedisResource<T>`
|
|
74
112
|
|
|
75
|
-
|
|
76
|
-
- `
|
|
77
|
-
- `
|
|
78
|
-
- `
|
|
79
|
-
|
|
113
|
+
`Resource<T>` plus:
|
|
114
|
+
- `publish(value, channel?): Promise<void>` — publish to a namespaced pub/sub channel
|
|
115
|
+
- `subscribe(handler, { channel?, once?, ttl? }): Promise<Unsubscribe>` — channel pub/sub
|
|
116
|
+
- `watch(id, handler, { once?, ttl? }): Promise<Unsubscribe>` — keyspace notifications for ONE
|
|
117
|
+
record; the handler is given `null` once the key is gone. Bound to **db 0**, so deployments
|
|
118
|
+
sharing an instance isolate on the key prefix, and the server needs `notify-keyspace-events`
|
|
119
|
+
- `stream(key, value): Promise<void>` — append to a Redis Stream
|
|
120
|
+
- `consume(key, { group?, consumer?, block? }): AsyncGenerator<T>` — consume from a Redis Stream
|
|
121
|
+
- `key(key?): string` — the namespaced key, or the namespace's glob
|
|
80
122
|
|
|
81
123
|
### Constants
|
|
82
124
|
|
|
83
125
|
- `DEFAULT_DB_ALIAS` — `'redis'`
|
|
126
|
+
- `DEFAULT_PAGE_SIZE` — `0`, meaning unpaged
|
|
127
|
+
|
|
128
|
+
## Requirements
|
|
129
|
+
|
|
130
|
+
Redis 6.2 or newer: `delete` and `take` use `GETDEL`.
|
|
84
131
|
|
|
85
132
|
## Related Packages
|
|
86
133
|
|
|
87
134
|
- [`@owlmeans/redis`](../redis) — Redis connection service
|
|
88
|
-
- [`@owlmeans/resource`](../resource) — `Resource<T>` base interface
|
|
135
|
+
- [`@owlmeans/resource`](../resource) — `Resource<T>` base interface and the criteria engine
|
|
89
136
|
- [`@owlmeans/server-socket`](../server-socket) — WebSocket handlers often use Redis resources for streaming
|
|
90
137
|
|
|
91
138
|
<!-- owlmeans:agent-guidance:start -->
|
|
@@ -96,7 +143,7 @@ This package ships embedded agent skills under `agent-meta/`. After installing y
|
|
|
96
143
|
your project's skill store (`.agents/skills/`):
|
|
97
144
|
|
|
98
145
|
```sh
|
|
99
|
-
npx @owlmeans/agent-skills
|
|
146
|
+
npx @owlmeans/agent-skills@^0.1.18-rc.20
|
|
100
147
|
```
|
|
101
148
|
|
|
102
149
|
The embedded files are version-matched to this package release. Do not edit them
|
package/agent-meta/manifest.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 2,
|
|
3
3
|
"package": "@owlmeans/redis-resource",
|
|
4
|
-
"version": "0.1.18-rc.
|
|
5
|
-
"generatedAt": "2026-
|
|
4
|
+
"version": "0.1.18-rc.20",
|
|
5
|
+
"generatedAt": "2026-09-12T14:21:25.465Z",
|
|
6
6
|
"canonicalRepo": "https://github.com/owlmeans/common",
|
|
7
7
|
"entries": [
|
|
8
8
|
{
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: redis-resource
|
|
3
|
-
description: How to use @owlmeans/redis-resource — Redis-backed Resource implementation for caching/state with TTL
|
|
3
|
+
description: How to use @owlmeans/redis-resource — Redis-backed Resource implementation for caching/state with TTL, pub/sub, keyspace watching and streams. Auto-invoked when defining a resource backed by Redis.
|
|
4
4
|
user-invocable: false
|
|
5
5
|
---
|
|
6
6
|
<!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
|
|
@@ -8,17 +8,23 @@ user-invocable: false
|
|
|
8
8
|
# @owlmeans/redis-resource
|
|
9
9
|
|
|
10
10
|
**Layer:** Infra
|
|
11
|
-
**Install:** `"@owlmeans/redis-resource": "^0.1.18-rc.
|
|
11
|
+
**Install:** `"@owlmeans/redis-resource": "^0.1.18-rc.20"` in `dependencies`
|
|
12
12
|
|
|
13
13
|
## Key Exports
|
|
14
14
|
|
|
15
15
|
| Export | Description |
|
|
16
16
|
|--------|-------------|
|
|
17
|
-
| `makeRedisResource<R>(alias, dbAlias?, serviceAlias
|
|
18
|
-
| `RedisResource<R
|
|
19
|
-
| `
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
| `makeRedisResource<R>(alias, dbAlias?, serviceAlias?)` | Factory for a Redis-backed `Resource<R>`. Both alias defaults are `DEFAULT_DB_ALIAS` (`'redis'`) |
|
|
18
|
+
| `RedisResource<R>` | `Resource<R>` plus the `PubSubResource`, `WatchableResource` and `StreamResource` capabilities, `db`, `name` and `key(id?)` |
|
|
19
|
+
| `RedisDb`, `RedisClient`, `RedisDbService`, `RedisConnection` | The db and connection contracts — `@owlmeans/redis` implements them |
|
|
20
|
+
| `DEFAULT_DB_ALIAS`, `DEFAULT_PAGE_SIZE`, `SCAN_BATCH`, `READ_BATCH` | Constants for the record half |
|
|
21
|
+
| `STREAM_MAX_LENGTH`, `DEFAULT_STREAM_BLOCK`, `RECLAIM_IDLE`, `RECLAIM_COUNT`, `CONSUMER_ID_LENGTH` | Constants for the stream half |
|
|
22
|
+
|
|
23
|
+
Keys are namespaced by the db config's key prefix plus the resource's name:
|
|
24
|
+
`resource.key(id)` → `<prefix>-<name>:<id>`, and `key()` with no argument yields the namespace's
|
|
25
|
+
glob. The name is `resource.name` when set and the registration alias otherwise, so two resources
|
|
26
|
+
can share one namespace deliberately — and a `name` given by accident quietly merges two id spaces.
|
|
27
|
+
Every non-word character in either half is collapsed to `_`.
|
|
22
28
|
|
|
23
29
|
## Usage
|
|
24
30
|
|
|
@@ -27,47 +33,106 @@ import { makeRedisResource } from '@owlmeans/redis-resource'
|
|
|
27
33
|
|
|
28
34
|
context.registerResource(makeRedisResource<SessionData>('sessions'))
|
|
29
35
|
|
|
36
|
+
// Type the RESOURCE once — never a method
|
|
30
37
|
const sessions = context.resource<RedisResource<SessionData>>('sessions')
|
|
31
38
|
await sessions.create({ id, token }, { ttl: 3600 }) // seconds, or a Date
|
|
39
|
+
const live = await sessions.load({ token }) // criteria, not just an id
|
|
32
40
|
```
|
|
33
41
|
|
|
34
|
-
TTL is a **per-call option** on `create
|
|
35
|
-
comes from the `dbs[]` config entry (`schema`), not from the resource.
|
|
42
|
+
TTL is a **per-call option** on `create` / `update` / `save`, not a property of the factory. The
|
|
43
|
+
prefix comes from the `dbs[]` config entry (`schema`), not from the resource.
|
|
44
|
+
|
|
45
|
+
## Reads: one key is cheap, everything else is a walk
|
|
46
|
+
|
|
47
|
+
`load(id)`, `get(id)`, `delete(id)`, `take(id)` are single-key commands.
|
|
48
|
+
|
|
49
|
+
`load(where)`, `get(where)`, `list`, `count` and `purge` walk the resource's **own namespace** with
|
|
50
|
+
`SCAN` + `MGET` and evaluate the criteria in memory with `firstMatch` / `filterRecords` /
|
|
51
|
+
`applyQuery` from `@owlmeans/resource` — the same engine every other store without a query planner
|
|
52
|
+
uses, so a criteria object means here exactly what it means in SQL. That is O(N) over the
|
|
53
|
+
namespace, and `{ sort }` orders the records after the walk, not in redis.
|
|
54
|
+
|
|
55
|
+
- Use it for a small namespaced set — a session cache, an OTP store, an adapter store.
|
|
56
|
+
- Never for an unbounded keyspace or a hot path. A resource that needs real queries belongs in
|
|
57
|
+
mongo or postgres.
|
|
58
|
+
- `SCAN`, never `KEYS`: `KEYS` blocks the server for the whole sweep.
|
|
59
|
+
- The walk reaches one server, so `list` / `count` / `purge` are **not cluster-safe**. In a
|
|
60
|
+
clustered deployment stay on the by-id operations.
|
|
61
|
+
- `load({ id })` is recognised and answered by key — the walk only starts for a real criteria.
|
|
62
|
+
- A key in the namespace holding something other than a string — this resource's own streams
|
|
63
|
+
included — reads back as `null` from `MGET` and is skipped, so a stream never shows up as a
|
|
64
|
+
record.
|
|
65
|
+
|
|
66
|
+
## Paging
|
|
67
|
+
|
|
68
|
+
Redis is **UNPAGED**: `DEFAULT_PAGE_SIZE` is `0`, `list(where)` with no `size` returns every match,
|
|
69
|
+
and `ListResult.total` always counts every match. `list(where, { page })` without a `size` throws
|
|
70
|
+
`UnsupportedArgumentError('page-without-size')` — there is no implied default to take a window of.
|
|
36
71
|
|
|
37
72
|
## TTL
|
|
38
73
|
|
|
39
74
|
| `opts.ttl` | Meaning | Command |
|
|
40
75
|
|---|---|---|
|
|
41
|
-
| `number`
|
|
76
|
+
| `number` | seconds from now | `EXPIRE` |
|
|
42
77
|
| `Date` | the absolute instant to expire at | `PEXPIREAT` (milliseconds — what `Date.getTime()` gives) |
|
|
43
78
|
| omitted | persistent (`PTTL` reports `-1`) | — |
|
|
44
79
|
|
|
45
|
-
A `Date` already in the past drops the record immediately. `update`
|
|
46
|
-
renewal must pass
|
|
80
|
+
A `Date` already in the past drops the record immediately. `update` and `save` rewrite the key, so
|
|
81
|
+
a renewal must pass a TTL again — otherwise the record becomes persistent.
|
|
47
82
|
|
|
48
83
|
## Rules
|
|
49
84
|
|
|
50
|
-
- `delete(id)`
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
- `create`
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
- `
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
- `
|
|
61
|
-
|
|
62
|
-
-
|
|
63
|
-
the
|
|
85
|
+
- `delete(id)` returns the removed record or `null`; `take(id)` is the same read but **throws**
|
|
86
|
+
`UnknownRecordError` when the key is gone. Both use `GETDEL`, so two callers can never be handed
|
|
87
|
+
the same record. Choose by whether absence is an error.
|
|
88
|
+
- `create` generates an id when the record carries none, and refuses an id that is already there
|
|
89
|
+
(`RecordExists`) using `SET NX` — no read-then-write race. The id is written into the stored
|
|
90
|
+
record, so what comes back always carries one.
|
|
91
|
+
- `update` **replaces** the whole record and throws `UnknownRecordError` for an unknown id (and
|
|
92
|
+
`MisshapedRecord` when the record carries no id at all). It does not merge over what was stored;
|
|
93
|
+
pass every field that must survive.
|
|
94
|
+
- `save` creates when the record carries no id and replaces otherwise — that is the upsert.
|
|
95
|
+
- `purge(where)` refuses an empty criteria object. Use it instead of a page loop that deletes each
|
|
96
|
+
item.
|
|
97
|
+
- `publish(value, channel?)` / `subscribe(handler, { channel?, once?, ttl? })` are channel pub/sub;
|
|
98
|
+
the channel name is namespaced like a key, and an omitted channel listens to the resource's whole
|
|
99
|
+
namespace. `watch(id, handler, { once?, ttl? })` is the keyspace-notification form for ONE
|
|
100
|
+
record — the handler receives the current value on every write, and `null` once the key is gone.
|
|
101
|
+
They are separate methods; a channel is never passed as a bare string.
|
|
102
|
+
- `watch` subscribes to `__keyspace@0__:`, while redis publishes keyspace events per database as
|
|
103
|
+
`__keyspace@<db>__:`. So a resource on a connection whose `meta.dbIndex` is anything but 0 gets
|
|
104
|
+
no notifications at all and its `watch` handler silently never fires — deployments sharing one
|
|
105
|
+
instance isolate on the key prefix, not on the db index. The server also needs
|
|
106
|
+
`notify-keyspace-events` enabled; it emits nothing otherwise.
|
|
107
|
+
- `stream(key, value)` appends to a namespaced redis stream, trimmed approximately to
|
|
108
|
+
`STREAM_MAX_LENGTH` so trimming stays cheap. `consume(key, { group?, consumer?, block? })` is the
|
|
109
|
+
async generator that reads it — with no `group` it tails from now with `XREAD`, with one it joins
|
|
110
|
+
the consumer group and reclaims stale entries under the **passed** consumer name. Claiming them
|
|
111
|
+
for a fixed name leaves them owned by a consumer that never reads.
|
|
112
|
+
- Requires redis 6.2 or newer (`GETDEL`).
|
|
113
|
+
- Assert an expiry by reading `PTTL` back from redis, never by trusting that a command was issued.
|
|
114
|
+
An expiry set in the wrong unit is still an expiry — just one tens of millennia out — so only the
|
|
115
|
+
value redis reports back proves anything.
|
|
116
|
+
|
|
117
|
+
## Tests
|
|
118
|
+
|
|
119
|
+
Integration specs live in the `@owlmeans/redis` package's own `tests/` — the db package that backs
|
|
120
|
+
this contract; putting them here would need a devDependency on this package's own dependent.
|
|
121
|
+
Gated on `REDIS_URL` (see `/.env.example`); each suite namespaces its keys and flushes them, and a
|
|
122
|
+
spec that walks the namespace boots under its own resource alias so it never sees another test's
|
|
123
|
+
records.
|
|
64
124
|
|
|
65
125
|
## Depends On
|
|
66
126
|
|
|
67
|
-
- `@owlmeans/
|
|
127
|
+
- `@owlmeans/resource` · `@owlmeans/context` · `@owlmeans/server-context` · `@owlmeans/basic-ids`
|
|
128
|
+
- peer `ioredis` (the client types every method is written against), `ajv`
|
|
68
129
|
|
|
69
|
-
|
|
130
|
+
`@owlmeans/redis` is NOT a dependency — it depends on this package, and that is the direction the
|
|
131
|
+
connection contracts flow in.
|
|
70
132
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
133
|
+
## Related
|
|
134
|
+
|
|
135
|
+
- `redis` — the connection service implementing `RedisDbService`, and the `cfg.dbs` entry a
|
|
136
|
+
resource takes its prefix and db index from
|
|
137
|
+
- `redis-queue` — BullMQ queues on the same connections
|
|
138
|
+
- `resource` — the criteria language, paging and the error classes raised here
|
package/build/consts.d.ts
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
1
|
export declare const DEFAULT_DB_ALIAS = "redis";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Redis is UNPAGED: `list()` without a `size` returns every match, and `0` says exactly that.
|
|
4
|
+
* There is no server side LIMIT to fall back on — answering a criteria already walked the whole
|
|
5
|
+
* namespace — so an implied default would only hide records without saving any work.
|
|
6
|
+
*/
|
|
7
|
+
export declare const DEFAULT_PAGE_SIZE = 0;
|
|
8
|
+
/** Keys per SCAN round trip. Bounded so one sweep never blocks the server the way KEYS does. */
|
|
9
|
+
export declare const SCAN_BATCH = 200;
|
|
10
|
+
/** Keys per MGET / DEL round trip once SCAN has collected them. */
|
|
11
|
+
export declare const READ_BATCH = 200;
|
|
12
|
+
/** Entries kept in a stream, trimmed approximately (`MAXLEN ~`) so trimming stays O(1)-ish. */
|
|
13
|
+
export declare const STREAM_MAX_LENGTH = 10000;
|
|
14
|
+
/** How long a stream read blocks before the consumer loops and looks for pending entries. */
|
|
15
|
+
export declare const DEFAULT_STREAM_BLOCK = 1000;
|
|
16
|
+
/** How long an unacknowledged entry may sit with its consumer before another may reclaim it. */
|
|
17
|
+
export declare const RECLAIM_IDLE = 60000;
|
|
18
|
+
/** Entries reclaimed per XAUTOCLAIM pass. */
|
|
19
|
+
export declare const RECLAIM_COUNT = 10;
|
|
20
|
+
/** Length of the generated consumer name when `consume` is not given one. */
|
|
21
|
+
export declare const CONSUMER_ID_LENGTH = 15;
|
|
3
22
|
//# sourceMappingURL=consts.d.ts.map
|
package/build/consts.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,UAAU,CAAA;AAEvC;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,IAAI,CAAA;AAElC,gGAAgG;AAChG,eAAO,MAAM,UAAU,MAAM,CAAA;AAE7B,mEAAmE;AACnE,eAAO,MAAM,UAAU,MAAM,CAAA;AAE7B,+FAA+F;AAC/F,eAAO,MAAM,iBAAiB,QAAQ,CAAA;AAEtC,6FAA6F;AAC7F,eAAO,MAAM,oBAAoB,OAAO,CAAA;AAExC,gGAAgG;AAChG,eAAO,MAAM,YAAY,QAAQ,CAAA;AAEjC,6CAA6C;AAC7C,eAAO,MAAM,aAAa,KAAK,CAAA;AAE/B,6EAA6E;AAC7E,eAAO,MAAM,kBAAkB,KAAK,CAAA"}
|
package/build/consts.js
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
1
|
export const DEFAULT_DB_ALIAS = 'redis';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Redis is UNPAGED: `list()` without a `size` returns every match, and `0` says exactly that.
|
|
4
|
+
* There is no server side LIMIT to fall back on — answering a criteria already walked the whole
|
|
5
|
+
* namespace — so an implied default would only hide records without saving any work.
|
|
6
|
+
*/
|
|
7
|
+
export const DEFAULT_PAGE_SIZE = 0;
|
|
8
|
+
/** Keys per SCAN round trip. Bounded so one sweep never blocks the server the way KEYS does. */
|
|
9
|
+
export const SCAN_BATCH = 200;
|
|
10
|
+
/** Keys per MGET / DEL round trip once SCAN has collected them. */
|
|
11
|
+
export const READ_BATCH = 200;
|
|
12
|
+
/** Entries kept in a stream, trimmed approximately (`MAXLEN ~`) so trimming stays O(1)-ish. */
|
|
13
|
+
export const STREAM_MAX_LENGTH = 10000;
|
|
14
|
+
/** How long a stream read blocks before the consumer loops and looks for pending entries. */
|
|
15
|
+
export const DEFAULT_STREAM_BLOCK = 1000;
|
|
16
|
+
/** How long an unacknowledged entry may sit with its consumer before another may reclaim it. */
|
|
17
|
+
export const RECLAIM_IDLE = 60000;
|
|
18
|
+
/** Entries reclaimed per XAUTOCLAIM pass. */
|
|
19
|
+
export const RECLAIM_COUNT = 10;
|
|
20
|
+
/** Length of the generated consumer name when `consume` is not given one. */
|
|
21
|
+
export const CONSUMER_ID_LENGTH = 15;
|
|
3
22
|
//# sourceMappingURL=consts.js.map
|
package/build/consts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAA;AAEvC;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAA;AAElC,gGAAgG;AAChG,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,CAAA;AAE7B,mEAAmE;AACnE,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,CAAA;AAE7B,+FAA+F;AAC/F,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,CAAA;AAEtC,6FAA6F;AAC7F,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,CAAA;AAExC,gGAAgG;AAChG,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,CAAA;AAEjC,6CAA6C;AAC7C,MAAM,CAAC,MAAM,aAAa,GAAG,EAAE,CAAA;AAE/B,6EAA6E;AAC7E,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,CAAA"}
|
package/build/resource.d.ts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ResourceRecord } from '@owlmeans/resource';
|
|
2
2
|
import type { RedisResource } from './types.js';
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* A `Resource` over plain redis strings: one JSON document per namespaced key.
|
|
5
|
+
*
|
|
6
|
+
* Reads by id are O(1) GETs. Everything else — a criteria read, a listing, a count, a purge —
|
|
7
|
+
* walks this resource's OWN namespace with SCAN and evaluates the criteria in memory, because
|
|
8
|
+
* redis has no index to ask. That is affordable for a small namespaced set (a session cache, an
|
|
9
|
+
* adapter store) and wrong for anything unbounded or hot; a resource that needs real queries
|
|
10
|
+
* belongs in mongo or postgres.
|
|
11
|
+
*/
|
|
12
|
+
export declare const makeRedisResource: <R extends ResourceRecord, T extends RedisResource<R> = RedisResource<R>>(alias: string, dbAlias?: string, serviceAlias?: string) => T;
|
|
4
13
|
//# sourceMappingURL=resource.d.ts.map
|
package/build/resource.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../src/resource.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACuC,cAAc,EAEhE,MAAM,oBAAoB,CAAA;AAK3B,OAAO,KAAK,EAA+B,aAAa,EAAE,MAAM,YAAY,CAAA;AAY5E;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,GAC5B,CAAC,SAAS,cAAc,EAAE,CAAC,SAAS,aAAa,CAAC,CAAC,CAAC,4BAE7C,MAAM,8CACZ,CAmZF,CAAA"}
|