Search by

tenma / redis

Lento Leisenfeld

A Valkey server of the app's own on Tenma, for Redis clients: started next to the app through a native plugin, stopped with it.

v0.1.0 2026-10-31 11:45 UTC

This package is not auto-updated.

Last update: 2026-10-31 21:20:41 UTC


README

A Redis server of the app's own on Tenma. The app starts it next to itself, with its data in a directory the app chooses, and Tenma stops it when the app ends. Meant for apps that ship as one download and want shared state, a cache or messages between processes without asking the user to set up a server.

The server is Valkey (BSD-3-Clause), which speaks the Redis protocol; Tenma's Data\Redis talks to it as it is.

use Data\Redis;
use Tenma\Redis\Server;

$server = Server::start(__DIR__ . '/data/redis', maxMemory: 256 * 1024 * 1024);
$redis = Redis::connect($server->url());
  • The first start creates the directory (mode 0700) and a random password, kept in data/redis/tenma-password (mode 0600). valkey.conf holds it too and is written on every start, also with mode 0600, so the password never shows as an argument in ps.
  • The server listens on 127.0.0.1 only, on a free port. Unix sockets stay off.
  • Every write goes to the append-only file and is synced once a second: keys survive a restart.
  • maxMemory (bytes) limits the memory, set on every start. Keys with an expiry give way first; once only keys without one are left, writes fail. Without it there is no limit.
  • It runs once per process: every worker gets the same server. A server that an earlier process left running on the same directory (a restart in watch mode, a crash) is found and used.
  • It stops when tenma ends: after Ctrl+C or SIGTERM, and when a script that serves nothing finishes. Only the process that owns it stops it (its PID is in tenma-owner): a second tenma on the same directory while the owner runs, such as a command-line task next to the dev server, borrows the server and leaves it running.
  • $server->url() gives redis://:PASSWORD@127.0.0.1:PORT, the form of REDIS_URL.

Optional by design

The package is meant to be easy to add and to drop. An app asks for its own server only when no Redis is configured, so the same code runs with an external Redis and without:

$url = getenv('REDIS_URL') ?: Server::start($home . '/data/redis')->url();

Without the package, that line becomes the plain REDIS_URL, and nothing else changes.

Install

composer require tenma/redis
vendor/bin/tenma-redis install

The install downloads the plugin of this version for the machine and valkey-server, built for this release from Valkey's source without TLS, checks both against their SHA-256, puts Valkey in vendor/tenma/redis/valkey/ and adds the plugin to tenma.json.

Platforms: macOS arm64, Linux x64 and arm64.

Develop

cd plugin && cargo build --release && mkdir -p ../lib
cp target/release/libtenma_redis.dylib ../lib/tenma_redis.plugin   # .so on Linux
# Valkey: make BUILD_TLS=no valkey-server in its source, then copy src/valkey-server to valkey/
composer test

The tests run the plugin under a real tenma and skip when tenma, the plugin or Valkey is missing.

License

The package: MIT or Apache-2.0, at your option. Valkey itself: BSD-3-Clause; the install puts its license and those of the libraries built into it in valkey/licenses/.