Suddenly, I looked for KVS that can be used as a library like SQLite and found it in LevelDB.
google / leveldb
LevelDB is a fast key-value storage library written at Google that provides an ordered mapping from string keys to string values.
LevelDB is a fast key-value storage library written at Google that provides an ordered mapping from string keys to string values.
Authors: Sanjay Ghemawat (sanjay@google.com) and Jeff Dean (jeff@google.com)
Features
- Keys and values are arbitrary byte arrays.
- Data is stored sorted by key.
- Callers can provide a custom comparison function to override the sort order.
- The basic operations are
Put(key,value)
,Get(key)
,Delete(key)
. - Multiple changes can be made in one atomic batch.
- Users can create a transient snapshot to get a consistent view of data.
- Forward and backward iteration is supported over the data.
- Data is automatically compressed using the Snappy compression library.
- External activity (file system operations etc.) is relayed through a virtual interface so users can customize the operating system interactions.
Documentation
LevelDB library documentation is online and bundled with the source code.
Limitations
- This is not a SQL database. It…
It was a pleasure to use plyvel of Python's LevelDB library, but I decided to create a client command because I don't want to not write Python every time to retrieve a list or list of keys or to delete unnecessary keys.
And here is the one.
yuuichi-fujioka / go-leveldbctl
LevelDB control command
leveldbctl
LevelDB control command.
This command provides easy way to CRUD operation on LevelDB.
$ leveldbctl put foo bar
put foo: bar into ./
$ leveldbctl get foo
bar
Features
- Initialize LevelDB
- Put key/value into LevelDB
- Get value with key
- Delete key
- Dump all key/values in LevelDB
- Print all keys
Install
$ export GO111MODULE=on
$ go get github.com/yuuichi-fujioka/go-leveldbctl/cmd/leveldbctl
Usage
NAME
leveldbctl - A new cli application
USAGE
leveldbctl [global options] command [command options] [arguments...]
VERSION:
0.0.0
COMMANDS:
init, i Initialize a LevelDB
walk, w Walk in a LevelDB
keys, k Search all keys in a LevelDB
put, p Put a value into a LevelDB
get, g Gut a value from a LevelDB
delete, d Delete a value from a LevelDB
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--dbdir value, -d value LevelDB Directory (default: "./") [$LEVELDB_DIR]
--hexkey, --xk
…It can be used by installing with go get.
$ go get github.com/yuuichi-fujioka/go-leveldbctl/cmd/leveldbctl
$ leveldbctl -h
NAME:
leveldbctl - A new cli application
USAGE:
leveldbctl [global options] command [command options] [arguments...]
VERSION:
0.0.0
COMMANDS:
init, i Initialize a LevelDB
walk, w Walk in a LevelDB
keys, k Search all keys in a LevelDB
put, p Put a value into a LevelDB
get, g Gut a value from a LevelDB
delete, d Delete a value from a LevelDB
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--dbdir value, -d value LevelDB Directory (default: "./") [$LEVELDB_DIR]
--help, -h show help
--version, -v print the version
How to Use
It can initialize and CRUD operation, assuming that the current directory is a directory of LevelDB. (Specific directories may be set as LevelDB with the options --dbdir
or -d
)
Initialize with init
, make it with put
, get it with get
, delete it with delete
.
$ leveldbctl init # Initialize. Several files are created.
./ is initialized as LevelDB
$ leveldbctl get aaa # When a key is not exist in db, it is displayed that it cannot be found.
aaa is not found.
$ leveldbctl put aaa bbb # Put bbb into aaa.
put aaa: bbb into ./.
$ leveldbctl get aaa # Got bbb
bbb
$ leveldbctl delete aaa # Delete it.
aaa is deleted
walk
can output all key values,keys
can output all keys.
$ leveldbctl keys
egg
foo
hoge
$ leveldbctl walk
egg: spam
foo: bar
hoge: fuga
Misc
- I tested it On Mac OS High Sierra and Ubuntu 16.04.4 LTS.。
- CLI is implemented using
github.com/urfave/cli
. - LevelDB operation uses
github.com/syndtr/goleveldb/leveldb
.
Top comments (2)
Did you try RocksDB? It's been working wonders for us.
Thank you! I will try it.