An in-memory database that supports basic CRUD operations, incrementing/decrementing numeric values, and setting TTLs for keys.
Note that this implementation is not thread-safe and should not be used in a multi-threaded environment.
Sets the value for a given key.
If the key already has a TTL, it will be cleared.
Parameters
key
(string): The key to set.value
(any): The value to set.
Gets the value for a given key.
Parameters
key
(string): The key to get.
Returns
- (any | null): The value for the key, or null if the key does not exist.
Deletes a key from the database.
Parameters
key
(string): The key to delete.
Sets a TTL for a given key.
If the key already has a TTL, it will be cleared before setting a new one.
Parameters
key
(string): The key to set a TTL for.seconds
(number): The number of seconds until the key expires.
Increments a numeric value for a given key.
If the key does not exist, it will be created with a value of 1.
Parameters
key
(string): The key to increment.
Returns
- (number | null): The new value for the key, or null if the value is not a number.
Decrements a numeric value for a given key.
If the key does not exist, it will be created with a value of -1.
Parameters
key
(string): The key to decrement.
Returns
- (number | null): The new value for the key, or null if the value is not a number.
Checks if a key exists in the database.
Parameters
key
(string): The key to check.
Returns
- (boolean): True if the key exists, false otherwise.
Clears all keys from the database.