> ## Documentation Index
> Fetch the complete documentation index at: https://cache-pot.thatdevguy.in/llms.txt
> Use this file to discover all available pages before exploring further.

# Cache-Pot data types: strings, hashes, lists, sets, vectors

> Cache-Pot supports six data types: strings, hashes, lists, sets, sorted sets, and vector collections. Each type has its own set of commands.

Cache-Pot supports the same core data types as Redis — strings, hashes, lists, sets, and sorted sets — plus a native **vector collection** type built for embedding-based search. Every key in the keyspace holds exactly one type, and you use that type's dedicated commands to interact with it. All types support expiry via `EXPIRE` and `PEXPIRE`, and you can always check what type a key holds with the `TYPE` command.

***

### Strings

Binary-safe values up to 512 MB. Strings are the most fundamental type and double as integers when the stored value is a valid integer — commands like `INCR` and `INCRBY` operate atomically on the numeric representation.

**Key commands:** `SET`, `GET`, `INCR`, `DECR`, `INCRBY`, `DECRBY`, `APPEND`, `STRLEN`, `GETRANGE`, `SETRANGE`, `GETSET`, `MGET`, `MSET`

<CodeGroup>
  ```bash Basic operations theme={null}
  SET counter 0
  INCR counter         # (integer) 1
  APPEND greeting "Hello"
  GET greeting         # "Hello"
  ```

  ```bash Multi-key and options theme={null}
  MSET key1 "foo" key2 "bar"
  MGET key1 key2       # 1) "foo" 2) "bar"
  SET session abc EX 3600 NX   # set only if key doesn't exist, expire in 1 hour
  ```
</CodeGroup>

***

### Hashes

Field-value maps stored under a single key — ideal for representing objects like users, sessions, or configuration records. Each field is itself a string value.

**Key commands:** `HSET`, `HGET`, `HGETALL`, `HDEL`, `HLEN`, `HKEYS`, `HVALS`, `HEXISTS`, `HMGET`

<CodeGroup>
  ```bash Basic operations theme={null}
  HSET user:1 name Alice age 30
  HGET user:1 name     # "Alice"
  HGETALL user:1       # 1) "name" 2) "Alice" 3) "age" 4) "30"
  ```

  ```bash Multiple fields theme={null}
  HMGET user:1 name age      # 1) "Alice" 2) "30"
  HLEN user:1                # (integer) 2
  HDEL user:1 age
  ```
</CodeGroup>

***

### Lists

Ordered sequences of strings where you can push and pop from either end. Use lists for queues, stacks, timelines, and any workload that needs ordered insertion.

**Key commands:** `LPUSH`, `RPUSH`, `LPOP`, `RPOP`, `LRANGE`, `LLEN`, `LINDEX`

<CodeGroup>
  ```bash Queue pattern (FIFO) theme={null}
  RPUSH queue task1 task2 task3
  LPOP queue           # "task1"
  LRANGE queue 0 -1    # 1) "task2" 2) "task3"
  ```

  ```bash Stack pattern (LIFO) theme={null}
  LPUSH stack item1 item2
  LPOP stack           # "item2"
  LLEN stack           # (integer) 1
  ```
</CodeGroup>

***

### Sets

Unordered collections of unique string members. Sets enforce uniqueness automatically — adding an already-present member is a no-op. Use sets for tags, unique visitors, or membership checks.

**Key commands:** `SADD`, `SMEMBERS`, `SISMEMBER`, `SREM`, `SCARD`

<CodeGroup>
  ```bash Basic operations theme={null}
  SADD tags go redis ai
  SISMEMBER tags go    # (integer) 1
  SMEMBERS tags        # 1) "go" 2) "redis" 3) "ai"
  ```

  ```bash Membership and removal theme={null}
  SCARD tags           # (integer) 3
  SREM tags redis
  SISMEMBER tags redis # (integer) 0
  ```
</CodeGroup>

***

### Sorted Sets

Members paired with a floating-point score. Cache-Pot keeps members ordered by score at all times, making sorted sets perfect for leaderboards, priority queues, and time-series data (using timestamps as scores).

**Key commands:** `ZADD`, `ZRANGE`, `ZRANGEBYSCORE`, `ZSCORE`, `ZREM`, `ZCARD`

<CodeGroup>
  ```bash Leaderboard theme={null}
  ZADD leaderboard 100 alice 200 bob 150 carol
  ZRANGE leaderboard 0 -1 WITHSCORES
  # 1) "alice" 2) "100" 3) "carol" 4) "150" 5) "bob" 6) "200"
  ```

  ```bash Range queries theme={null}
  ZRANGEBYSCORE leaderboard 100 200    # alice carol bob
  ZSCORE leaderboard bob               # "200"
  ZREM leaderboard alice
  ```
</CodeGroup>

***

### Vector Collections

Float32 vector arrays with cosine similarity search — Cache-Pot's native AI-oriented type. A collection is a named group of vectors that all share the same dimension. The dimension is fixed the moment you insert the first vector; subsequent inserts must match it exactly.

Each vector entry has three parts: a string **ID**, the **float32 array**, and an optional **META** string for storing arbitrary text (such as the source document or a serialised JSON payload).

**Key commands:** `VSET`, `VSEARCH`, `VDEL`, `VCARD`, `VDIM`

<CodeGroup>
  ```bash Inserting and searching vectors theme={null}
  VSET embeddings doc1 0.1 0.2 0.3 META "intro to AI"
  VSET embeddings doc2 0.9 0.8 0.7 META "advanced AI"
  VSEARCH embeddings 0.1 0.2 0.3 TOPK 5
  # 1) "doc1" 2) "intro to AI"
  ```

  ```bash Collection metadata theme={null}
  VCARD embeddings     # (integer) 2
  VDIM  embeddings     # (integer) 3
  VDEL  embeddings doc2
  ```

  ```bash Search with scores theme={null}
  VSEARCH embeddings 0.1 0.2 0.3 TOPK 5 WITHSCORES
  # 1) "doc1" 2) "intro to AI" 3) "1.0000"
  ```
</CodeGroup>

<Note>
  All vectors in a collection must have the same dimension. If you attempt a `VSET` with a different number of floats than the first insertion, Cache-Pot returns an error. Plan your embedding dimensions before populating a collection.
</Note>

***

## Inspecting key types

Use `TYPE` to check any key's type at any time:

```bash theme={null}
TYPE counter        # string
TYPE user:1         # hash
TYPE queue          # list
TYPE tags           # set
TYPE leaderboard    # zset
TYPE embeddings     # vector
TYPE missing-key    # none
```

## Key expiry

Every data type supports automatic expiry. Set a time-to-live with `EXPIRE` (seconds) or `PEXPIRE` (milliseconds), and Cache-Pot deletes the key once the TTL elapses:

```bash theme={null}
SET session "xyz" EX 3600          # string: built-in expiry
HSET user:tmp email "t@x.com"
EXPIRE user:tmp 600                # any type: set TTL separately
TTL user:tmp                       # seconds remaining
PERSIST user:tmp                   # remove TTL entirely
```

<Tip>
  Use `SCAN` with the `TYPE` filter instead of `KEYS` on large keyspaces — `SCAN` is non-blocking and cursor-based, so it doesn't stall the server while iterating millions of keys.
</Tip>
