Skip to content

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).

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 error

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 plain int64 millisecond count; 60_000 is exactly SET key value PX 60000. Pass 0 for 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).
  • Wrong arity replies -ERR wrong number of arguments for 'set' command.
  • Invalid TTL replies -ERR syntax error.
  • With RBAC enabled, SET is gated per key; a denial replies -NOPERM.