Coder Social home page Coder Social logo

minidb's Introduction

minidb

rosedb 的 mini 版本,帮助理解 bitcask 存储模型以及 rosedb 项目。

需要说明的是,minidb 没有实现 bitcask 模型的多个数据文件的机制,为了简单,我只使用了一个数据文件进行读写。但这并不妨碍你理解 bitcask 模型。

我写了一篇文章对 minidb 进行讲解:从零实现一个 k-v 存储引擎,相信结合文章及 minidb 的简单的代码,你能够快速上手了。

reference

bitcask 模型的论文

https://riak.com/assets/bitcask-intro.pdf

rosedb 项目

rosedb

Usage

package main

import (
	"fmt"

	"github.com/roseduan/minidb"
)

func main() {
	db, err := minidb.Open("/tmp/minidb")
	if err != nil {
		panic(err)
	}

	var (
		key   = []byte("dbname")
		value = []byte("minidb")
	)

	err = db.Put(key, value)
	if err != nil {
		panic(err)
	}
	fmt.Printf("1. put kv successfully, key: %s, value: %s.\n", string(key), string(value))

	cur, err := db.Get(key)
	if err != nil {
		panic(err)
	}
	fmt.Printf("2. get value of key %s, the value of key %s is %s.\n", string(key), string(key), string(cur))

	err = db.Del(key)
	if err != nil {
		panic(err)
	}
	fmt.Printf("3. delete key %s.\n", string(key))

	db.Merge()
	fmt.Println("4. compact data to new dbfile.")

	db.Close()
	fmt.Println("5. close minidb.")
}

minidb's People

Contributors

roseduan avatar spike014 avatar rfyiamcool avatar biningo avatar wujianfeng01 avatar zll600 avatar her-cat avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.