Skip to content

You can use Clever Tools to send Redis protocol commands to Materia KV and Redis® add-ons. Create a Materia KV add-on, then send it commands with clever kv:

clever addon create kv session-cache
clever kv session-cache PING
clever kv session-cache PING Hello

The first PING returns PONG; the second returns Hello. Clever Tools connects using the add-on’s REDIS_URL environment variable. You can identify the add-on by its name, add-on ID or real ID. Use an ID when several add-ons share the same name.

To limit the lookup to an organisation, add --org (or -o):

clever kv session-cache PING --org platform-team

Commands

You can send any Redis protocol command supported by your add-on. For example, store and retrieve a value, increment a counter, or set a key that expires after 120 seconds:

clever kv session-cache SET session-status active
clever kv session-cache GET session-status
clever kv session-cache INCR session-count
clever kv session-cache SET session-status active EX 120
clever kv session-cache TTL session-status

Each clever kv call opens a single connection, sends one command, and closes it. Clever Tools refuses the commands that would wait forever on such a connection, such as SUBSCRIBE or CLIENT REPLY OFF, before connecting. A write is never sent twice: if the connection drops, the command fails, so check whether it landed before you retry.

Use COMMAND to inspect the commands supported by the add-on:

clever kv session-cache COMMAND

To query a stored JSON string with jq, pass the value directly to it:

clever kv session-cache SET session-details '{"status": "active"}'
clever kv session-cache GET session-details | jq .status

Use --format json (or -F json) to encode the command result as JSON. This is useful for responses containing arrays, such as SCAN:

clever kv session-cache SCAN 0 -F json | jq '.[1]'

SCAN returns a cursor and a batch of keys. Repeat it with the returned cursor until the cursor is 0 to complete the iteration.

Integer replies outside the safe integer range of JavaScript, beyond ±9,007,199,254,740,991, may lose precision. Clever Tools prints a warning on the standard error output for an integer reply, but doesn’t check integers nested in a list. To see such a value exactly, read it back with a command that returns text, such as GET for a string key or HGET for a hash field.

Last updated on