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.
SET key value [EX seconds | PX milliseconds] [NX | XX]
GET key> 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.
SETNX key value
SETEX key seconds value
PSETEX key milliseconds value> SETNX session:abc "data"
(integer) 1
> SETEX cache:page 300 "<html>..."
OK
> PSETEX temp:token 1500 "xyz"
OKMGET / MSET / MSETNX
Batch get or set multiple keys in a single round trip. MSETNX only sets all keys if none of them exist.
MSET key value [key value ...]
MGET key [key ...]
MSETNX key value [key value ...]> 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.
> 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).
> 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.
> 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
| Command | Description |
|---|---|
| SET | Set a key to a value with optional expiration and flags |
| GET | Get the value of a key |
| SETNX | Set key only if it does not exist |
| SETEX | Set key with expiration in seconds |
| PSETEX | Set key with expiration in milliseconds |
| GETSET | Set key and return the previous value |
| GETDEL | Get the value and delete the key |
| GETEX | Get the value and optionally set expiration |
| MGET | Get values of multiple keys |
| MSET | Set multiple key-value pairs |
| MSETNX | Set multiple keys only if none exist |
| STRLEN | Get the length of the string value |
| APPEND | Append a value to an existing string |
| INCR | Increment integer value by 1 |
| DECR | Decrement integer value by 1 |
| INCRBY | Increment integer value by a given amount |
| DECRBY | Decrement integer value by a given amount |
| INCRBYFLOAT | Increment float value by a given amount |
| GETRANGE | Get a substring by byte offsets |
| SETRANGE | Overwrite part of a string at a byte offset |