PyRedis is a lightweight, in-memory key-value store server, written in Python, that partially implements the Redis protocol. Below are the features currently supported by PyRedis.
- Description: Stores a key-value pair in the memory. If the key already exists, its value is overwritten.
- Usage:
SET <key> <value> [PX <milliseconds>]
- Extended Feature: The
SET
command supports an optionalPX
argument that allows setting an expiry time for the key in milliseconds. After the specified duration, the key will automatically be removed from the store.
- Description: Retrieves the value of the specified key. If the key does not exist, a null bulk string is returned.
- Usage:
GET <key>
- Note: If a key has been set with an expiry time using the
PX
argument in theSET
command and the key has expired, a null bulk string ($-1
) is returned.
- Description: Echoes the given string back to the client.
- Usage:
ECHO <message>
- Note: This command is useful for testing and debugging client-server communication.
- Description: Keys can be set with an expiry time in milliseconds using the
PX
argument in theSET
command. Expired keys are automatically removed from the store and are not retrievable with theGET
command. - Usage: Included as part of the
SET
command with thePX
argument.
- Description: Supports basic replication functionality, allowing one PyRedis server to act as a replica of another PyRedis server.
- Usage: --replicaof
- Extended Feature: Replication is supported between PyRedis instances. A server can be started as a replica of another server using the --replicaof option, allowing data synchronization from the master to the replica.
To start the PyRedis server, ensure you have Python installed on your machine, navigate to the project directory in your terminal, and run:
python server.py
The server will start listening for connections on localhost:6379
.
You can connect to the PyRedis server using any Redis client by connecting to localhost
on port 6379
. For example, using redis-cli
:
redis-cli -h localhost -p 6379
PyRedis is a simplified version of Redis and does not support the full set of Redis features or security measures.