Skip to content

Scripting

Scripting in Varc

Write bounded TypeScript automation against Redis and Valkey, with editor guidance and explicit control over host access.

Varc scripts are small TypeScript programs that run inside the desktop app. Use them to inspect or change Redis data, build repeatable command macros, decode binary values, and calculate dashboard results.

Varc includes a bounded JavaScript and TypeScript engine for this work. It is not Node.js or Redis-hosted Lua: scripts get a typed redis API, selected web APIs, and a deliberately small set of globals. Filesystem access, arbitrary npm installation, and ambient browser or Node APIs are not available.

Before you start

Open a connection workspace, then choose Automate → Scripts from the Dock. The Scripts tool needs an active Redis or Valkey connection before it can run code.

Every new editor starts as a manual script. You can run it without saving, but host permissions such as Network are granted only to saved scripts.

Run your first script

Paste this into the editor:

import { formatISO } from "date-fns";

const keyCount = await redis.dbsize();
const checkedAt = formatISO(new Date());

console.info(`Found ${keyCount} keys`);
return { keyCount, checkedAt };

Choose Run. Varc shows captured console messages and the returned value in Run output.

Three rules explain most scripts:

  1. Top-level await is available, so Redis calls do not need an extra function wrapper.
  2. Only an explicit return becomes the run result. A trailing expression is ignored.
  3. When the value being returned is a Promise, use return await promise so the result is resolved before the run ends.
Planned capture: one connected workspace, the first-script source, its console message, and its returned value in the same frame.

Read and write Redis data

The root redis object targets the workspace’s current logical database:

const current = await redis.get("feature:state");
await redis.set("feature:state", "ready");
return { database: redis.database, previous: current };

Scripts may perform ordinary writes, so Varc can ask for confirmation before a write-capable run. Administrative, connection-affine, and server-side scripting commands remain blocked by the central command policy.

Use redis.db(n) when the script must target another logical database explicitly:

const queueDepth = await redis.db(2).llen("jobs:ready");
return { database: 2, queueDepth };

Cluster connections support database 0 only. All database routes share the same run deadline and operation quotas.

Save and reuse it

Choose Save, give the script a name, and keep it as Manual for an ordinary library script. Saved scripts can be opened from the library and run against any compatible connection.

Turn on Macro when the script should appear in the macro palette or a configured macro slot. Use the separate Transformers tool for pure value decoders. Dashboard scripts are authored from the Dashboard widget composer.

See execution classes for the differences before moving code between those surfaces.

Use editor assistance

The editor type-checks against the same APIs available when the script runs. It provides:

  • completion and hover information for redis, env, Fetch, and the other globals available to the current execution class;
  • package-root completion in static imports;
  • named-export and member completion from each embedded module’s declarations;
  • diagnostics, declaration navigation, aliased imports, and import type support.

The editor does not automatically insert a missing import for an unimported symbol. Start the static import yourself, then use completion inside the module specifier or imported member list.

Choose what to learn next