A stable, high-performance, fast, embedded K-V database supports a variety of data structures, including String, List, Hash, Set, Sorted Set, interface name style similar to Redis.

Open source licenses

Use the MIT Open Source license

The link address

[ros] get git address

introduce

An instance of RoseDB is essentially a folder on the system where, apart from some configuration, the main thing is the data files. In an instance, only one active data file exists for write operations, and if the file size reaches the upper limit, the file is closed and a new active file is created.

The rest of the files, which I call archived files, are closed and cannot be written to, but can be read.

So the entire database instance is a collection of currently active files, archived files, and other configurations:

In each file, writes to data are appended only to the end of the file, which ensures that writes do not require additional disk addressing. The written data is organized into Entry structures. The main data structures of Entry are as follows:

So a data file can be thought of as a collection of multiple entries:

When writing data, IF it is String, I store the key in the hop table to support String prefix scan and range scan. If it is other types of data, I store it directly in the corresponding data structure. Then, information such as keys and values is encapsulated as Entry and stored in data files for persistence.

If it is an delete operation, it is encapsulated into an Entry, marked as an delete operation, and persisted in a data file. In this case, there may be a large amount of redundant data in the data file, resulting in unnecessary disk space waste. To solve this problem, I wrote a Reclaim method, which you can think of as reorganizing the data files to make them more compact.

The execution process of Reclaim method is also relatively simple. First, a temporary folder is established to store temporary data files. Then, all archived files in the entire database instance are iterated, each Entry in the data file is iterated in turn, and the valid Entry is written to the new temporary data file. Finally, the temporary file is copied to the new data file, and the original data file is deleted.

This makes the data file more compact and removes unnecessary entries to avoid taking up extra disk space.

features

  • Support rich data structures: strings, lists, hash tables, sets, ordered sets.
  • Embedding is extremely simple and does not require any installation or deployment.
  • Low latency, high throughput (see Benchmark of project English README for details).
  • Operations of different data types can be completely parallel.
  • Supports client command line operations.
  • Support for expiration time.
  • StringData types support prefix and range scanning.

Begin to use

Command line operation

Switch the directory to rosedb/ CMD /server

Run main.go in the server directory

Open a new window and switch to rosedb/ CMD /cli

Run main.go in the directory

Embedded use

Import my project from the project:

import "github.com/roseduan/rosedb"
Copy the code

Then open the database and perform the corresponding operation:

package main

import (
  "github.com/roseduan/rosedb"
  "log"
)

func main(a) {
  config := rosedb.DefaultConfig()
  db, err := rosedb.Open(config)
  
  iferr ! =nil {
    log.Fatal(err)
  }
  
  // Don't forget to close the database.
  defer db.Close()
  
  / /...
}
Copy the code

Data structure: Supports five data structures: String, List, Hash, Set, and ZSet.

At the end

This issue is to share here, I am xiaobian South wind blowing, focus on sharing interesting, novel, practical open source projects and developer tools, learning resources! I hope to learn and communicate with you together. Welcome to follow my official account ** [Github navigation station] **.