Created a simplified version of Redis that supports a subset of its commands,
The simplified server can handle basic SET, GET, DEL, EXPIRE, KEYS, TTL, ZADD and ZRANGE commands.
- SET: Store a key-value pair.
SET <key> <value>
- GET: Fetch the value associated with a given key.
GET key
- DEL: Delete a key-value pair.
DEL key
- EXPIRE: Set expire time for a key-value pair.
EXPIRE key ttl
- KEYS: Fetch all keys matching the regex.
KEYS filter
- TTL: Check the expire time for a key-value pair.
TTL key
- ZADD: Store a key in a sorted set.
ZADD key score value
- ZRANGE: Fetch the score and value of a given key between min and max score.
ZRANGE key minindex maxindex
These instructions will help you get the project up and running on your local machine.
- Go (Golang) should be installed on your machine. If not, you can download it from here.
- Clone the repository to your local machine.
git clone https://github.com/saurabhy27/redis-database.git
- Change to the project directory.
cd redis-database
- Run the server.
go run main.go
- Start the client by running the following command in Mac/Linux system
nc <localhostip> 80
- You can interact with the server by entering Redis-like commands in the client. For example
redis> SET test test123 OK redis> SET care care123 OK redis> GET test test123 redis> KEYS ERR wrong number of arguments for given command redis> KEYS * test care redis> EXPIRE test 10 1 redis> TTL test 7 redis> KEYS * care redis> ZADD saurabh 10 saurabh10 1 redis> ZADD saurabh 12 saurabh12 1 redis> ZRANGE saurabh 0 1 saurabh12 12.000000 saurabh10 10.000000
- Run the test cases
go test ./...
- Run the test cases and check the coverage
go test -coverpkg ./... ./... -v