Skip to content

Reference

Data type commands

Klyro implements 145 commands: 130 Redis-shaped commands plus the 15-command MEM.* family. Matching RESP reply shapes let standard client libraries decode the results.

Choose a language once and every tabbed example in the documentation follows that choice. The preference is stored only in this browser.

import { createClient } from "klyro-db";

const db = createClient();
// Run commands, then close with: await db.quit();

Generic (any type)

const exists = await db.exists("session:42");
await db.expire("session:42", 900);
const ttl = await db.ttl("session:42");
CommandReply
PING [message]PONG, or the message
ECHO messageThe message
HELLO [protover]Server info; HELLO 3 switches to RESP3
DEL key [key ...] / UNLINK key [key ...]Number of keys removed
EXISTS key [key ...]How many exist; a repeated key counts each time
EXPIRE key seconds / PEXPIRE key ms1 if the TTL was set, 0 if the key is missing
EXPIREAT key unix-seconds / PEXPIREAT key unix-ms1 or 0
PERSIST key1 if a TTL was removed, else 0
TTL key / PTTL keyTime left, -1 no expiry, -2 missing
TYPE keystring, list, hash, set, zset, memory, or none
RENAME key newkey / RENAMENX key newkeyOK, or 1/0 for the NX form
COPY source destination [REPLACE]1 if copied, else 0
RANDOMKEYA key, or nil if the keyspace is empty
KEYS patternArray of matching keys
SCAN cursor [MATCH pattern] [COUNT count][next-cursor, [keys...]]
DBSIZENumber of live keys
FLUSHDB / FLUSHALLOK; one keyspace, so both do the same thing
INFO [section]One text blob of # Section headers over key:value lines
CONFIG GET pattern [pattern ...]Map of parameter to value
CONFIG SET parameter valueOK, or an error explaining the refusal
CONFIG RESETSTATOK; clears INFO's activity counters
SAVEOK; writes the dump file immediately
QUIT / SHUTDOWNOK, then closes the connection or stops the server

COPY is a deep copy: mutating the destination afterwards leaves the source untouched. RENAME and COPY both carry the TTL across.

Strings

await db.set("session:42", "active", "EX", 900);
await db.incr("metrics:requests");
const status = await db.get("session:42");
CommandReply
SET key value [NX|XX] [GET] [EX s|PX ms|EXAT ts|PXAT ts|KEEPTTL]OK, or nil when NX/XX is not satisfied
SETNX key value1 if written, else 0
SETEX key seconds value / PSETEX key ms valueOK
GET keyThe value, or nil
GETSET key valueThe previous value, or nil; clears any TTL
GETDEL keyThe value, or nil; removes the key
GETEX key [EX s|PX ms|PERSIST]The value, or nil; adjusts the TTL
MGET key [key ...]Array of values, nil per missing key
MSET key value [key value ...]OK
MSETNX key value [key value ...]1 if all were written, 0 if any key existed
INCR / DECR / INCRBY / DECRBY key [n]The new value
INCRBYFLOAT key nThe new value, as text
APPEND key valueThe new length
STRLEN keyThe length, 0 if missing
GETRANGE key start end / SUBSTR key start endThe substring; inclusive, negatives count from the end
SETRANGE key offset valueThe new length; pads any gap with NUL bytes

Lists

await db.lpush("jobs", "generate-report");
const job = await db.brpop("jobs", 5);
CommandReply
LPUSH / RPUSH key value [value ...]The new length
LPUSHX / RPUSHX key value [value ...]The new length, or 0 if the key does not exist
LPOP / RPOP key [count]One value or nil; with a count, an array
LLEN keyThe length
LRANGE key start stopArray of values
LINDEX key indexThe value, or nil
LSET key index valueOK, or an error if the key or index is out of range
LINSERT key BEFORE|AFTER pivot valueThe new length, -1 if the pivot is absent, 0 if the key is
LREM key count valueHow many were removed
LTRIM key start stopOK; an empty range deletes the key
RPOPLPUSH source destinationThe moved value, or nil
LMOVE source destination LEFT|RIGHT LEFT|RIGHTThe moved value, or nil

Hashes

await db.hset("user:42", { name: "Ari", plan: "pro" });
const profile = await db.hgetall("user:42");
CommandReply
HSET key field value [field value ...]Number of fields added
HSETNX key field value1 if written, 0 if the field exists
HMSET key field value [field value ...]OK
HGET key fieldThe value, or nil
HMGET key field [field ...]Array of values, nil per missing field
HDEL key field [field ...]Number of fields removed
HLEN key / HSTRLEN key fieldThe field count / the value's length
HEXISTS key field1 or 0
HKEYS key / HVALS keyArray of fields, or of values
HGETALL keyMap of field to value
HINCRBY key field n / HINCRBYFLOAT key field nThe new value

Sets

await db.sadd("online-users", "42", "73");
const online = await db.sismember("online-users", "42");
const users = await db.smembers("online-users");
CommandReply
SADD key member [member ...]Number of members newly added
SREM key member [member ...]Number removed
SISMEMBER key member1 or 0
SMISMEMBER key member [member ...]Array of 1/0, one per member
SCARD key / SMEMBERS keyThe member count / the members
SPOP key [count]Removes and returns one member or nil; with a count, a set
SRANDMEMBER key [count]The same without removing; a negative count may repeat members
SMOVE source destination member1 if moved, else 0
SINTER / SUNION / SDIFF key [key ...]Set of members
SINTERSTORE / SUNIONSTORE / SDIFFSTORE dest key [key ...]Size of the stored result

A missing key counts as an empty set. SDIFF subtracts every later set from the first, so it is not symmetric. A STORE variant whose result is empty deletes the destination.

Sorted sets

await db.zadd("leaderboard", 980, "user:42", 860, "user:73");
const leaders = await db.zrevrange("leaderboard", 0, 9, "WITHSCORES");
CommandReply
ZADD key score member [score member ...]Number of members newly added
ZSCORE key member / ZMSCORE key member [member ...]The score, or nil
ZINCRBY key increment memberThe new score; a missing member starts at 0
ZREM key member [member ...]Number removed
ZCARD keyThe member count
ZRANK / ZREVRANK key memberThe 0-based rank, or nil
ZRANGE / ZREVRANGE key start stop [WITHSCORES]Members by score
ZRANGEBYSCORE / ZREVRANGEBYSCORE key min max [WITHSCORES]Members inside the score window
ZCOUNT key min maxHow many fall inside the window
ZREMRANGEBYRANK / ZREMRANGEBYSCORE key start stopNumber removed
ZPOPMIN / ZPOPMAX key [count]The popped members with their scores

Score bounds accept a plain number, -inf/+inf, or a ( prefix for an exclusive bound, as in ZCOUNT board (75 +inf.

Rules that apply everywhere

  • A command against a key holding a different type replies WRONGTYPE, for instance LPUSH on a key created by SET.
  • Removing the last element of a collection deletes the key, same as Redis.
  • Keys, values, fields, and members are arbitrary bytes: they may contain spaces, newlines, and NUL bytes. So are a memory record’s text and metadata.
  • Calling an unimplemented Redis command returns ERR unknown command. See limitations for what is missing.