Better Auth secondary storage backed by Bun's built-in Redis client
Better Auth secondary storage backed by Bun’s built-in Redis client.
The official @better-auth/redis-storage requires ioredis, which exposes call() and eval() that Bun.RedisClient does not have. This package targets Bun.RedisClient directly, so a Bun project needs no third-party Redis client — and no runtime dependency at all.
Bun.RedisClientGETDEL commandTested in CI against Redis 8 and Valkey 9.
bun add @kevinmarrec/better-auth-bun-redis
import { bunRedisStorage } from '@kevinmarrec/better-auth-bun-redis'
import { betterAuth } from 'better-auth'
export const auth = betterAuth({
secondaryStorage: bunRedisStorage({ client: Bun.redis }),
})
Bun.redis is the lazily-connected default client, reading REDIS_URL from the environment. Pass your own instance to control the connection:
const client = new Bun.RedisClient('redis://localhost:6379')
export const auth = betterAuth({
secondaryStorage: bunRedisStorage({ client, keyPrefix: 'my-app:' }),
})
The client’s lifecycle stays yours: this package never calls connect() or close().
| Option | Default | Purpose |
|---|---|---|
client |
– | The Bun.RedisClient instance to use |
keyPrefix |
'better-auth:' |
Prefix applied to every key |
Alongside Better Auth’s SecondaryStorage methods, the returned object exposes two helpers, matching @better-auth/redis-storage:
listKeys() — the stored keys, prefix strippedclear() — delete every key under the prefixBoth enumerate with SCAN rather than the blocking KEYS. clear() is not atomic: it deletes page by page, so a rejection means an unknown subset may already be gone. It is idempotent, so retry until it resolves.
Integration tests need a server:
docker compose up -d
Then run the suite against Redis (default) or Valkey:
bun test
REDIS_URL=redis://127.0.0.1:6380 bun test