lmvalkey guide

Overview

lmvalkey embeds the upstream Valkey in-memory datastore, a zero-dependency HTTP JSON REST server (src/rest.c), and the lmcode-cpp bytecode virtual machine (src/lmcode_host.cpp) inside a single native executable. Both protocol listeners operate on the same in-memory keyspace, allowing native RESP clients, HTTP clients, and LMScript _lmcode_ programs to read and mutate shared state without external proxies or adapters.

Unified RESP and HTTP REST architecture

Standard Valkey deployments speak only the Redis Serialization Protocol (RESP), requiring specialized client drivers or sidecar proxies when HTTP services or AI agents need to inspect keys. lmvalkey integrates HTTP directly into the server core:

Embedded lmcode host, pipelined batches, and offline fallback

When invoked with --lmcode <file.dslb>, lmvalkey executes compiled LMScript bytecode using its built-in ValkeyClient and Batch classes:

Standard lmcode_std_v3 REST and CLI interfaces

In addition to context valkey, lmvalkey embeds the 226-signature lmcode_std_v3 standard library (src/stdlib/rest.hpp). Scripts can define custom application-level HTTP routes and CLI subcommands backed by Valkey storage:

p = _lmcode_ cli="lmvalkey" install="github:lmctl-ai/lmvalkey@latest";
@"--ns"
fn opt_ns(x: RestExchange) -> void implements CliOption {
  x.set("ns", x.query("ns"));
}

@"seed"
fn cmd_seed(x: RestExchange) -> void implements CliCommand {
  let ns = x.get("ns");
  let b = valkey.batch();
  b.set(ns + ":a", "10").set(ns + ":b", "20");
  x.send(b.exec());
}

@"/read/:ns/:item"
fn get_item(x: RestExchange) -> void implements RestGet {
  let k = x.param("ns") + ":" + x.param("item");
  x.json("{\"key\":\"" + k + "\",\"val\":\"" + valkey.get(k) + "\"}");
}

rest_config("session", "global");
assert_eq(rest_cli(str_split("--ns=prod seed", " ")), "[\"OK\",\"OK\"]");
assert_eq(rest_cli(str_split("/read/prod/a", " ")), "{\"key\":\"prod:a\",\"val\":\"10\"}");
end _lmcode_

Combining lmvalkey with lmconn and lmcurl

In multi-tool integration tests, start lmvalkey as a background daemon (--port 6379 --rest-port 8080 --daemonize yes), seed fixture batches through an _lmcode_ block on cli="lmvalkey", verify RESP wire responses with lmconn valkey ... --mode resp, and run JSONPath contract assertions against http://127.0.0.1:8080/get/... or /cmd using lmcurl.