2014-11-21 05:32:33 +03:00
# LedisDB
2020-05-10 13:17:39 +03:00
[![Build Status ](https://travis-ci.org/ledisdb/ledisdb.svg?branch=develop )](https://travis-ci.org/ledisdb/ledisdb) [![codecov ](https://codecov.io/gh/ledisdb/ledisdb/branch/master/graph/badge.svg )](https://codecov.io/gh/ledisdb/ledisdb) [![goreportcard ](https://goreportcard.com/badge/github.com/ledisdb/ledisdb )](https://goreportcard.com/report/github.com/ledisdb/ledisdb)
2014-05-22 04:52:38 +04:00
2020-05-10 13:17:39 +03:00
Ledisdb is a high-performance NoSQL database library and server written in [Go ](http://golang.org ). It's similar to Redis but store data in disk. It supports many data structures including kv, list, hash, zset, set.
2014-07-26 05:22:09 +04:00
2014-11-24 04:25:25 +03:00
LedisDB now supports multiple different databases as backends.
2014-05-22 04:52:38 +04:00
2014-07-11 13:30:40 +04:00
## Features
2015-03-03 04:21:00 +03:00
+ Rich data structure: KV, List, Hash, ZSet, Set.
2014-11-24 04:25:25 +03:00
+ Data storage is not limited by RAM.
2016-05-01 18:33:02 +03:00
+ Various backends supported: LevelDB, goleveldb, RocksDB, RAM.
2014-11-24 04:25:25 +03:00
+ Supports Lua scripting.
+ Supports expiration and TTL.
+ Can be managed via redis-cli.
2014-08-06 05:30:44 +04:00
+ Easy to embed in your own Go application.
2014-11-24 04:25:25 +03:00
+ HTTP API support, JSON/BSON/msgpack output.
+ Replication to guarantee data safety.
+ Supplies tools to load, dump, and repair database.
2020-05-10 13:47:46 +03:00
+ Supports cluster, use [xcodis ](https://github.com/ledisdb/xcodis ).
+ Authentication (though, not via http).
+ Repair integrated: You can use `ledis repair` to repair broken databases and `ledis repair-ttl` to repair a very serious bug for key expiration and TTL if you upgraded from v0.4.
2014-07-11 13:30:40 +04:00
2020-04-24 08:01:35 +03:00
## Build from source
2014-05-22 04:52:38 +04:00
2014-07-26 05:22:09 +04:00
Create a workspace and checkout ledisdb source
2020-04-24 08:01:35 +03:00
git clone git@github.com:ledisdb/ledisdb.git
cd ledisdb
2014-05-22 04:52:38 +04:00
2014-07-28 10:20:18 +04:00
#set build and run environment
source dev.sh
2014-07-28 08:46:17 +04:00
make
make test
2014-05-22 04:52:38 +04:00
2020-04-24 08:01:35 +03:00
Then you will find all the binary build on `./bin` directory.
2014-07-26 05:22:09 +04:00
## LevelDB support
2014-05-22 04:52:38 +04:00
2014-07-26 14:39:54 +04:00
+ Install leveldb and snappy.
2014-05-22 04:52:38 +04:00
2014-07-27 03:01:01 +04:00
LedisDB supplies a simple script to install leveldb and snappy:
2014-05-22 04:52:38 +04:00
2014-08-27 10:31:46 +04:00
sudo sh tools/build_leveldb.sh
2014-05-22 04:52:38 +04:00
2014-11-24 04:25:25 +03:00
It will install leveldb at /usr/local/leveldb and snappy at /usr/local/snappy by default.
2014-07-21 06:46:11 +04:00
2020-04-24 08:01:35 +03:00
LedisDB uses the modified LevelDB for better performance. [Details. ](https://github.com/ledisdb/ledisdb/wiki/leveldb-source-modification )
2014-05-22 04:52:38 +04:00
2014-11-24 04:25:25 +03:00
You can easily use other LevelDB versions (like Hyper LevelDB or Basho LevelDB) instead, as long as the header files are in `include/leveldb` , not `include/hyperleveldb` or any other location.
2014-10-16 07:10:19 +04:00
2014-09-13 10:11:05 +04:00
+ Set `LEVELDB_DIR` and `SNAPPY_DIR` to the actual install path in dev.sh.
+ `make clean && make`
2014-05-22 04:52:38 +04:00
2017-03-12 16:21:49 +03:00
## RocksDB support
2014-05-22 04:52:38 +04:00
2017-03-12 16:21:49 +03:00
+ [Install rocksdb(5.1+) ](https://github.com/facebook/rocksdb/blob/master/INSTALL.md )(`make shared_lib`) and snappy first.
2014-07-26 14:39:54 +04:00
2014-11-24 04:25:25 +03:00
LedisDB has not yet supplied a simple script to install.
2014-07-26 14:39:54 +04:00
2014-09-13 10:11:05 +04:00
+ Set `ROCKSDB_DIR` and `SNAPPY_DIR` to the actual install path in `dev.sh` .
+ `make clean && make`
2014-07-26 14:39:54 +04:00
2014-10-05 04:56:35 +04:00
2017-03-14 17:13:22 +03:00
If the RocksDB API changes, LedisDB may not build successfully. LedisDB currently supports RocksDB version 5.1 or later.
2014-08-12 10:44:16 +04:00
2014-07-26 14:39:54 +04:00
## Choose store database
2016-05-01 18:33:02 +03:00
LedisDB now supports goleveldb, leveldb, rocksdb, and RAM. It will use goleveldb by default.
2014-07-26 14:39:54 +04:00
2014-11-24 04:25:25 +03:00
Choosing a store database to use is very simple.
2014-07-26 14:39:54 +04:00
+ Set in server config file
2014-08-07 12:49:48 +04:00
db_name = "leveldb"
2014-07-26 14:39:54 +04:00
+ Set in command flag
2014-08-08 03:45:34 +04:00
ledis-server -config=/etc/ledis.conf -db_name=leveldb
2014-07-26 14:39:54 +04:00
2014-11-24 04:25:25 +03:00
Flag command set will overwrite config setting.
2014-07-26 14:39:54 +04:00
2014-09-07 06:58:18 +04:00
## Lua support
2014-07-26 14:39:54 +04:00
2017-04-15 16:51:03 +03:00
Lua is supported using [gopher-lua ](https://github.com/yuin/gopher-lua ), a Lua VM, completely written in Go.
2014-05-22 04:52:38 +04:00
2014-08-08 03:45:34 +04:00
## Configuration
2014-08-27 11:37:42 +04:00
LedisDB uses [toml ](https://github.com/toml-lang/toml ) as the configuration format. The basic configuration ```./etc/ledis.conf``` in LedisDB source may help you.
2014-08-08 03:45:34 +04:00
If you don't use a configuration, LedisDB will use the default for you.
2014-07-21 06:46:11 +04:00
## Server Example
2014-07-28 10:20:18 +04:00
//set run environment if not
source dev.sh
2014-05-22 04:52:38 +04:00
2016-05-01 18:33:02 +03:00
./bin/ledis-server -config=/etc/ledis.conf
2014-05-22 04:52:38 +04:00
2014-06-12 11:56:04 +04:00
//another shell
2016-05-01 18:33:02 +03:00
./bin/ledis-cli -p 6380
2014-06-12 11:56:04 +04:00
2014-06-22 17:05:52 +04:00
ledis 127.0.0.1:6380> set a 1
2014-06-12 11:56:04 +04:00
OK
2014-06-22 17:05:52 +04:00
ledis 127.0.0.1:6380> get a
2014-06-12 11:56:04 +04:00
"1"
2014-08-04 07:55:39 +04:00
//use curl
curl http://127.0.0.1:11181/SET/hello/world
→ {"SET":[true,"OK"]}
curl http://127.0.0.1:11181/0/GET/hello?type=json
→ {"GET":"world"}
2014-07-21 06:46:11 +04:00
## Package Example
2014-06-12 11:56:04 +04:00
2015-10-25 12:06:37 +03:00
import (
2020-04-24 08:01:35 +03:00
lediscfg "github.com/ledisdb/ledisdb/config"
"github.com/ledisdb/ledisdb/ledis"
2015-10-25 12:06:37 +03:00
)
# Use Ledis's default config
cfg := lediscfg.NewConfigDefault()
2014-07-04 11:45:23 +04:00
l, _ := ledis.Open(cfg)
2014-06-12 11:56:04 +04:00
db, _ := l.Select(0)
db.Set(key, value)
db.Get(key)
2014-07-21 06:46:11 +04:00
## Replication Example
2014-06-12 11:56:04 +04:00
2014-07-16 10:34:08 +04:00
Set slaveof in config or dynamiclly
2014-06-12 11:56:04 +04:00
2014-06-22 17:05:52 +04:00
ledis-cli -p 6381
2014-06-12 11:56:04 +04:00
2014-07-24 08:16:42 +04:00
ledis 127.0.0.1:6381> slaveof 127.0.0.1 6380
2014-06-12 11:56:04 +04:00
OK
2014-12-04 15:59:16 +03:00
## Cluster support
2020-05-10 08:32:35 +03:00
LedisDB uses a proxy named [xcodis ](https://github.com/ledisdb/xcodis ) to support cluster.
2014-12-04 15:59:16 +03:00
2020-04-24 08:27:36 +03:00
## CONTRIBUTING
See [CONTRIBUTING.md] .
2014-05-22 04:52:38 +04:00
## Benchmark
2020-04-24 08:01:35 +03:00
See [benchmark ](https://github.com/ledisdb/ledisdb/wiki/Benchmark ) for more.
2014-05-22 04:52:38 +04:00
## Todo
2020-04-24 08:01:35 +03:00
See [Issues todo ](https://github.com/ledisdb/ledisdb/issues?labels=todo&page=1&state=open )
2014-05-22 04:52:38 +04:00
2014-10-17 06:30:48 +04:00
## Client
2020-04-24 08:01:35 +03:00
See [Clients ](https://github.com/ledisdb/ledisdb/wiki/Clients ) to find or contribute LedisDB client.
2014-06-30 07:48:09 +04:00
2014-07-16 12:58:03 +04:00
## Links
2014-06-30 07:48:09 +04:00
2020-04-24 08:01:35 +03:00
+ [Official Website ](https://ledisdb.io )
+ [GoDoc ](https://godoc.org/github.com/ledisdb/ledisdb )
+ [Server Commands ](https://github.com/ledisdb/ledisdb/wiki/Commands )
2014-06-30 07:48:09 +04:00
2014-09-07 06:58:18 +04:00
## Caveat
2014-11-24 04:25:25 +03:00
+ Changing the backend database at runtime is very dangerous. Data validation is not guaranteed if this is done.
2014-06-30 07:48:09 +04:00
2014-11-19 05:26:50 +03:00
## Requirement
2014-07-21 06:46:11 +04:00
2020-04-24 08:27:36 +03:00
+ Go version >= 1.11
2014-07-16 10:34:08 +04:00
2016-11-24 04:27:38 +03:00
## Related Repos
+ [pika ](https://github.com/Qihoo360/pika )
2017-03-14 17:13:22 +03:00
## Donate
If you like the project and want to buy me a cola, you can through:
|PayPal|微信|
|------|---|
|[![](https://www.paypalobjects.com/webstatic/paypalme/images/pp_logo_small.png)](https://paypal.me/siddontang)|[![](https://github.com/siddontang/blog/blob/master/donate/weixin.png)|
2014-05-22 04:52:38 +04:00
## Feedback
2014-12-03 12:27:15 +03:00
+ Gmail: siddontang@gmail.com