Skip to content

technojo2000/RemoteDict

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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: A Minimal Redis-like In-Memory Dictionary Server

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).

Features

  • 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)

Installation

  1. Clone this repository or copy the relevant files from src/remotedict/ into your project.

  2. Install the required client library:

    pip install redis

Usage Examples

Basic In-Memory Server (RemoteDict)

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()

Expiring Keys (ExpiringRemoteDict)

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()

Persistent Storage (PersistentRemoteDict)

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()

Testing

You can run the test suites for all variants using unittest or by running the provided test runner script.

Run all tests (recommended)

python -m tests.run_tests

Run individual test suites

python -m unittest tests/test_remotedict_server.py
python -m unittest tests/test_expiring_remotedict_server.py
python -m unittest tests/test_persistent_remotedict_server.py

All tests should pass if the server and its variants are working correctly.

Supported Commands

  • SET key value — Set the value for a key
  • GET key — Get the value for a key
  • DEL key [key ...] — Delete one or more keys
  • EXISTS key [key ...] — Check if one or more keys exist
  • KEYS pattern — List keys matching a pattern (supports Unix shell-style wildcards)
  • FLUSHDB — Remove all keys from the current database
  • FLUSHALL — Remove all keys from all databases (if supported)

Notes

  • Expiry in ExpiringRemoteDict is global: all keys expire after the configured expiry_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.

About

RemoteDict is a lightweight, in-memory key-value store server implemented in Python.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages