|
| 1 | +# KV Store |
| 2 | + |
| 3 | +A lightweight, high-performance key-value store with HTTP API. Built with ReactPHP and SQLite. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +This project provides a simple, performant and resource-efficient key-value store that can be easily deployed alongside microservices and Docker containers. It offers a straightforward HTTP API for storing and retrieving data with minimal overhead. |
| 8 | + |
| 9 | +## Features |
| 10 | + |
| 11 | +* RESTful HTTP API |
| 12 | +* Persistent storage via SQLite |
| 13 | +* Low resource usage (typical memory usage ~35MB, negligible CPU usage) |
| 14 | +* Simple GET/PUT/DELETE operations |
| 15 | + |
| 16 | +## Getting Started |
| 17 | + |
| 18 | +### Running with Docker |
| 19 | + |
| 20 | +Run the container with default settings: |
| 21 | + |
| 22 | +``` |
| 23 | +docker run -p 8080:8080 ghcr.io/binaryfire/kv:latest |
| 24 | +``` |
| 25 | + |
| 26 | +For data persistence, map the database directory to a volume: |
| 27 | + |
| 28 | +``` |
| 29 | +docker run -p 8080:8080 -v kv-database:/var/www/database ghcr.io/binaryfire/kv:latest |
| 30 | +``` |
| 31 | + |
| 32 | +## API Routes |
| 33 | + |
| 34 | +| Method | Route | Description | |
| 35 | +| --- | --- | --- | |
| 36 | +| GET | / | List all keys | |
| 37 | +| GET | /{key} | Get value for key | |
| 38 | +| PUT | /{key} | Set value for key | |
| 39 | +| DELETE | /{key} | Delete key | |
| 40 | + |
| 41 | +## Usage Examples |
| 42 | + |
| 43 | +List all keys: |
| 44 | + |
| 45 | +``` |
| 46 | +curl http://localhost:8080/ |
| 47 | +``` |
| 48 | + |
| 49 | +Get a specific value: |
| 50 | + |
| 51 | +``` |
| 52 | +curl http://localhost:8080/my_key |
| 53 | +``` |
| 54 | + |
| 55 | +Set a value (or overwrite existing value): |
| 56 | + |
| 57 | +``` |
| 58 | +curl -X PUT -d "my value" http://localhost:8080/my_key |
| 59 | +``` |
| 60 | + |
| 61 | +Delete a key: |
| 62 | + |
| 63 | +``` |
| 64 | +curl -X DELETE http://localhost:8080/my_key |
| 65 | +``` |
| 66 | + |
| 67 | +## Key Format Requirements |
| 68 | + |
| 69 | +All keys must be in lowercase \`snake\_case\` format: |
| 70 | + |
| 71 | +* Must contain only lowercase letters and numbers |
| 72 | +* Words separated by underscores |
| 73 | +* Example: `user_settings`, `api_key_1` |
| 74 | + |
| 75 | +## Building from Source |
| 76 | + |
| 77 | +``` |
| 78 | +./build.sh |
| 79 | +``` |
| 80 | + |
| 81 | +This will create Docker images tagged with the current timestamp and 'latest'. |
0 commit comments