Command: DELETE
Overview
The DELETE
command is used to remove a key-value pair from the in-memory database. It ensures the specified key is validated, removes it from the appropriate memory shard.
Command Name
DELETE
Description
Deletes a key and its associated value from the database. If the key exists, it is removed. If the key does not exist, the command still responds with a successful “Ok” to maintain idempotency.
Syntax
DELETE <key>
<key>
: The string identifier of the key to be deleted from the database.
Permissions
- No authentication or role-based permission checks are implemented in the current version.
- All connected clients can issue
DELETE
commands.
Examples
Example 1: Valid key
localhost:9219> DELETE user:1001
Example 2: Key does not exist
localhost:9219> DELETE unknownKey
Example 3: Invalid syntax
localhost:9219> DELETE
Example 1: Key successfully deleted
Ok
Example 2: Key did not exist (still considered successful)
Ok
Use Cases
Cleanup stale data
Applications can use DELETE
to remove expired or stale data from the database once it’s no longer needed.
Idempotent API behavior
DELETE
can be called multiple times safely — even if the key doesn’t exist — making it ideal for REST-like APIs where DELETE operations are meant to be idempotent.
User data revocation
In systems that manage user sessions or temporary keys, DELETE
is used to revoke access or clear temporary state.