SET
SET stores a value under a key. Every key pins to exactly one shard via
FNV-1a hashing, so the write touches a single shard and never crosses shard
boundaries (see Architecture).
RESP2 (Redis-compatible)
Section titled “RESP2 (Redis-compatible)”SET key value [EX <seconds> | PX <milliseconds>]Exactly one of EX (seconds) or PX (milliseconds) may follow the value. A
negative or non-numeric TTL is a syntax error.
Reply: +OK on success.
> SET session:42 "{}" EX 60+OK> SET cached "hello" PX 5000+OK> SET bad "x" EX -1-ERR syntax errorNative binary protocol
Section titled “Native binary protocol”The client package exposes Set:
c, _ := client.Dial("127.0.0.1:9988", 2*time.Second)defer c.Close()
scratch := make([]byte, 4096)if _, err := c.Set([]byte("greeting"), []byte("hello"), 60_000, scratch); err != nil { log.Fatal(err)}ttlMs— a plainint64millisecond count;60_000is exactlySET key value PX 60000. Pass0for no expiry.scratchBuf— a reusable buffer for the server response; it must be large enough to hold the reply.- An empty key is rejected (
EMPTY_KEY).
Error handling
Section titled “Error handling”- Wrong arity replies
-ERR wrong number of arguments for 'set' command. - Invalid TTL replies
-ERR syntax error. - With RBAC enabled,
SETis gated per key; a denial replies-NOPERM.