Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,46 @@ jobs:

- name: Run tests
run: pnpm test

redis:
name: Redis adapter · Node.js ${{ matrix.node-version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version:
- 22
- 24

services:
redis:
image: redis:7.4-alpine
ports:
- 16379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
- name: Check out repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7

- name: Set up pnpm
uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0

- name: Set up Node.js
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7
with:
node-version: ${{ matrix.node-version }}
cache: pnpm

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Check types
run: pnpm run check

- name: Run Redis adapter tests
run: pnpm run test:redis
13 changes: 13 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ concurrency:
jobs:
prepare:
runs-on: ubuntu-latest
services:
redis:
image: redis:7.4-alpine
ports:
- 16379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
RELEASE_PRERELEASE: ${{ github.event.release.prerelease }}
Expand Down Expand Up @@ -71,6 +81,9 @@ jobs:
- name: Run tests
run: pnpm test

- name: Run Redis adapter tests
run: pnpm run test:redis

- name: Prepare and verify release tarballs
run: pnpm run release:pack -- --require-clean --require-main-ancestor --require-release-tag --expected-release-commit "${RELEASE_COMMIT}" --output .release

Expand Down
13 changes: 8 additions & 5 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ unbounded in-process map as a fallback when the remote cache is down.
**No vendor clients in application code.** Adapters wrap Redis, Azure Cache,
ElastiCache, or Upstash. Hosts depend on `CacheStore`. Do not create an
adapter package until implementation begins and a named consumer exists.
`@pegma/cache-redis` exists because RetireGolden.org and Exsimplify are
named future hosts.

**This is not durable state.** Persistence, optimistic concurrency, and
transactions belong in `@pegma/storage-core`. A cache miss is not data loss.
Expand All @@ -71,18 +73,19 @@ when pnpm set it, or pack/publish silently go through pnpm.

Work on a `claude/*` branch and open a pull request. The gate is
`pnpm run format:check`, `pnpm run check`, `pnpm test` — all three, on Node 22
and 24.
and 24. Changes to `@pegma/cache-redis` also run `pnpm run test:redis`
against a real Redis (CI starts one; locally `redis-server` on port 16379
or a service already bound there).

Publishing is trusted-publisher only; no tokens exist. A release starts from a
protected signed annotated `vX.Y.Z` tag already on `origin/main`, followed by
`gh release create vX.Y.Z --verify-tag`. See `docs/RELEASING.md`.

## Where things stand

Phase 1: `@pegma/cache-core` (ports, codecs, `formatCacheKey`, single-flight
helper, in-memory store) and `@pegma/cache-conformance` (executable suite).
Redis / Azure Redis / ElastiCache / Upstash adapters are later phases — do
not create those packages here yet.
Phase 2: `@pegma/cache-core`, `@pegma/cache-conformance`, and
`@pegma/cache-redis` (generic Redis adapter). Azure Redis / ElastiCache /
Upstash adapters are later phases — do not create those packages here yet.

Siblings: [spine](https://github.com/pegma-dev/spine),
[storage-core](https://github.com/pegma-dev/storage-core),
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ corepack enable
pnpm install --frozen-lockfile
pnpm run check
pnpm test
pnpm run test:redis
pnpm run format:check
```

Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ and a conformance suite every adapter must pass.
| ---------------------------- | ----------------------------------------- | ----- |
| `@pegma/cache-core` | Port, codecs, single-flight, memory store | 1 |
| `@pegma/cache-conformance` | Executable suite every adapter must pass | 1 |
| `@pegma/cache-redis` | Generic Redis adapter | later |
| `@pegma/cache-redis` | Generic Redis adapter | 2 |
| `@pegma/cache-azure-redis` | Azure Cache for Redis adapter | later |
| `@pegma/cache-elasticache` | Amazon ElastiCache adapter | later |
| `@pegma/cache-upstash-redis` | Upstash Redis adapter | later |

Adapter packages are not created until implementation begins and a named
consumer exists.
`@pegma/cache-redis` is the generic Redis adapter. Intended future hosts:
RetireGolden.org and Exsimplify. Remaining adapter packages wait until
implementation begins and a named consumer exists.

## Constraint that shapes everything

Expand All @@ -66,8 +67,13 @@ pnpm install --frozen-lockfile
pnpm run format:check
pnpm run check
pnpm test
pnpm run test:redis
```

`pnpm test` is the Phase 1 gate and does not need Redis. `pnpm run test:redis`
starts a local `redis-server` on port 16379 when that port is free, or uses
whatever is already listening there.

## License

[MIT](LICENSE) © 2026 RetireGolden, LLC
26 changes: 15 additions & 11 deletions docs/PROJECT_PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

## Status

**Stage:** Phase 1 — ports, in-memory store, and the conformance suite.
Nothing is published. (`0.1.0`, unpublished.)
**Stage:** Phase 2 — generic Redis adapter, in-tree, unpublished.
`@pegma/cache-core`, `@pegma/cache-conformance`, and `@pegma/cache-redis`
are `0.1.0` and not published.

**License:** MIT

Expand Down Expand Up @@ -94,10 +95,10 @@ those land with a later adapter, named, tested, and never smuggled into

### No adapter package without a consumer

The Pegma rule: do not create `cache-redis`, `cache-azure-redis`,
`cache-elasticache`, or `cache-upstash-redis` until implementation begins
and a named consumer exists. Phase 1 ships the port, the memory store, and
the suite those adapters will have to pass.
The Pegma rule: do not create an adapter package until implementation
begins and a named consumer exists. Phase 2 creates `@pegma/cache-redis`
because RetireGolden.org and Exsimplify are named future hosts.
`cache-azure-redis`, `cache-elasticache`, and `cache-upstash-redis` wait.

### Vendor clients stay behind the port

Expand Down Expand Up @@ -125,7 +126,8 @@ local composition never take a network client.
- **Unbounded local memory fallbacks when a remote cache is down.**
Fail-open computes; it does not accumulate.
- **Vendor clients in application code.**
- **Redis / Azure Redis / ElastiCache / Upstash packages in Phase 1.**
- **Azure Redis / ElastiCache / Upstash packages in Phase 2.**
Those remain later phases.

## Package architecture

Expand All @@ -143,17 +145,19 @@ Dependencies: `@pegma/spine` pinned exactly. Conformance pins

## Delivery phases

### Phase 1 — port, memory store, conformance (this PR)
### Phase 1 — port, memory store, conformance

`CacheStore`, codecs, `formatCacheKey`, single-flight `getOrCompute`
helper, in-memory store, and the suite cases listed above. The in-memory
store is the first adapter and must pass.

### Phase 2 — generic Redis adapter
### Phase 2 — generic Redis adapter (this PR)

`@pegma/cache-redis` against a real empty Redis (or a faithful local
server). Created only when implementation begins and a consumer exists.
Must pass `@pegma/cache-conformance`.
server). Created because RetireGolden.org and Exsimplify are named future
hosts. Must pass `@pegma/cache-conformance`. Expiry stays on the injected
Clock; tag invalidation uses a sidecar index and never implies a
multi-key command.

### Phase 3 — Azure Cache for Redis

Expand Down
24 changes: 13 additions & 11 deletions docs/RELEASING.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Release operations

`@pegma/cache-core` and `@pegma/cache-conformance` publish only from a
stable GitHub release. Merging a pull request never publishes, and the
workflow has no manual-dispatch or npm-token fallback.
`@pegma/cache-core`, `@pegma/cache-conformance`, and `@pegma/cache-redis`
publish only from a stable GitHub release. Merging a pull request never
publishes, and the workflow has no manual-dispatch or npm-token fallback.

## Required external configuration

Before the first release through this workflow:

- configure `@pegma/cache-core` and `@pegma/cache-conformance` on npm with
the GitHub Actions trusted publisher `pegma-dev/cache-core`, workflow
`publish.yml`, environment `npm-publish`, and allowed action
`npm publish`;
- configure `@pegma/cache-core`, `@pegma/cache-conformance`, and
`@pegma/cache-redis` on npm with the GitHub Actions trusted publisher
`pegma-dev/cache-core`, workflow `publish.yml`, environment `npm-publish`,
and allowed action `npm publish`;
- create the GitHub `npm-publish` environment. A second reviewer is not
required under Pegma's single-maintainer policy;
- create the repository Actions variable `RELEASE_ALLOWED_SIGNERS` containing
Expand All @@ -26,10 +26,12 @@ remaining traditional npm publish tokens.

## Release procedure

The version in `packages/cache-core/package.json` and
`packages/cache-conformance/package.json` is the release version. Both
public packages publish at the same version. Change it through an ordinary
reviewed pull request and run the complete gate on Node 22 and 24.
The version in `packages/cache-core/package.json`,
`packages/cache-conformance/package.json`, and
`packages/cache-redis/package.json` is the release version. All public
packages publish at the same version. Change it through an ordinary
reviewed pull request and run the complete gate on Node 22 and 24,
including `pnpm run test:redis`.

After that pull request is merged, create a signed annotated tag at the exact
`origin/main` commit, push the tag, verify the fetched tag, and only then
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"release:check": "node scripts/release-packages.mjs check",
"release:pack": "node scripts/release-packages.mjs pack",
"release:publish": "node scripts/release-packages.mjs publish",
"test": "pnpm run build && vitest run"
"test": "pnpm run build && vitest run",
"test:redis": "pnpm run build && vitest run --config vitest.redis.config.ts"
},
"devDependencies": {
"@types/node": "^26.1.1",
Expand Down
21 changes: 21 additions & 0 deletions packages/cache-redis/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 RetireGolden, LLC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
41 changes: 41 additions & 0 deletions packages/cache-redis/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# `@pegma/cache-redis`

Generic Redis adapter for [`@pegma/cache-core`](https://github.com/pegma-dev/cache-core).
Intended future hosts: RetireGolden.org and Exsimplify.

> [!IMPORTANT]
> Pegma is in early `0.x` development. This package's public API is unstable.

```ts
import { createControllableClock, jsonCodec } from "@pegma/cache-core";
import { createRedisCacheStore } from "@pegma/cache-redis";
import { Redis } from "ioredis";

const clock = createControllableClock("2026-08-15T16:00:00.000Z");
const cache = createRedisCacheStore({
clock,
redis: new Redis(process.env.REDIS_URL ?? "redis://127.0.0.1:6379"),
});
const codec = jsonCodec<string>();

const result = await cache.getOrCompute(
{ namespace: "sessions", key: "abc", hashTag: "user-1" },
{
codec,
ttl: { absoluteMs: 60_000 },
fallback: "fail-open",
compute: () => loadSession(),
},
);
```

Hosts depend on `CacheStore`. Construct the Redis client at the composition
root and hand it to this adapter; application code does not import `ioredis`.

TTL, sliding refresh, and XFetch read the injected Spine `Clock`. Redis
`EXPIRE` is not the source of truth, so a test clock can pin expiry. Tag
invalidation uses a sidecar index in Redis — one key at a time, never an
implicit multi-key command. Hash tags stay formatting: `{tag}` in the wire
key from `formatCacheKey`.

This adapter passes `@pegma/cache-conformance` against a real Redis.
44 changes: 44 additions & 0 deletions packages/cache-redis/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "@pegma/cache-redis",
"version": "0.1.0",
"description": "Generic Redis adapter for @pegma/cache-core.",
"license": "MIT",
"type": "module",
"sideEffects": false,
"publishConfig": {
"access": "public"
},
"files": [
"dist/**/*.d.ts",
"dist/**/*.d.ts.map",
"dist/**/*.js",
"dist/**/*.js.map"
],
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
}
},
"engines": {
"node": ">=22"
},
"repository": {
"type": "git",
"url": "git+https://github.com/pegma-dev/cache-core.git",
"directory": "packages/cache-redis"
},
"dependencies": {
"@pegma/cache-core": "0.1.0",
"@pegma/spine": "0.1.2",
"ioredis": "^5.8.2"
},
"devDependencies": {
"@pegma/cache-conformance": "0.1.0"
},
"scripts": {
"build": "tsc -p tsconfig.json",
"check": "tsc -p tsconfig.json --noEmit",
"prepack": "pnpm run build"
}
}
Loading
Loading