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 @@ -177,3 +177,46 @@ jobs:

- name: Run ElastiCache adapter tests
run: pnpm run test:elasticache

upstash-redis:
name: Upstash 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 Upstash Redis adapter tests
run: pnpm run test:upstash-redis
3 changes: 3 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ jobs:
- name: Run ElastiCache adapter tests
run: pnpm run test:elasticache

- name: Run Upstash Redis adapter tests
run: pnpm run test:upstash-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
14 changes: 8 additions & 6 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,21 @@ against a real Redis (CI starts one; locally `redis-server` on port 16379
or a service already bound there). Changes to `@pegma/cache-azure-redis`
also run `pnpm run test:azure-redis` against the same Redis. Changes to
`@pegma/cache-elasticache` also run `pnpm run test:elasticache` against
the same Redis.
the same Redis. Changes to `@pegma/cache-upstash-redis` also run
`pnpm run test:upstash-redis` against the same Redis through an injected
client that matches the Upstash REST command surface.

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 4: `@pegma/cache-core`, `@pegma/cache-conformance`,
`@pegma/cache-redis`, `@pegma/cache-azure-redis`, and
`@pegma/cache-elasticache` (thin composition of the generic Redis
adapter; cluster hash-tag colocation is proven). The Upstash adapter is
a later phase — do not create that package here yet.
Phase 5: `@pegma/cache-core`, `@pegma/cache-conformance`,
`@pegma/cache-redis`, `@pegma/cache-azure-redis`,
`@pegma/cache-elasticache`, and `@pegma/cache-upstash-redis` (Upstash
REST/SDK client, reusing the generic Redis store after adapting the HTTP
command surface). Do not create further adapter packages here.

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 @@ -25,6 +25,7 @@ pnpm test
pnpm run test:redis
pnpm run test:azure-redis
pnpm run test:elasticache
pnpm run test:upstash-redis
pnpm run format:check
```

Expand Down
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ and a conformance suite every adapter must pass.
| `@pegma/cache-redis` | Generic Redis adapter | 2 |
| `@pegma/cache-azure-redis` | Azure Cache for Redis adapter | 3 |
| `@pegma/cache-elasticache` | Amazon ElastiCache adapter | 4 |
| `@pegma/cache-upstash-redis` | Upstash Redis adapter | later |
| `@pegma/cache-upstash-redis` | Upstash Redis adapter | 5 |

`@pegma/cache-redis` is the generic Redis adapter.
`@pegma/cache-azure-redis` and `@pegma/cache-elasticache` are thin
compositions of it: Azure Cache for Redis and ElastiCache speak Redis.
Intended future hosts: RetireGolden.org and Exsimplify. Remaining
adapter packages wait until implementation begins and a named consumer
exists.
`@pegma/cache-upstash-redis` wraps the Upstash serverless REST client
and reuses that store after adapting the HTTP command surface. Intended
future hosts: RetireGolden.org and Exsimplify. Do not create further
adapter packages here.

## Constraint that shapes everything

Expand Down Expand Up @@ -73,12 +74,15 @@ pnpm test
pnpm run test:redis
pnpm run test:azure-redis
pnpm run test:elasticache
pnpm run test:upstash-redis
```

`pnpm test` is the Phase 1 gate and does not need Redis. `pnpm run test:redis`,
`pnpm run test:azure-redis`, and `pnpm run test:elasticache` start a local
`redis-server` on port 16379 when that port is free, or use whatever is
already listening there.
`pnpm run test:azure-redis`, `pnpm run test:elasticache`, and
`pnpm run test:upstash-redis` start a local `redis-server` on port 16379
when that port is free, or use whatever is already listening there. The
Upstash suite injects a REST-shaped client; `@upstash/redis` cannot speak
the Redis protocol to that service.

## License

Expand Down
33 changes: 20 additions & 13 deletions docs/PROJECT_PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

## Status

**Stage:** Phase 4 — Amazon ElastiCache adapter, in-tree, unpublished.
**Stage:** Phase 5 — Upstash Redis adapter, in-tree, unpublished.
`@pegma/cache-core`, `@pegma/cache-conformance`, `@pegma/cache-redis`,
`@pegma/cache-azure-redis`, and `@pegma/cache-elasticache` are `0.1.0`
and not published.
`@pegma/cache-azure-redis`, `@pegma/cache-elasticache`, and
`@pegma/cache-upstash-redis` are `0.1.0` and not published.

**License:** MIT

Expand Down Expand Up @@ -98,15 +98,16 @@ those land with a later adapter, named, tested, and never smuggled into

The Pegma rule: do not create an adapter package until implementation
begins and a named consumer exists. Phase 2 created `@pegma/cache-redis`,
Phase 3 created `@pegma/cache-azure-redis`, and Phase 4 creates
`@pegma/cache-elasticache` because RetireGolden.org and Exsimplify are
named future hosts. `cache-upstash-redis` waits.
Phase 3 created `@pegma/cache-azure-redis`, Phase 4 created
`@pegma/cache-elasticache`, and Phase 5 creates
`@pegma/cache-upstash-redis` because RetireGolden.org and Exsimplify are
named future hosts.

### Vendor clients stay behind the port

Application code depends on `CacheStore`. An adapter may import `ioredis`
or a vendor SDK; a host must not. The memory store exists so tests and
local composition never take a network client.
or a vendor SDK such as `@upstash/redis`; a host must not. The memory
store exists so tests and local composition never take a network client.

## Scope

Expand All @@ -128,8 +129,7 @@ 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.**
- **Upstash package in Phase 4.**
That remains a later phase.
- **Further adapter packages beyond Phase 5.**

## Package architecture

Expand Down Expand Up @@ -167,17 +167,24 @@ Thin adapter over the same port. Azure Cache for Redis speaks Redis, so
`@pegma/cache-azure-redis` composes `@pegma/cache-redis` rather than
wrapping a data-plane Azure SDK. Real backend, same suite.

### Phase 4 — Amazon ElastiCache (this PR)
### Phase 4 — Amazon ElastiCache

Thin adapter over the same port. ElastiCache speaks Redis, so
`@pegma/cache-elasticache` composes `@pegma/cache-redis` rather than
wrapping a data-plane AWS SDK. Cluster hash-tag behaviour is proven
here, not implied: `formatCacheKey` embeds `{tag}`, and tagged wire
keys share a Redis Cluster slot. Real backend, same suite.

### Phase 5 — Upstash Redis
### Phase 5 — Upstash Redis (this PR)

Thin adapter for the serverless Redis client. Same suite.
Thin adapter over the same port. Upstash's serverless client is HTTP
REST (`@upstash/redis`), not the ioredis TCP surface, so
`@pegma/cache-upstash-redis` wraps that client and reuses
`@pegma/cache-redis` store logic after adapting the REST command shape.
It does not pretend the HTTP client is ioredis, and it does not invent
implicit cross-partition multi-key ops. CI has no live Upstash;
conformance runs against an injected client that implements the Upstash
command surface and talks to the same Redis the other adapters use.

## Open questions

Expand Down
22 changes: 12 additions & 10 deletions docs/RELEASING.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Release operations

`@pegma/cache-core`, `@pegma/cache-conformance`, `@pegma/cache-redis`,
`@pegma/cache-azure-redis`, and `@pegma/cache-elasticache` publish only
from a stable GitHub release.
`@pegma/cache-azure-redis`, `@pegma/cache-elasticache`, and
`@pegma/cache-upstash-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.

Expand All @@ -11,10 +11,11 @@ manual-dispatch or npm-token fallback.
Before the first release through this workflow:

- configure `@pegma/cache-core`, `@pegma/cache-conformance`,
`@pegma/cache-redis`, `@pegma/cache-azure-redis`, and
`@pegma/cache-elasticache` on npm with the GitHub Actions trusted
publisher `pegma-dev/cache-core`, workflow `publish.yml`, environment
`npm-publish`, and allowed action `npm publish`;
`@pegma/cache-redis`, `@pegma/cache-azure-redis`,
`@pegma/cache-elasticache`, and `@pegma/cache-upstash-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 @@ -32,12 +33,13 @@ remaining traditional npm publish tokens.
The version in `packages/cache-core/package.json`,
`packages/cache-conformance/package.json`,
`packages/cache-redis/package.json`,
`packages/cache-azure-redis/package.json`, and
`packages/cache-elasticache/package.json` is the release version. All
`packages/cache-azure-redis/package.json`,
`packages/cache-elasticache/package.json`, and
`packages/cache-upstash-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`, `pnpm run test:azure-redis`, and
`pnpm run test:elasticache`.
including `pnpm run test:redis`, `pnpm run test:azure-redis`,
`pnpm run test:elasticache`, and `pnpm run test:upstash-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 @@ -21,7 +21,8 @@
"test": "pnpm run build && vitest run",
"test:redis": "pnpm run build && vitest run --config vitest.redis.config.ts",
"test:azure-redis": "pnpm run build && vitest run --config vitest.azure-redis.config.ts",
"test:elasticache": "pnpm run build && vitest run --config vitest.elasticache.config.ts"
"test:elasticache": "pnpm run build && vitest run --config vitest.elasticache.config.ts",
"test:upstash-redis": "pnpm run build && vitest run --config vitest.upstash-redis.config.ts"
},
"devDependencies": {
"@types/node": "^26.1.1",
Expand Down
21 changes: 21 additions & 0 deletions packages/cache-upstash-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.
53 changes: 53 additions & 0 deletions packages/cache-upstash-redis/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# `@pegma/cache-upstash-redis`

Upstash Redis adapter for [`@pegma/cache-core`](https://github.com/pegma-dev/cache-core).
Wraps the Upstash serverless Redis client (`@upstash/redis`): that client is
HTTP REST, not the ioredis TCP surface, so this package adapts the REST
command shape and reuses [`@pegma/cache-redis`](https://github.com/pegma-dev/cache-core/tree/main/packages/cache-redis)
store logic. It does not pretend the HTTP client is ioredis. 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 { createUpstashRedisCacheStore } from "@pegma/cache-upstash-redis";
import { Redis } from "@upstash/redis";

const clock = createControllableClock("2026-08-15T16:00:00.000Z");
const cache = createUpstashRedisCacheStore({
clock,
redis: new Redis({
url: process.env.UPSTASH_REDIS_REST_URL,
token: process.env.UPSTASH_REDIS_REST_TOKEN,
}),
});
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 Upstash REST client at the
composition root and hand it to this adapter. Application code does not
import `@upstash/redis`.

TTL, sliding refresh, and XFetch still read the injected Spine `Clock`.
Tag invalidation still uses a sidecar index — one key at a time — and
hash tags stay formatting. Envelopes travel as base64 strings because the
REST client is JSON-over-HTTP, not a binary Redis connection.

This adapter passes `@pegma/cache-conformance`. CI has no live Upstash
account; the suite injects a client with the Upstash command surface
(`get` / `set` / `eval(script, keys, args)`) that talks to the same Redis
the other adapters use. Point `UPSTASH_REDIS_REST_URL` and
`UPSTASH_REDIS_REST_TOKEN` at a real Upstash database to run the same
cases through `@upstash/redis`.
46 changes: 46 additions & 0 deletions packages/cache-upstash-redis/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "@pegma/cache-upstash-redis",
"version": "0.1.0",
"description": "Upstash 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-upstash-redis"
},
"dependencies": {
"@pegma/cache-core": "0.1.0",
"@pegma/cache-redis": "0.1.0",
"@pegma/spine": "0.1.2",
"@upstash/redis": "^1.38.2"
},
"devDependencies": {
"@pegma/cache-conformance": "0.1.0",
"ioredis": "^5.8.2"
},
"scripts": {
"build": "tsc -p tsconfig.json",
"check": "tsc -p tsconfig.json --noEmit",
"prepack": "pnpm run build"
}
}
Loading
Loading