Prithvi is an in-memory key-value store built in Java, with support for TTL, LRU caching, list and set operations, authentication, and disk persistence. You can connect via a TCP client on port 1902 to start issuing commands.
Below is a quick overview of common Prithvi commands, what they do, and their syntax.
| Command | Syntax | Description |
|---|---|---|
| SET | SET <key> <value> [EX <seconds>] | Store a value with optional TTL |
| GET | GET <key> | Retrieve value and expiry info |
| DEL | DEL <key> | Delete a key |
| EXISTS | EXISTS <key> | Check if key exists |
| SADD | SADD <key> <val> | Add a value to a Set |
| SMEMBERS | SMEMBERS <key> | Retrieve all members of a Set |
| SREM | SREM <key> <val> | Remove a value from a Set |
| LPUSH / RPUSH | LPUSH <key> <val> | Push to List (left/right) |
| LPOP / RPOP | LPOP <key> | Pop from List (left/right) |
| KEYS | KEYS | List all keys with TTL |
| SAVE / LOAD | SAVE | Manual persistence |
| AUTH / TOKEN | AUTH <user> | Authentication + session |
| FLUSH | FLUSH or FLUSH FALL | Clear DB with/without confirm |
| HELP | HELP | Prints all commands |
Prithvi lets you store keys temporarily using TTL. You can attach an expiry time (in seconds) when setting a key. Once the time is up, the key vanishes — no manual deletion needed.
Booleans use true or false, strings go inside double quotes, and integers are written as-is. Terminate every declaration with a semicolon.
Terminal
1 SET X 4 EX 8;
2 GET X
3 4;
4 # After 8 seconds
5 GET X
5 nil // Value has expired
Prithvi uses an LRU (Least Recently Used) eviction policy if the number of keys exceeds the configured limit (default is 5). When a new key is added beyond the limit, the least recently used key is removed.
Here's a code example demonstrating this behavior. The key A will be evicted once F is inserted, since it was the oldest and not recently accessed.
Terminal
1 SET A 1;
2 SET B 2;
3 SET C 3;
4 SET D 4;
5 SET E 5;
// LRU limit reached (5 keys)
6 SET F 6;
// 'A' is least recently used and will be evicted
LISTALL; // returns B, C, D, E, F
By default, Prithvi stores data in memory — fast, but ephemeral. To persist across restarts or failures, Prithvi offers two built-in commands: SAVE and LOAD.
- SAVE writes the current in-memory state to data/store.json.
- LOAD reads from this file and restores state exactly as before — keys, TTLs, types and all.
Terminal
1 SET language Sanskrit
2 SAVE
Saved to Disk!
3 LOAD
Loaded from Disk!
4 GET language
5 Sanskrit
data/store.json.Prithvi supports a minimal built-in auth system — just enough to get by with basic sessions. It’s **not cryptographically secure** and should not be used in production or internet-facing systems.
- AUTH <username> generates a unique session token.
- TOKEN <token> is required in each session to validate access.
Terminal
1 AUTH boss
2 TOKEN 39rhsbdkuhqwn8397828f2fn2yc2dnu9w13d10d
Session Token Validated
3 TOKEN 39rhsbdkuhqwn8397828f2fn2yc2dnu9w13d10d
# User Authenticated