GDare-DB is a project that provides an in-memory database utilizing Redis-inspired hashtables implemented in Go here. It offers a lightweight and efficient solution for storing data in memory and accessing it through simple HTTP operations.
The primary goal of this project is to offer an in-memory database that leverages hashtables for efficient data storage and retrieval. The Go implementation allows using this database as a component in other Go services or integrating it into applications that require rapid access to in-memory data.
To run the database as a Docker image, ensure you have Docker installed on your system. First, navigate to the root directory of your project and execute the following command to build the Docker image:
docker build -t dare-db .
Once the image is built, you can run the database as a Docker container with the following command:
docker run -d -p 2605:2605 dare-db
This command will start the database as a Docker container in detached mode, exposing port 2605 of the container to port 2605 on your localhost.
The in-memory database provides three simple HTTP endpoints to interact with stored data:
This endpoint retrieves an item from the hashtable using a specific key.
Example usage with cURL:
curl -X GET http://localhost:2605/get/myKey
This endpoint inserts a new item into the hashtable. The request body should contain the key and value of the new item.
Example usage with cURL:
curl -X POST -d '{"myKey":"myValue"}' http://localhost:2605/set
This endpoint deletes an item from the hashtable using a specific key.
Example usage with cURL:
curl -X DELETE http://localhost:2605/delete/myKey
Below is a simple example of how to use this database in a Go application:
package main
import (
"fmt"
"net/http"
"bytes"
)
func main() {
// Example of inserting a new item
_, err := http.Post("http://localhost:2605/set", "application/json", bytes.NewBuffer([]byte(`{"myKey":"myValue"}`)))
if err != nil {
fmt.Println("Error while inserting item:", err)
return
}
// Example of retrieving an item
resp, err := http.Get("http://localhost:2605/get/myKey")
if err != nil {
fmt.Println("Error while retrieving item:", err)
return
}
defer resp.Body.Close()
// Example of deleting an item
req, err := http.NewRequest("DELETE", "http://localhost:2605/delete/myKey", nil)
if err != nil {
fmt.Println("Error while deleting item:", err)
return
}
_, err = http.DefaultClient.Do(req)
if err != nil {
fmt.Println("Error while deleting item:", err)
return
}
}