https://github.com/dev-siri/gedis
A fast Redis inspired in-memory database made with Go.
https://github.com/dev-siri/gedis
database fast-database golang in-memory-database redis-like
Last synced: about 2 months ago
JSON representation
A fast Redis inspired in-memory database made with Go.
- Host: GitHub
- URL: https://github.com/dev-siri/gedis
- Owner: Dev-Siri
- License: mit
- Created: 2023-06-06T11:46:00.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-11-02T19:32:53.000Z (over 1 year ago)
- Last Synced: 2025-02-02T09:19:00.098Z (over 1 year ago)
- Topics: database, fast-database, golang, in-memory-database, redis-like
- Language: Go
- Homepage: https://gedis.vercel.app
- Size: 285 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Gedis
Gedis is an in-memory Redis inspired database written in Go.
## Why?
Just wanted to challenge myself to create a Database. + I just wanted to build a Go project since I am very much foreign with the language (not having used it in anything other than backend development)
## How does this work?
Its simple, a `map[string]string` stored in memory, while writing to cache for persistence.
Backups are also supported. Creating a backup will take the map from meory & spit out a `backup-[TIMESTAMP].(json|csv)` file with the map encoded as JSON or CSV. When loading a backup, the type of the file is inferred based on the file extension. If the name of a backup file is changed to include other stuff like extra ".", it will fail. After the type is inferred of either JSON or CSV, it decodes it & then places it in memory + cache.
It also starts a server by default on port 5000 (If PORT env variable is not set, the default is 5000). This API allows for `GET`, `SET` & `DELETE` so it can be accessed by an application using a network request.
## Commands
The database is very simple with 5 commands.
NOTE: The commands are case-insensitive, so doesn't matter if you are a SQL guy or not.
### Open commands
These commands can be accessed from both the CLI and the Rest API.
### `GET`
Gets a value with the given key from memory.
#### Syntax
```sh
GET
# example, if the key is "foo"
GET foo
```
### `SET`
Sets a value with a given key. Also written to cache for persistence.
#### Syntax
```sh
SET
# example with the key="foo" & value="bar"
SET foo bar
```
### `DELETE`
Deletes a value with the given key.
#### Syntax
```sh
DELETE
# example, delete the value with key "foo"
DELETE foo
```
### CLI-only commands
### `create_backup`
Creates a `backup-[TIMESTAMP].(json|csv)` in the `backups` folder.
Supported Backup export type
- JSON
- CSV
```sh
# by default, it exports as JSON
create_backup
# export as CSV
create_backup --csv
# any flag not-meaningful to the database is ignored (exported as JSON)
create_backup --never-gonna-give-you-up
```
### `load_backup`
Loads a backup file.
It looks for backups in the `backups/` folder so anything else is ignored.
#### Syntax
```sh
load_backup
# json
load_backup backup-060623-17:12:51.json
# csv
load_backup backup-060623-17:12:51.csv
```
## Using the Rest API
The database's server only has one endpoint, the root (/)
Here you can send `GET`, `POST` (`SET`) & `DELETE` Requests to perform actions on the database. Make sure to also pass `?key=...` & `&value=...` based on the type of action.
## Getting Started
- Clone the repo
```sh
$ git clone https://github.com/Dev-Siri/gedis.git
```
- Compile the project. Make sure you have [Go](https://go.dev) installed on your system. Then run the build.sh file.
```sh
$ ./build.sh
```
- Then run the binary according to your CPU architecture & OS.
```sh
$ ./bin/gedis-[VERSION]-[OS]-[ARCH]/gedis
```
This will start a server on your machine w/ PORT env (default 5000) + a CLI that will allow you to interact with the database.
## Running with Docker
- Pull the image from GitHub's Container Registry.
```sh
$ docker pull ghcr.io/dev-siri/gedis:latest
```
- Then pass a PORT & run the container with the "-it" flag
```sh
$ docker run -p :8080 -it ghcr.io/dev-siri/gedis:latest
```
## License
This project is MIT licensed, see [LICENSE.md](LICENSE.md).