Prithvi

Core Features

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.

Command Reference

Below is a quick overview of common Prithvi commands, what they do, and their syntax.

CommandSyntaxDescription
SETSET <key> <value> [EX <seconds>]Store a value with optional TTL
GETGET <key>Retrieve value and expiry info
DELDEL <key>Delete a key
EXISTSEXISTS <key>Check if key exists
SADDSADD <key> <val>Add a value to a Set
SMEMBERSSMEMBERS <key>Retrieve all members of a Set
SREMSREM <key> <val>Remove a value from a Set
LPUSH / RPUSHLPUSH <key> <val>Push to List (left/right)
LPOP / RPOPLPOP <key>Pop from List (left/right)
KEYSKEYSList all keys with TTL
SAVE / LOADSAVEManual persistence
AUTH / TOKENAUTH <user>Authentication + session
FLUSHFLUSH or FLUSH FALLClear DB with/without confirm
HELPHELPPrints all commands

Time To Live

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

LRU Cache

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

Persistence

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

Key Points

  • State is saved to data/store.json.
  • TTL info, lists, sets, and values are fully preserved.
  • No need for external DBs or setup — it's built-in.
  • Persistence is optional, controlled by user commands.

Authentication

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

Key Points

  • Tokens are generated in-memory per session.
  • No external login, no password hashing, no encryption.
  • Use only for local development or demos.
  • To secure in production, use proper OAuth/JWT frameworks.

Prithvi

An open-source, Java-based key-value store engineered for speed, simplicity, and developer control.

© 2025 Prithvi — Built with Java | PHILKHANA SIDHARTH