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.
Creation
Section titled “Creation”In the control panel: project card → Valkey block → Create. From the terminal:
webshield apps kv create cache --memory 128 # 128 MB, in memory onlywebshield apps kv create cache --memory 128 --persistent # survives a restartwebshield apps kv list # the stores of the projectwebshield apps kv delete cache # deleteMemory 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.
Connection
Section titled “Connection”A reference to the store works like the databases: ${{cache.url}} in an app variable.
webshield apps env set REDIS_URL='${{cache.url}}' --redeployUsing from code
Section titled “Using from code”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")); // helloawait redis.incr("hits");Python with redis:
import osimport redis
r = redis.from_url(os.environ["REDIS_URL"])r.set("greeting", "hello")print(r.get("greeting").decode()) # helloWhen memory is full
Section titled “When memory is full”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).