A simple in-memory data store in Go with REST API and client library.
- String and list operations
- TTL support
- Data persistence to disk
- REST API
- Go client library
- Docker support
# Using Docker
docker-compose up -d
# Or run locally
go run main.goServer runs on http://localhost:8080.
# Set a string
curl -X POST http://localhost:8080/strings \
-H "Content-Type: application/json" \
-d '{"key":"user","value":"john"}'
# Get a string
curl http://localhost:8080/strings/user
# Create a list
curl -X POST http://localhost:8080/lists \
-H "Content-Type: application/json" \
-d '{"key":"items","value":["apple","banana"]}'
# Add to list
curl -X POST http://localhost:8080/lists/items/push \
-H "Content-Type: application/json" \
-d '{"value":"orange"}'
# Remove from list
curl -X POST http://localhost:8080/lists/items/pop
# Delete key
curl -X DELETE http://localhost:8080/keys/userpackage main
import (
"fmt"
"log"
"in-memory/client"
)
func main() {
c := client.New()
// String operations
err := c.Set("user", "john")
if err != nil {
log.Fatal(err)
}
value, err := c.Get("user")
if err != nil {
log.Fatal(err)
}
fmt.Printf("User: %s\n", value)
// List operations
err = c.SetList("items", []string{"apple", "banana"})
if err != nil {
log.Fatal(err)
}
err = c.Push("items", "orange")
if err != nil {
log.Fatal(err)
}
items, err := c.GetList("items")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Items: %v\n", items)
}in-memory/
├── api/ # HTTP handlers and models
├── client/ # Go client library
├── store/ # Core in-memory store
├── docs/ # Documentation
├── main.go # Server entry point
└── docker-compose.yml # Docker configuration
Configure with environment variables:
# Set port
PORT=9000 go run main.go
# Set persistence file location
PERSIST_FILE=my_data.json go run main.go
# Both settings
PORT=9000 PERSIST_FILE=my_data.json go run main.goData is automatically saved to data.json when the server shuts down gracefully (Ctrl+C). On startup, any existing data is loaded from the file.
Features:
- Graceful shutdown saves data
- Expired entries are cleaned up during save/load
- Configurable data file location
go test ./...- Single instance
- No clustering
- No authentication
- File-based persistence only (not database)