Redis
DocsDatabasesRedis

Redis

Redis-compatible cache and data store on StackBlaze, served by Valkey, for caching, session storage, pub/sub, and job queues.

This demo adds Valkey from the catalog, attaches it to the app, and shows REDISHOST, REDISPORT, and REDIS_URL injected.

Powered by Valkey

Redis on StackBlaze is served by Valkey, the open-source, Redis-compatible fork backed by the Linux Foundation. Your Redis clients, commands, and connection strings work unchanged. In the catalog the add-on is named Valkey.

Creating a Valkey instance

From the project canvas, click + ServiceDatabasesValkey. Stage the add-on, then click Commit.

To attach it to an app, use the add-on's Connections list or the app's Add-ons tab. StackBlaze injects connection environment variables into the app. There is no Environment tab → Attach database flow. To inspect or add your own variables, use the app's Variables tab.

Injected environment variables

Valkey on StackBlaze is password-less. Attached apps receive:

VariableRole
REDISHOSTInstance hostname
REDISPORT6379
REDIS_URLredis://host:6379
REDIS_URL
redis://[host]:6379

There is no password in the URL, and no TLS URL scheme. Use the injected REDIS_URL as-is.

Browse and query with CloudBeaver

Every database add-on ships with CloudBeaver. Open with DB Beaver on the add-on's Overview starts a scoped session where you can browse tables, run SQL, and edit data in the browser.

Open with DB Beaver launches a scoped CloudBeaver session where the users table is browsed, a query runs, and the results appear.

Common use cases

Caching (Node.js / ioredis)

cache.ts
import Redis from 'ioredis'

const redis = new Redis(process.env.REDIS_URL)

async function getUser(id: string) {
  const cached = await redis.get(`user:${id}`)
  if (cached) return JSON.parse(cached)

  const user = await db.users.findById(id)
  await redis.setex(`user:${id}`, 3600, JSON.stringify(user)) // TTL: 1 hour
  return user
}

Session storage (Express + connect-redis)

server.ts
import session from 'express-session'
import { createClient } from 'redis'
import { RedisStore } from 'connect-redis'

const client = createClient({ url: process.env.REDIS_URL })
await client.connect()

app.use(session({
  store: new RedisStore({ client }),
  secret: process.env.SESSION_SECRET,
  resave: false,
  saveUninitialized: false,
  cookie: { secure: true, maxAge: 86400000 }, // 24 hours
}))

Job queues with BullMQ

queue.ts
import { Queue, Worker } from 'bullmq'

const connection = { url: process.env.REDIS_URL }

// Producer: add jobs from your API
const emailQueue = new Queue('emails', { connection })

export async function sendWelcomeEmail(userId: string) {
  await emailQueue.add('welcome', { userId }, {
    attempts: 3,
    backoff: { type: 'exponential', delay: 2000 },
  })
}

// Consumer: process jobs in a worker service
const worker = new Worker('emails', async (job) => {
  const { userId } = job.data
  await mailer.sendWelcome(userId)
}, { connection })

Pub/Sub (broadcasting across pods)

When you scale your web service horizontally, use Redis pub/sub to broadcast events across all running instances. This is especially useful for WebSocket servers that need to push to all connected clients.

pubsub.ts
import { createClient } from 'redis'

const publisher = createClient({ url: process.env.REDIS_URL })
const subscriber = publisher.duplicate()

await publisher.connect()
await subscriber.connect()

// Publish from any pod
await publisher.publish('notifications', JSON.stringify({ userId, message }))

// Subscribe on all pods
await subscriber.subscribe('notifications', (message) => {
  const { userId, message: msg } = JSON.parse(message)
  io.to(userId).emit('notification', msg) // Socket.IO broadcast
})

Backups

Backups are not enabled automatically. Open the Valkey add-on, go to the Backups tab, and click Enable backups. From there you can use Backup now, Restore, and Schedule.

Valkey backups are RDB snapshots. Restore always creates a new instance — there is no in-place restore. After the new instance is ready, switch the app connection to it from the add-on Connections list or the app Add-ons tab.

For the full backup workflow, see Backups & recovery.

Eviction policy

When Valkey reaches its memory limit, it uses an eviction policy to decide which keys to remove. The default policy is typically allkeys-lru (evict least recently used keys first), which is appropriate for cache workloads.

For session storage or job queues where silent key loss is unacceptable, use a policy such as noeviction so the instance returns errors when memory is full rather than dropping keys.

Tip

Use REDIS_URL or the pair REDISHOST / REDISPORT. Do not add a password to the URL.

Under the hood

The catalog add-on is Valkey. Attached apps reach it over the project's private network on port 6379 with no password.