百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
F

flashdb

> 数据库
开源

FlashDB 是一个可嵌入式的内存式键值数据库,使用 Go 语言(具有类似 Redis 的命令,而且非常易于阅读)

377 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

FlashDB 是一个可嵌入式的内存式键值数据库,使用 Go 语言(具有类似 Redis 的命令,而且非常易于阅读)

flashdb

FlashDB is a simple, in-memory, key/value store in pure Go. It persists to disk, is ACID compliant, and uses locking for multiple readers and a single writer. It supports redis like operations for data structures like SET, SORTED SET, HASH and STRING.

Features

  • In-memory database for fast reads and writes
  • Embeddable with a simple API
  • Supports Redis like operations for SET, SORTED SET, HASH and STRING
  • Durable append-only file format for persistence
  • Option to evict old items with an expiration TTL
  • ACID semantics with locking transactions that support rollbacks

Architecture

FlashDB is made of composable libraries that can be used independently and are easy to understand. The idea is to bridge the learning for anyone new on how to build a simple ACID database.

  • Set
  • ZSet
  • String
  • Hash
  • Append Only Log

Getting Started

Installing

To start using FlashDB, install Go and run go get:

bash
$ go get -u github.com/arriqaaq/flashdb

This will retrieve the library.

Opening a database

The primary object in FlashDB is a DB. To open or create your database, use the flashdb.New() function:

go
package main

import (
	"log"

	"github.com/arriqaaq/flashdb"
)

func main() {
	config := &flashdb.Config{Path:"/tmp", EvictionInterval: 10}
	db, err := flashdb.New(config)
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()

	...
}

It's also possible to open a database that does not persist to disk by keeping the path in the config empty.

go
config := &flashdb.Config{Path:"", EvictionInterval: 10}
flashdb.New(config)

Transactions

All reads and writes must be performed from inside a transaction. FlashDB can have one write transaction opened at a time, but can have many concurrent read transactions. Each transaction maintains a stable view of the database. In other words, once a transaction has begun, the data for that transaction cannot be changed by other transactions.

When a transaction fails, it will roll back, and revert all changes that occurred to the database during that transaction. When a read/write transaction succeeds all changes are persisted to disk.

Read-only Transactions

A read-only transaction should be used when you don't need to make changes to the data. The advantage of a read-only transaction is that there can be many running concurrently.

go
err := db.View(func(tx *flashdb.Tx) error {
	...
	return nil
})

Read/write Transactions

A read/write transaction is used when you need to make changes to your data. There can only be one read/write transaction running at a time. So make sure you close it as soon as you are done with it.

go
err := db.Update(func(tx *flashdb.Tx) error {
	...
	return nil
})

Setting and getting key/values

To set a value you must open a read/write transaction:

go
err := db.Update(func(tx *flashdb.Tx) error {
	err := tx.Set("mykey", "myvalue")
	return err
})

To get the value:

go
err := db.View(func(tx *flashdb.Tx) error {
	val, err := tx.Get("mykey")
	if err != nil{
		return err
	}
	fmt.Printf("value is %s\n", val)
	return nil
})

Commands

String Hash Set ZSet
SET HSET SADD ZADD
GET HGET SISMEMBER ZSCORE
DELETE HGETALL SRANDMEMBER ZCARD
EXPIRE HDEL SREM ZRANK
TTL HEXISTS SMOVE ZREVRANK
HLEN SCARD ZRANGE
HKEYS SMEMBERS ZREVRANGE
HVALS SUNION ZREM
HCLEAR SDIFF ZGETBYRANK
SCLEAR ZREVGETBYRANK
ZSCORERANGE
ZREVSCORERANGE
ZCLEAR

Benchmarks

  • Go Version : go1.11.4 darwin/amd64
  • OS: Mac OS X 10.13.6
  • Architecture: x86_64
  • 16 GB 2133 MHz LPDDR3
  • CPU: 3.1 GHz Intel Core i7
…

With fsync enabled for every update transaction

…

The benchmark code can be found here flashdb-bench.

TODO

FlashDB is in early stages of development. A couple of to-do tasks listed:

  • Add more comprehensive unit test cases
  • Add explicit documentation on various usecases

References

FlashDB is inspired by NutsDB and BuntDB.

Contact

Farhan Khan @arriqaaq

License

FlashDB source code is available under the MIT License

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Godatabaseembeddedflashdbgo

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类数据库
定价开源

> 相关工具

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库