String Commands
String commands operate on string values. In Redlite, strings are stored as binary data (bytes).
Get the value of a key.
GET keyReturns:
- The value if key exists
nilif key does not exist
Example:
127.0.0.1:6767> SET greeting "Hello"OK127.0.0.1:6767> GET greeting"Hello"127.0.0.1:6767> GET nonexistent(nil)Library:
let value = db.get("key")?; // Option<Vec<u8>>Set the value of a key.
SET key value [EX seconds | PX milliseconds] [NX | XX]Options:
EX seconds- Set expiration in secondsPX milliseconds- Set expiration in millisecondsNX- Only set if key does NOT existXX- Only set if key DOES exist
Returns:
OKif successfulnilif NX/XX condition not met
Examples:
# Basic set127.0.0.1:6767> SET name "Alice"OK
# With expiration (60 seconds)127.0.0.1:6767> SET session "abc123" EX 60OK
# With expiration (5000 milliseconds)127.0.0.1:6767> SET temp "quick" PX 5000OK
# Only if not exists (NX)127.0.0.1:6767> SET counter 0 NXOK127.0.0.1:6767> SET counter 1 NX(nil)
# Only if exists (XX)127.0.0.1:6767> SET counter 10 XXOK127.0.0.1:6767> SET newkey value XX(nil)Library:
use std::time::Duration;use redlite::SetOptions;
// Basicdb.set("key", b"value", None)?;
// With TTLdb.set("key", b"value", Some(Duration::from_secs(60)))?;
// With optionsdb.set_opts("key", b"value", SetOptions::new().nx())?;db.set_opts("key", b"value", SetOptions::new().xx().ex(Duration::from_secs(60)))?;Delete one or more keys.
DEL key [key ...]Returns:
- Number of keys deleted
Example:
127.0.0.1:6767> SET key1 "a"OK127.0.0.1:6767> SET key2 "b"OK127.0.0.1:6767> DEL key1 key2 key3(integer) 2Library:
db.del(&["key1", "key2", "key3"])?;Connection Commands
Section titled “Connection Commands”Test server connectivity.
PING [message]Returns:
PONGif no message provided- The message if provided
Example:
127.0.0.1:6767> PINGPONG127.0.0.1:6767> PING "hello""hello"Echo the given message.
ECHO messageReturns:
- The message
Example:
127.0.0.1:6767> ECHO "Hello, World!""Hello, World!"COMMAND
Section titled “COMMAND”Get information about Redis commands.
COMMANDReturns:
- Array of command information
Example:
127.0.0.1:6767> COMMAND1) 1) "ping" 2) (integer) -1...Expiration Behavior
Section titled “Expiration Behavior”Keys with TTL are lazily expired:
- Expiration is checked on read (GET)
- Expired keys return
niland are deleted
127.0.0.1:6767> SET temp "value" PX 100OK127.0.0.1:6767> GET temp"value"# Wait 100ms127.0.0.1:6767> GET temp(nil)