Disclaimer: The majority of the code in this project was generated by AI (GitHub Copilot and similar tools). Please review and test thoroughly before using in production.
RemoteDict is a lightweight, in-memory key-value store server implemented in Python. It mimics a subset of the Redis protocol and can be accessed using any Redis client library (such as redis-py).
- RESP protocol support for basic commands:
SET,GET,DEL,EXISTS,KEYS - In-memory storage (no persistence) via
RemoteDict - Expiring keys (with TTL) via
ExpiringRemoteDict - Persistent storage (disk-backed) via
PersistentRemoteDict - Asyncio-based server with optional threaded start/stop
- Compatible with Redis clients (e.g.,
redis-py)
-
Clone this repository or copy the relevant files from
src/remotedict/into your project. -
Install the required client library:
pip install redis
import time
import redis
from remotedict import RemoteDict
# Start the server in a background thread
server = RemoteDict(address="127.0.0.1", port=8085)
server.start_thread()
time.sleep(0.5) # Give the server a moment to start
# Connect as a client using redis-py
r = redis.Redis(host="127.0.0.1", port=8085, decode_responses=True)
# SET key value
r.set("foo", "bar")
# GET key
print(r.get("foo")) # Output: bar
server.stop_thread()from remotedict import ExpiringRemoteDict
# All keys will expire after 5 seconds (default expiry for all keys)
server = ExpiringRemoteDict(address="127.0.0.1", port=8086, expiry_seconds=5)
server.start_thread()
# ...
# All keys set will automatically expire after 5 seconds
# ...
server.stop_thread()from remotedict import PersistentRemoteDict
server = PersistentRemoteDict(address="127.0.0.1", port=8087, db_path="./mydb.json")
server.start_thread()
# ...
# Data will be saved to disk and reloaded on restart
# ...
server.stop_thread()You can run the test suites for all variants using unittest or by running the provided test runner script.
python -m tests.run_testspython -m unittest tests/test_remotedict_server.py
python -m unittest tests/test_expiring_remotedict_server.py
python -m unittest tests/test_persistent_remotedict_server.pyAll tests should pass if the server and its variants are working correctly.
SET key value— Set the value for a keyGET key— Get the value for a keyDEL key [key ...]— Delete one or more keysEXISTS key [key ...]— Check if one or more keys existKEYS pattern— List keys matching a pattern (supports Unix shell-style wildcards)FLUSHDB— Remove all keys from the current databaseFLUSHALL— Remove all keys from all databases (if supported)
- Expiry in
ExpiringRemoteDictis global: all keys expire after the configuredexpiry_seconds(default: 3600 seconds). There is no per-key expiry or TTL/EXPIRE command support. - This server is for educational/testing purposes and is not suitable for production use.
- Data is stored in memory and will be lost when the server stops, except when using
PersistentRemoteDict. - Expiry and persistence features are only available in their respective variants.