A high performance NoSQL Database Server powered by Go

LedisDB

Build Status codecov goreportcard

Ledisdb is a high-performance NoSQL database library and server written in Go. It's similar to Redis but store data in disk. It supports many data structures including kv, list, hash, zset, set.

LedisDB now supports multiple different databases as backends.

Features

  • Rich data structure: KV, List, Hash, ZSet, Set.
  • Data storage is not limited by RAM.
  • Various backends supported: LevelDB, goleveldb, RocksDB, RAM.
  • Supports Lua scripting.
  • Supports expiration and TTL.
  • Can be managed via redis-cli.
  • Easy to embed in your own Go application.
  • HTTP API support, JSON/BSON/msgpack output.
  • Replication to guarantee data safety.
  • Supplies tools to load, dump, and repair database.
  • Supports cluster, use 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.

Build from source

Create a workspace and checkout ledisdb source

git clone [email protected]:ledisdb/ledisdb.git
cd ledisdb

#set build and run environment 
source dev.sh

make
make test

Then you will find all the binary build on ./bin directory.

LevelDB support

  • Install leveldb and snappy.

    LedisDB supplies a simple script to install leveldb and snappy:

      sudo sh tools/build_leveldb.sh
    

    It will install leveldb at /usr/local/leveldb and snappy at /usr/local/snappy by default.

    LedisDB uses the modified LevelDB for better performance. Details.

    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.

  • Set LEVELDB_DIR and SNAPPY_DIR to the actual install path in dev.sh.

  • make clean && make

RocksDB support

  • Install rocksdb(5.1+)(make shared_lib) and snappy first.

    LedisDB has not yet supplied a simple script to install.

  • Set ROCKSDB_DIR and SNAPPY_DIR to the actual install path in dev.sh.

  • make clean && make

If the RocksDB API changes, LedisDB may not build successfully. LedisDB currently supports RocksDB version 5.1 or later.

Choose store database

LedisDB now supports goleveldb, leveldb, rocksdb, and RAM. It will use goleveldb by default.

Choosing a store database to use is very simple.

  • Set in server config file

    db_name = "leveldb"

  • Set in command flag

    ledis -config=/etc/ledis.conf -db_name=leveldb

Flag command set will overwrite config setting.

Lua support

Lua is supported using gopher-lua, a Lua VM, completely written in Go.

Configuration

LedisDB uses toml as the configuration format. The basic configuration ./etc/ledis.conf in LedisDB source may help you.

If you don't use a configuration, LedisDB will use the default for you.

Server Example

//set run environment if not
source dev.sh

./bin/ledis -config=/etc/ledis.conf

//another shell
./bin/ledis cli -p 6380

ledis 127.0.0.1:6380> set a 1
OK
ledis 127.0.0.1:6380> get a
"1"

//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"}

Package Example

import (
    lediscfg "github.com/ledisdb/ledisdb/config"
    "github.com/ledisdb/ledisdb/ledis"
)

# Use Ledis's default config
cfg := lediscfg.NewConfigDefault()
l, _ := ledis.Open(cfg)
db, _ := l.Select(0)

db.Set(key, value)

db.Get(key)

Replication Example

Set slaveof in config or dynamiclly

ledis cli -p 6381 

ledis 127.0.0.1:6381> slaveof 127.0.0.1 6380
OK

Cluster support

LedisDB uses a proxy named xcodis to support cluster.

CONTRIBUTING

See [CONTRIBUTING.md] .

Benchmark

See benchmark for more.

Todo

See Issues todo

Client

See Clients to find or contribute LedisDB client.

Links

Caveat

  • Changing the backend database at runtime is very dangerous. Data validation is not guaranteed if this is done.

Requirement

  • Go version >= 1.11

Related Repos

Donate

If you like the project and want to buy me a cola, you can through:

PayPal 微信
[

Feedback

Owner
LedisDB
A high performance NoSQL Database Server powered by Go
LedisDB
Comments
  • LedisDB QA LLEN and more ...

    LedisDB QA LLEN and more ...

    assuming you already know, webapps often use lists like; comments, likes etc.. followers etc.. I see that; rocksdb rocks with ledisdb. however, never saw benchmark results for LLEN. does it full scan over list ? or it incr + 1 when we command lpush. I don;t think that fullscan is somehow faster than a local key - value. I short, I wonder LLEN performance and how it works :)

  • refactor scan command

    refactor scan command

    Now "scan" commands are very redundant and complicate, see #137. It is time to refactor them.

    For compatibility, I may not remove old XSCAN, XLSCAN, etc..., so maybe another API is better, like this:

    XKEYSCAN type cursor [MATCH match] [COUNT count]
    

    "type" is kv, list, hash, set, and zset. This API likes redis SCAN, to iterates keys, for different data type.

    But if we don't care compatibility, we may use XSCAN instead, @pkieltyka.

    XHSCAN key cursor [MATCH match] [COUNT count]
    

    XHSCAN likes redis HSCAN to iterates hash field and values.

    XSSCAN key cursor [MATCH match] [COUNT count]
    

    XSSCAN likes redis SSCAN to iterates set memebers.

    XZSCAN key cursor [MATCH match] [COUNT count]
    

    XZSCAN likes redis ZSCAN to iterates zset element and score.

  • RAM is very slow for HMset and and HMget

    RAM is very slow for HMset and and HMget

    https://github.com/siddontang/ledisdb/issues/354

    extremely slow, how do I speed it up? Afterall, I'm using RAM, using redis directly is 2x slower (because of the TCP roundtrip i suspect) but other in-memory such as freecache is running around 50ms average for both SET and GET.

    Currently with the example you have provided, I'm running HMset at 6s. Can you pls give example on how to speed this up? I suspect it's at the FVPair area but... any ideas?

    Hope you can look into the GC area like freecache. Thanks in advance.

    pure SET and GET only 3x slower than freecache which is "acceptable"

  • fail to add lua when compiling

    fail to add lua when compiling

    godep go install -tags 'linenoise leveldb lua' ./... github.com/siddontang/ledisdb/vendor/lua could not determine kind of name for C.lua_tointeger could not determine kind of name for C.lua_tonumber godep: go exit status 2 make: *** [build] Error 1

    An error with lua version? I 'm using lua-5.2

  • make through error cmd/ledis-load/main.go:6:2: cannot find package

    make through error cmd/ledis-load/main.go:6:2: cannot find package "github.com/siddontang/ledisdb/config" in any of:

    uname -a

    Linux ubdesk1404 3.13.0-53-generic #89-Ubuntu SMP Wed May 20 10:34:39 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

    $PATH

    /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/cloud/gocode/bin

    make

    godep go install -tags 'linenoise ' ./... cmd/ledis-load/main.go:6:2: cannot find package "github.com/siddontang/ledisdb/config" in any of: /usr/src/pkg/github.com/siddontang/ledisdb/config (from $GOROOT) /home/cloud/prototypes/ledisdb/src/github.com/siddontang/ledisdb/Godeps/_workspace/src/github.com/siddontang/ledisdb/config (from $GOPATH) /home/cloud/gocode/src/github.com/siddontang/ledisdb/config cmd/ledis-load/main.go:7:2: cannot find package "github.com/siddontang/ledisdb/ledis" in any of: /usr/src/pkg/github.com/siddontang/ledisdb/ledis (from $GOROOT) /home/cloud/prototypes/ledisdb/src/github.com/siddontang/ledisdb/Godeps/_workspace/src/github.com/siddontang/ledisdb/ledis (from $GOPATH)

  • 内存数据库LPop后内存降不下来

    内存数据库LPop后内存降不下来

    //在一个go程里不停地往ledis数据库里插入,达到一定的长底LPop数据。跑了5300秒,内存占用从最开始的324468KB 到最后的964292KB,中间一直在上涨,没有降过。

    const (
        K_LOGS = "logs"
    )
    
    func textInsert(db *ledis.DB, val []byte, limit int) {
        c, err := db.RPush([]byte(K_LOGS), []byte(fmt.Sprintf("[%s] %s", time.Now().String(), string(val))))
        if err != nil {
            log.Fatalln("add log of ", val, " failed:", err)
        }
        if c > int64(limit) {
            if _, err := db.LPop([]byte(K_LOGS)); err != nil {
                log.Fatalln("pop log failed:", err)
            }
        }
    }
    
    func main() {
        var l *ledis.Ledis
        var db *ledis.DB
        var err error
    
        cfg := lediscfg.NewConfigDefault()
        cfg.DBName = goleveldb.MemDBName
        if l, err = ledis.Open(cfg); err != nil {
            log.Println("open underlying log db failed")
            log.Fatalln(err)
        }
    
        if db, err = l.Select(0); err != nil {
            log.Println("open underlying log db failed")
            log.Fatalln(err)
        }
    
        mylimit := 20000
        for i := 0; ; i++ {
            textInsert(db, []byte(fmt.Sprintf("hello %d", i)), mylimit)
        }
    }
    
  • Cross compile application using ledis fails

    Cross compile application using ledis fails

    Any ideas how to workaround the following issue:

    $ GOOS=linux GOARCH=amd64 go build -o streams_$GOOS_$GOARCH
    Godeps/_workspace/src/github.com/siddontang/ledisdb/store/mdb/mdb.go:9:2: C source files not allowed when not using cgo: mdb.c midl.c
    

    I am building my app on a Mac for Linux using go 1.4.2. My app depends on Ledis (v0.4-61-gb9d10ac). I am using the boltdb or memory backend, so I dont even need mdb support.

  • Ledis-server cli, config file required

    Ledis-server cli, config file required

    My first time playing with ledis-server, just wanted to offer some feedback. The "-config" file must exist or the server can't be started. Rather it makes more sense to either require config or db_name to start since the config file doesnt have anything in it besides the db_name.

    Also, perhaps instead of a json config file you could use https://github.com/BurntSushi/toml ? .. doesnt really matter I guess, but even if you call it /etc/ledis.conf using a toml format, it will feel good and unixy, and just a better format for this kind of thing IMHO.

  • Swapping master and slave and setting up new master/slave replication

    Swapping master and slave and setting up new master/slave replication

    We had a ledis master/slave setup that was replicating fine.

    We recently experienced some data corruption on the master so we took it down and promoted the slave to be the new master.

    Replication now no longer works between the new master and the old master (which is now the slave). The new slave had all its prior data removed and should just function like a brand new ledis slave node.

    On the new master:

    10.0.0.208:6380> info replication
    # Replication
    role:master
    pub_log_num:0
    pub_log_ack_per_time:0
    slaveof:
    slaves:10.0.0.99:6380
    last_log_id:4102189945
    first_log_id:4050241982
    commit_log_id:4102189945
    master_last_log_id:0
    

    On the new slave:

    10.0.0.99:6380> info replication
    # Replication
    role:slave
    pub_log_num:0
    pub_log_ack_per_time:0
    slaveof:10.0.0.208:6380
    last_log_id:0
    first_log_id:0
    commit_log_id:0
    master_last_log_id:0
    master_link_status:up
    slave_priority:100
    slave_repl_offset:0
    

    Is there some additional tasks required to set up replication in this case?

  • Replication not working

    Replication not working

    Hello,

    2 newest version ledis-server "localhost:6380" "localhost:6381" are running, and I want to replicate them. But "SLAVEOF" command return following error.

    127.0.0.1:6381> slaveof 127.0.0.1 6380
    (error) ERR slaveof must enable replication
    

    I changed use_replication=false to true and restart, but nothing goes well. Is there another options essential to start replication?

    Then I put slaveof="localhost:6380" to the conf of localhost:6381 and restart. Now localhost:6381 should be slave, and ROLE command displays like this.

    127.0.0.1:6381> role
    1) "slave"
    2) "localhost"
    3) (integer) 6381
    4) "connect"
    5) (integer) 0
    

    Status is slave. It's ok. but "3) (integer) 6381" is slave port. According to redis reference, this should be master port.

    master node show following. this means master without slave.

    127.0.0.1:6380> role
    1) "master"
    2) (integer) 0
    3) (empty list or set)
    

    Replication not working.

    redis-cli -p 6380
    127.0.0.1:6380> set a b
    OK
    127.0.0.1:6380> get a
    "b"
    redis-cli -p 6381
    127.0.0.1:6381> get a
    (nil)
    

    I found nothing under the path "data_dir/rpl". Am I doing something wrong?

  • how to support lmdb

    how to support lmdb

    make build_lmdb

    godep go install -tags ' lmdb' ./...
    godep: WARNING: Go version (go1.6) & $GO15VENDOREXPERIMENT=1 wants to enable the vendor experiment, but disabling because a Godep workspace (Godeps/_workspace) exists package github.com/siddontang/ledisdb/cmd/ledis-load imports github.com/siddontang/ledisdb/ledis imports github.com/siddontang/ledisdb/rpl imports github.com/siddontang/ledisdb/store imports github.com/siddontang/ledisdb/store/mdb imports github.com/siddontang/ledisdb/vendor/gomdb: must be imported as gomdb godep: go exit status 1 make: *** [build_lmdb] 错误 1

A rudimentary implementation of a basic document (NoSQL) database in Go
A rudimentary implementation of a basic document (NoSQL) database in Go

tiedot Documentation Keywords: Golang, go, document database, NoSQL, JSON tiedot - Your NoSQL database powered by Golang tiedot is a document database

Dec 11, 2022
Couchbase - distributed NoSQL cloud database

couchbase Couchbase is distributed NoSQL cloud database. create Scope CREATE SCO

Feb 16, 2022
A lightweight document-oriented NoSQL database written in pure Golang.
A lightweight document-oriented NoSQL database written in pure Golang.

Lightweight document-oriented NoSQL Database ???? English | ???? 简体中文 | ???? Spanish CloverDB is a lightweight NoSQL database designed for being simpl

Jan 1, 2023
LinDB is an open-source Time Series Database which provides high performance, high availability and horizontal scalability.
LinDB is an open-source Time Series Database which provides high performance, high availability and horizontal scalability.

LinDB is an open-source Time Series Database which provides high performance, high availability and horizontal scalability. LinDB stores all monitoring data of ELEME Inc, there is 88TB incremental writes per day and 2.7PB total raw data.

Jan 1, 2023
NoSql DB using fileSystems using golang

No SQL DB using Go Prerequisite go 1.15 Run test go test -v ./... Env Var Variable Description Default Value Possible Values DB_DATA dir location to s

Nov 8, 2021
A decentralized, trusted, high performance, SQL database with blockchain features
A decentralized, trusted, high performance, SQL database with blockchain features

中文简介 CovenantSQL(CQL) is a Byzantine Fault Tolerant relational database built on SQLite: ServerLess: Free, High Availabile, Auto Sync Database Service

Jan 3, 2023
High-performance Redis-Server multi-threaded framework, based on rawepoll model.
High-performance Redis-Server multi-threaded framework, based on rawepoll model.

RedHub High-performance Redis-Server multi-threaded framework, based on RawEpoll model. Ultra high performance Fully multi-threaded support Low CPU re

Dec 18, 2022
Owl is a db manager platform,committed to standardizing the data, index in the database and operations to the database, to avoid risks and failures.

Owl is a db manager platform,committed to standardizing the data, index in the database and operations to the database, to avoid risks and failures. capabilities which owl provides include Process approval、sql Audit、sql execute and execute as crontab、data backup and recover .

Nov 9, 2022
This is a simple graph database in SQLite, inspired by "SQLite as a document database".

About This is a simple graph database in SQLite, inspired by "SQLite as a document database". Structure The schema consists of just two structures: No

Jan 3, 2023
Hard Disk Database based on a former database

Hard Disk Database based on a former database

Nov 1, 2021
Simple key value database that use json files to store the database

KValDB Simple key value database that use json files to store the database, the key and the respective value. This simple database have two gRPC metho

Nov 13, 2021
Beerus-DB: a database operation framework, currently only supports Mysql, Use [go-sql-driver/mysql] to do database connection and basic operations

Beerus-DB · Beerus-DB is a database operation framework, currently only supports Mysql, Use [go-sql-driver/mysql] to do database connection and basic

Oct 29, 2022
A GPU-powered real-time analytics storage and query engine.
A GPU-powered real-time analytics storage and query engine.

AresDB AresDB is a GPU-powered real-time analytics storage and query engine. It features low query latency, high data freshness and highly efficient i

Jan 7, 2023
An embedded key/value database for Go.

bbolt bbolt is a fork of Ben Johnson's Bolt key/value store. The purpose of this fork is to provide the Go community with an active maintenance and de

Jan 1, 2023
BuntDB is an embeddable, in-memory key/value database for Go with custom indexing and geospatial support
BuntDB is an embeddable, in-memory key/value database for Go with custom indexing and geospatial support

BuntDB is a low-level, in-memory, key/value store in pure Go. It persists to disk, is ACID compliant, and uses locking for multiple readers and a sing

Dec 30, 2022
CockroachDB - the open source, cloud-native distributed SQL database.
CockroachDB - the open source, cloud-native distributed SQL database.

CockroachDB is a cloud-native SQL database for building global, scalable cloud services that survive disasters. What is CockroachDB? Docs Quickstart C

Jan 2, 2023
ACID key-value database.

Coffer Simply ACID* key-value database. At the medium or even low latency it tries to provide greater throughput without losing the ACID properties of

Dec 7, 2022
Native GraphQL Database with graph backend
Native GraphQL Database with graph backend

The Only Native GraphQL Database With A Graph Backend. Dgraph is a horizontally scalable and distributed GraphQL database with a graph backend. It pro

Jan 4, 2023
EliasDB a graph-based database.
EliasDB a graph-based database.

EliasDB EliasDB is a graph-based database which aims to provide a lightweight solution for projects which want to store their data as a graph. Feature

Jan 4, 2023