NutsDB is a simple, fast, embeddable, persistent key/value store written in pure Golang.
It supports fully serializable transactions, and many data structures such as list、set、sorted set. All operations happen inside a Tx. Tx represents a transaction, which can be read-only or read-write. Read-only transactions can read values for a given bucket and a given key or iterate over a set of key-value pairs. Read-write transactions can read, update and delete keys from the DB.
Getting Started with NutsDB
Installing
To start using NutsDB, first needs Go installed (version 1.11+ is required). and run go get:
go get -u github.com/xujiajun/nutsdb
Opening a database
To open your database, use the nutsdb.Open() function,with the appropriate options.The Dir
, EntryIdxMode
and SegmentSize
options are must be specified by the client. About options see here for detail.
package main import ( "log" "github.com/xujiajun/nutsdb" ) func main() { // Open the database located in the /tmp/nutsdb directory. // It will be created if it doesn't exist. db, err := nutsdb.Open( nutsdb.DefaultOptions, nutsdb.WithDir("/tmp/nutsdb"), ) if err != nil { log.Fatal(err) } defer db.Close() ... }
Options
- Dir string
Dir
represents Open the database located in which dir.
- EntryIdxMode EntryIdxMode
EntryIdxMode
represents using which mode to index the entries. EntryIdxMode
includes three options: HintKeyValAndRAMIdxMode
,HintKeyAndRAMIdxMode
and HintBPTSparseIdxMode
. HintKeyValAndRAMIdxMode
represents ram index (key and value) mode, HintKeyAndRAMIdxMode
represents ram index (only key) mode and HintBPTSparseIdxMode
represents b+ tree sparse index mode.
- RWMode RWMode
RWMode
represents the read and write mode. RWMode
includes two options: FileIO
and MMap
. FileIO represents the read and write mode using standard I/O. And MMap represents the read and write mode using mmap.
- SegmentSize int64
NutsDB will truncate data file if the active file is larger than SegmentSize
. Current version default SegmentSize
is 8MB,but you can custom it. The defaultSegmentSize becomes 256MB when the version is greater than 0.8.0.
Once set, it cannot be changed. see caveats–limitations for detail.
- NodeNum int64
NodeNum
represents the node number.Default NodeNum is 1. NodeNum
range [1,1023] .
- SyncEnable bool
SyncEnable
represents if call Sync() function. if SyncEnable
is false, high write performance but potential data loss likely. if SyncEnable
is true, slower but persistent.
- StartFileLoadingMode RWMode
StartFileLoadingMode
represents when opening a database in which RWMode loads files.
This Golang Package is inspired by the following:
License
The NutsDB is open-sourced software licensed under the Apache 2.0 license.
There is no ads to display, Please add some