This project implements a distributed cache system using Go. It is designed to handle caching efficiently across multiple nodes, providing capabilities for storing, retrieving, and managing key-value pairs. The system includes features like TTL (time-to-live) for cache entries, distributed node communication, and administrative functionality for managing cluster operations.
- Distributed Architecture: The cache system can be deployed across multiple nodes.
- TTL Support: Cached entries expire after a configurable time-to-live duration.
- Cluster Management: Administrative functionality for managing nodes and subscribers.
- Key Operations: Supports
SET
,GET
,DELETE
, andHAS
operations. - Scalable Design: Nodes can join or leave the cluster dynamically.
- Client Support: A client library is provided for interacting with the cache system programmatically.
- Go 1.18+ installed on your system.
Clone the repository:
git clone https://github.com/ayushgupta4002/bitboat.git
cd bitboat
Start a Admin server node:
go run main.go --listenaddr localhost:8080
Start a Subscriber node that connects to Admin:
go run main.go --listenaddr localhost:8081 --adminaddr localhost:8080
The client library allows applications to interact with the cache system. Clients can interact with any Node ( Subscriber or Admin ), Example usage:
package main
import (
"context"
"log"
"github.com/ayushgupta4002/bitboat/client"
)
func main() {
client, err := client.NewClient("localhost:8080", client.ClientOpts{}) // [ here specify address of subscriber or admin node as per client need]
if err != nil {
log.Fatal("Error connecting to cache:", err)
}
// Set a key
err = client.Set(context.Background(), []byte("key1"), []byte("value1"), 3000000000)
if err != nil {
log.Fatal("Error setting value:", err)
}
// Get a key
value, err := client.Get(context.Background(), []byte("key1"))
if err != nil {
log.Fatal("Error getting value:", err)
}
log.Println("Value:", string(value))
// Delete a key
err = client.Delete(context.Background(), []byte("key1"))
if err != nil {
log.Fatal("Error deleting key:", err)
}
client.Close()
}
The cache system uses a custom binary protocol for communication between nodes and clients. Commands supported:
- SET: Store a key-value pair with a TTL.
- GET: Retrieve the value of a key.
- DELETE: Remove a key from the cache.
- HAS: Check if a key exists in the cache.
- JOIN: Add a Subscriber node to the Admin cluster.
cache
: Implements the in-memory cache.client
: Provides a Go client library for interacting with the cache system.proto
: Defines the custom protocol for communication.main.go
: The entry point for starting server and client nodes.
Contributions are welcome! Please fork the repository and submit a pull request with your changes.
This project is licensed under the MIT License. See the LICENSE
file for details.