Skip to content
WebShield Docs

Valkey store

A Redis-compatible key-value store for apps — creation, connection and code examples.

Valkey is a managed key-value store compatible with Redis clients. Apps use it for caches, sessions and queues; you connect with an ordinary Redis client using a string from an environment variable.

Do not confuse it with the KV store of functions: that one lives inside a function, while Valkey is a separate project resource available to apps. For tables and SQL — Postgres.

In the control panel: project card → Valkey block → Create. From the terminal:

Terminal window
webshield apps kv create cache --memory 128 # 128 MB, in memory only
webshield apps kv create cache --memory 128 --persistent # survives a restart
webshield apps kv list # the stores of the project
webshield apps kv delete cache # delete

Memory is 64 to 512 MB. By default data lives in memory only and is lost on restart; with --persistent (in the control panel — Keep on disk) it survives.

A reference to the store works like the databases: ${{cache.url}} in an app variable.

Terminal window
webshield apps env set REDIS_URL='${{cache.url}}' --redeploy

Node.js with the redis client:

import { createClient } from "redis";
const redis = createClient({ url: process.env.REDIS_URL });
await redis.connect();
await redis.set("greeting", "hello");
console.log(await redis.get("greeting")); // hello
await redis.incr("hits");

Python with redis:

import os
import redis
r = redis.from_url(os.environ["REDIS_URL"])
r.set("greeting", "hello")
print(r.get("greeting").decode()) # hello

When memory is full, writes fail (OOM command not allowed); keys are not evicted on their own. For a cache that drops old entries, give keys a time to live (EXPIRE).