Skip to content

GoCache is a high-speed key-value database leveraging AVL trees for efficient data retrieval and storage operations with Log(N) time complexity

License

Notifications You must be signed in to change notification settings

Jarviss77/GoCache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GoCache

GoCache is a simple in-memory key-value store written in Go. It is thread-safe and supports expiration of keys. It uses AVL tree to store the keys and values. It can handle multiple requests concurrently from multiple clients and is optimized for fast read access.

Features

  • Multiple clients support
  • Thread-safe
  • AVL tree for key-value storage
  • Fast read access (O(log n) using AVL tree)
  • Concurrent requests handling
  • RESP protocol support (https://redis.io/topics/protocol)
  • In-memory storage
  • Supports expiration of keys

Installation

git clone https://github.com/Jarviss77/GoCache.git

Supported Commands

PING

Returns PONG if the server is running.

ECHO message

Returns the message.

SET key value

Set the key -> value. First the key is hashed and then stored in the AVL tree.

GET key

Get the value of the key. Searches the AVL tree for the key and returns the value.

Usage

Run the server using the following command:

go run server.go commands.go database.go hasher.go parser.go

The server will start running on port 6379. You can connect to the server using telnet to test the working of the server.

telnet localhost 6379

Testing Commands

Go to the client directory and open the client.go file and check the lines of code. You can add the commands you want to test in the client.go file. Then run the client.go file using the following command:

    _, err = conn.Write([]byte("*2\r\n$4\r\nECHO\r\n$4\r\nHello\r\n"))   <-- This

This is a RESP encoded command to test the ECHO command. You can read about the RESP protocol here

What this line outputs in the client side:

Hello

To run the client.go file, use the following command:

cd client
go run client.go

For example, to test the ECHO command, you can use the following command:

    _, err = conn.Write([]byte("*2\r\n$4\r\nECHO\r\n$4\r\nHello\r\n"))

To test the PING command, you can use the following command:

    _, err = conn.Write([]byte("*1\r\n$4\r\nPING\r\n"))

To test the SET command, you can use the following command:

    _, err = conn.Write([]byte("*3\r\n$3\r\nSET\r\n$3\r\nkey\r\n$5\r\nvalue\r\n"))

To test the GET command, you can use the following command:

    _, err = conn.Write([]byte("*2\r\n$3\r\nGET\r\n$3\r\nkey\r\n"))

About

GoCache is a high-speed key-value database leveraging AVL trees for efficient data retrieval and storage operations with Log(N) time complexity

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages