Gedis

A fast, Redis inspired, in-memory database written in

Windows build? Idc. Use WSL or something ¯\_(ツ)_/¯

Ok cool, but how to use this?

GET

Gets a value from memory.

SET

Sets a value with the given key in memory & writes to cache.

DELETE

Deletes a value from memory & removes it from cache.

create_backup

Create a backup in the `/backups` folder asynchronously & export it as either JSON or CSV.

By default, it exports it as JSON. But you can export it as CSV by adding the --csv flag.

A backups directory is created if it doesn't exist where all the backup files will be stored. Make sure you don't modify the names of the files, otherwise the Database won't be able to load backups.

load_backup

Gets/Parses a backup file and replaces the current data in the memory + cache with the backup data.

2023/06/07 13:41:41 Starting Gedis server
2023/06/07 13:41:41 Gedis server listening on port 5000
Enter .exit to stop the server.
gedis> GET hello
<nil>
.
.
.
gedis> SET hello world
gedis> GET hello
world
.
.
.
gedis> DELETE hello
gedis> GET hello
<nil>
.
.
.
gedis> create_backup
Backup created successfully
.
.
gedis> create_backup --csv
Backup created successfully
gedis> ^Z
[1] + 24587 suspended ./gedis
.
$ ls
.cache
backups
gedis

$ ls backups
backup-070623-14:46:35.json
backup-070623-14:46:41.csv

$ fg
[1] + 24587 continued ./gedis
.
gedis> SET hello world
.
gedis> load_backup backup-070623-14:46:35.json
Backup loaded into memory
gedis> GET hello
<nil>

But what about accessing data from apps?

Just use your language's native network request method!

TypeScript

const response = await fetch("http://localhost:3000?key=hello");
const data = await response.text();

console.log(data); // world | <nil>

Rust

use reqwest;

#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
  let url = "http://localhost:3000?key=hello";
  let response = reqwest::get(url).await?;
  let data = response.text().await?;
  println!("{}", data); // world | <nil>
  Ok(())
}

Go

package main

import (
	"fmt"
	"io/ioutil"
	"net/http"
)

func main() {
	url := "http://localhost:3000?key=hello"
	response, err := http.Get(url)

  if err != nil {
		fmt.Println(err)
		return
	}

  defer response.Body.Close()
	data, err := ioutil.ReadAll(response.Body)

  if err != nil {
		fmt.Println(err)
		return
	}

  fmt.Println(string(data)) // world | <nil>
}
Dart
import 'dart:convert';
import 'package:http/http.dart' as http;

void main() async {
  final http.Response response = await http.get(Uri.parse('http://localhost:3000?key=hello'));
  final data = utf8.decode(response.bodyBytes);
  print(data); // world | <nil>
}
#include <iostream>
#include <curl/curl.h>
#include <string>

int main() {
  CURL* curl;
  CURLcode res;
  std::string url = "http://localhost:3000?key=hello";
  curl_global_init(CURL_GLOBAL_DEFAULT);
  curl = curl_easy_init();

  if (curl) {
    curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
    res = curl_easy_perform(curl);

    if (res == CURLE_OK) {
      std::cout << curl_easy_strerror(res) << std::endl; // world | <nil>
    }

    curl_easy_cleanup(curl);
  }
  curl_global_cleanup();
  return 0;
}

Python

import requests

url = "http://localhost:3000?key=hello"
response = requests.get(url)
data = response.text
print(data) # world | <nil>

Ruby

require 'net/http'

url = URI.parse("http://localhost:3000?key=hello")
response = Net::HTTP.get_response(url)
data = response.body
puts data # world | <nil>

Swift

import Foundation

func fetchData() {
  let url = URL(string: "http://localhost:3000?key=hello")!
  let task = URLSession.shared.dataTask(with: url) { (data, response, error) in
    if let error = error {
      print("Error: \(error)")
      return
    }

    if let data = data, let dataString = String(data: data, encoding: .utf8) {
      print(dataString) // world | <nil>
    }
  }

  task.resume()
}

fetchData()