Skip to content

Repository files navigation

Simple Redis

This project is a simplified Redis clone implemented in Go, created as part of the CodeCrafters "Build Your Own Redis" challenge. It supports a subset of Redis commands and provides basic functionality for key-value storage and retrieval along with several redis features as described below.

Supported Features

  • Basic key/value storage using GET and SET command with values with expiry time.
  • RDB local database support for persistent storage.
  • AOF (Append-Only File) support for enhanced durability with default sync frequency.
  • Full Replication support with command propagation, acknowledgement tracking, and replica management.
  • List support with RPUSH, LPUSH, LRANGE, LLEN, LPOP and BLPOP commands.
  • Sorted sets support with ZADD, ZRANK, ZRANGE, ZCARD, ZSCORE and ZREM commands.
  • Streams support with TYPE, XADD, XRANGE, and XREAD commands.
  • Transaction support with MULTI, INCR, EXEC, DISCARD, WATCH and UNWATCH commands.
  • Pub/Sub support with SUBSCRIBE, UNSUBSCRIBE and PUBLISH commands.
  • Basic ACL support with AUTH, ACL WHOAMI, ACL GETUSER and ACL SETUSER commands. -Geo support with GEOADD, GEOPOS, GEODIST and GEOSEARCH commands.

Prerequisites

This project requires Go to be installed on your system. If you don't have Go installed, you can download it from the official Go downloads page:

https://go.dev/dl/

Choose the appropriate version for your operating system and follow the installation instructions provided on the Go website.

Installation

After ensuring Go is installed on your system, follow these steps to set up Simple Git:

  1. Clone the repository:

    git clone https://github.com/kakkarot9712/simple_redis_go
    
  2. Navigate to the project directory:

    cd simple-redis-go
    
  3. Build the project:

    go build -o myredis ./app
    

This will create an executable named myredis in your project directory.

Usage

  • After building the project, you can use the myredis executable to start server.
./myredis 
  • By default this server will bind to port 6379, Though you can use any port using --port flag while starting server
./myredis --port 6380
  • You can load existing RDB file while staring the server using --dir flag to specify file location and --dbfilename flag to specify RDB file name.
./myredis --dir /tmp/redis-files --dbfilename dump.rdb

Note: If you dont specify directory and file paths, server will try to fetch dump.rdb file from /tmp/redis-files directory.

  • You can enable AOF (Append-Only File) persistence using the --appendonly flag (set to yes to enable). Configure AOF options using:
    • --appendonly yes|no: Enable/disable AOF persistence
    • --appendfilename: AOF file name (default: appendonly.aof)
    • --appenddirname: Directory for AOF file (default: appendonlydir)
    • --appendfsync: AOF sync frequency - everysec, always, or no (default: everysec)
./myredis --appendonly yes --appendfsync everysec
  • By default Server will assume a master role. To start server as replica server of some other master server you can pass --replicaof flag along with host and port of master server.
./myredis --replicaof "localhost 6379"

Supported Commands

The following Redis commands are implemented in this project:

  1. PING: Test the server connection
  2. ECHO: Echo the given string
  3. SET: Set a key to hold a string value
  4. GET: Retrieve the value of a key
  5. CONFIG: Get or set server configuration parameters
  6. KEYS *: Find all keys
  7. INFO: Get information and statistics about the server
  8. REPLCONF: Configure replication settings (supports LISTENING-PORT, CAPA, GETACK, and ACK)
  9. PSYNC: Internal command used for full resynchronization in replication
  10. WAIT: Wait for replica acknowledgements
  11. TYPE: Get type of a key (string, stream, list, or none)
  12. INCR: Increments integer value of specified key by 1
  13. MULTI: Starts a transaction — subsequent commands are queued without execution
  14. EXEC: Executes all queued commands and returns results as an array
  15. DISCARD: Discards a previously initialized transaction (with MULTI)
  16. XADD: Append an entry to a stream
  17. XRANGE: Retrieve a range of entries from a stream
  18. XREAD: Read from one or more streams with optional blocking
  19. RPUSH: Append one or more values to a list
  20. LPUSH: Prepend one or more values to a list
  21. LRANGE: Get a range of elements from a list
  22. LLEN: Get the length of a list
  23. LPOP: Remove and return element(s) from the head of a list
  24. BLPOP: Blocking pop from the head of a list
  25. SUBSCRIBE: Subscribe to one or more channels
  26. UNSUBSCRIBE: Unsubscribe from one or more channels
  27. PUBLISH: Publish a message to a channel
  28. AUTH: Authenticate with a username and password
  29. ACL WHOAMI: Return the username of the current connection
  30. ACL GETUSER: Get flags and passwords for a user
  31. ACL SETUSER: Create or modify a user (supports >password rule to set password)
  32. COMMAND: Get information about Redis commands
  33. ZADD: Add one or more members to a sorted set
  34. ZRANK: Get the rank of a member in a sorted set
  35. ZRANGE: Get a range of members from a sorted set
  36. ZCARD: Get the cardinality (number of members) of a sorted set
  37. ZSCORE: Get the score of a member in a sorted set
  38. ZREM: Remove one or more members from a sorted set
  39. WATCH: Watch one or more keys for transaction
  40. UNWATCH: Unwatch all keys
  41. GEOADD: Add one or more locations to a geo key
  42. GEOPOS: Get the positions of one or more locations
  43. GEODIST: Get the distance between two locations
  44. GEOSEARCH: Search for locations within a radius

Limitations

  • HGET and HSET commands are not supported.
  • PSUBSCRIBE and PUNSUBSCRIBE (pattern-based pub/sub) are not supported.
  • RDB file loading is supported but SAVE command (writing RDB) is not.
  • Only RDB with single database and basic key-value storage is supported.
  • ACL support is limited to password-based authentication; command/key permissions are not enforced.
  • AOF persistence only supports the default sync frequency (everysec); other modes (always and no) are not yet implemented.
  • Replica restrictions: Connected replicas can only execute REPLCONF command; other commands are restricted to prevent accidental modifications.

Acknowledgments

  • CodeCrafters for providing the "Build Your Own Redis" challenge
  • The Redis project for inspiration and documentation
  • HDT3213 for CRC64 Checksum Jones varient implimentation.

About

This project is a simplified Redis clone implemented in Go, created as part of the CodeCrafters "Build Your Own Redis" challenge.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Used by

Contributors

Languages