Lux Docs

Build on Lux without guessing.

Lux Cloud + OSS core

Product docs for the Lux runtime: tables, cache, vectors, realtime, time series, auth, HTTP, SDK, CLI, and self-hosting.

Strings

The most fundamental data type in Lux. Strings can hold any binary data up to 512MB, including text, serialized JSON, or raw bytes. They also support atomic integer and float operations.

SET / GET

Set a key to a string value and retrieve it. SET supports optional expiration and conditional flags.

Syntax
SET key value [EX seconds | PX milliseconds] [NX | XX]
GET key
Example
> SET user:1 "alice" EX 3600
OK
> GET user:1
"alice"
> SET lock:checkout "held" NX
OK
> SET lock:checkout "other" NX
(nil)

SETNX / SETEX / PSETEX

SETNX sets a key only if it does not exist. SETEX and PSETEX set a value with an expiration in seconds or milliseconds.

Syntax
SETNX key value
SETEX key seconds value
PSETEX key milliseconds value
Example
> SETNX session:abc "data"
(integer) 1
> SETEX cache:page 300 "<html>..."
OK
> PSETEX temp:token 1500 "xyz"
OK

MGET / MSET / MSETNX

Batch get or set multiple keys in a single round trip. MSETNX only sets all keys if none of them exist.

Syntax
MSET key value [key value ...]
MGET key [key ...]
MSETNX key value [key value ...]
Example
> MSET name "alice" age "30" city "nyc"
OK
> MGET name age city
1) "alice"
2) "30"
3) "nyc"

GETSET / GETDEL / GETEX

Atomic read-and-modify operations. GETSET replaces a value and returns the old one. GETDEL returns and deletes. GETEX returns the value and optionally sets a new expiration.

Example
> SET counter "10"
OK
> GETSET counter "0"
"10"
> GETDEL temp:job
"payload-data"
> GETEX session:x EX 600
"active"

INCR / DECR / INCRBY / DECRBY / INCRBYFLOAT

Atomic numeric operations on string values. The value must be parseable as an integer (or float for INCRBYFLOAT).

Example
> SET hits 100
OK
> INCR hits
(integer) 101
> INCRBY hits 50
(integer) 151
> DECRBY hits 10
(integer) 141
> INCRBYFLOAT price 2.5
"142.5"

APPEND / STRLEN / GETRANGE / SETRANGE

String manipulation. APPEND concatenates to an existing value. STRLEN returns the length. GETRANGE and SETRANGE operate on substrings by byte offset.

Example
> SET greeting "Hello"
OK
> APPEND greeting " World"
(integer) 11
> STRLEN greeting
(integer) 11
> GETRANGE greeting 0 4
"Hello"
> SETRANGE greeting 6 "Lux!!"
(integer) 11
> GET greeting
"Hello Lux!!"

Command Reference

CommandDescription
SETSet a key to a value with optional expiration and flags
GETGet the value of a key
SETNXSet key only if it does not exist
SETEXSet key with expiration in seconds
PSETEXSet key with expiration in milliseconds
GETSETSet key and return the previous value
GETDELGet the value and delete the key
GETEXGet the value and optionally set expiration
MGETGet values of multiple keys
MSETSet multiple key-value pairs
MSETNXSet multiple keys only if none exist
STRLENGet the length of the string value
APPENDAppend a value to an existing string
INCRIncrement integer value by 1
DECRDecrement integer value by 1
INCRBYIncrement integer value by a given amount
DECRBYDecrement integer value by a given amount
INCRBYFLOATIncrement float value by a given amount
GETRANGEGet a substring by byte offsets
SETRANGEOverwrite part of a string at a byte offset