A simple, in-memory key-value store inspired by Redis, designed for educational purposes. PyRedis supports basic key-value operations, expiration times (TTL), and automatic saving/loading of data from a JSON file.
- Set key-value pairs with optional TTL (time-to-live)
- Get values by key, with automatic expiration handling
- Delete keys
- Auto-save and load data from a JSON file
- Command-line interface for easy interaction
- Python 3.x
To get started with PyRedis, clone the repository and navigate to the project directory:
git clone https://github.com/coderooz/PyRedis.git
cd PyRedis
You can also download the repository as a ZIP file and extract it.
To run the PyRedis command-line interface, execute:
python pyredis.py
The following commands are available in the CLI:
-
SET: Set a key-value pair. Optionally, specify a TTL (in seconds).
SET key value SET key1 value1, key2 value2, ..., ttl
-
GET: Retrieve the value of a key.
GET key
-
DELETE: Remove a key from the store.
DELETE key
-
SAVE: Save the current data to a JSON file.
SAVE
-
LOAD: Load data from a JSON file.
LOAD
-
ENABLE_AUTOSAVE: Enable automatic saving of data.
ENABLE_AUTOSAVE
-
DISABLE_AUTOSAVE: Disable automatic saving of data.
DISABLE_AUTOSAVE
-
EXIT: Exit the CLI.
EXIT
Here's an example of using the PyRedis CLI:
pyredis> SET country USA
SET country = USA
pyredis> GET country
GET country = USA
pyredis> DELETE country
DELETE country
pyredis> GET country
GET country = None
You can customize the following parameters in the PyRedisCLI
class:
- savefile_path: Path to the JSON file for saving/loading data (default is
pyredis_dump.json
). - expiration_time: Default TTL for keys in seconds (default is 1 year).
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please open an issue or submit a pull request to improve the project.
This project is inspired by Redis and is meant for educational purposes to understand key-value storage mechanisms.