Or simply - a light-weight distributed in-memory key-value store inspired primarily by Hazelcast.
IMDGO is built on top of Raft consensus protocol (Hashicorp's implementation) where all write (set and delete) operations are done through Raft and reads are done from a local replica. This means that it is possible for a read operation to see a stale value in some cases (e.g. a value is updated on the leader while the same value is read from some follower node that didn't get the updated value). This, on the other hand, makes read operation really fast.
Because of the leader based replication with Raft, every write and delete operation go to the leader (in case request hits a follower node) and then are replicated to followers. Currently, these requests are forwarded via plain old HTTP with JSON, but it will be done with MessagePack or gRPC.
It uses orcaman/concurrent-map as an underlining map to reduce locking and contention as much as possible.
Upcoming features:
- Stronger consistency model and ability to configure it
- data partitioning (currently every node holds all the data)
- multiple distinct maps
- item TTL and eviction
- memory usage management (set the percentage of the app's memory for imdgo)
- store management API
Beside the new stuff, there are non-functional things to improve and for sure bugs to fix.
Import the package:
import (
"github.com/inelpandzic/imdgo"
)
go get "github.com/inelpandzic/imdgo"
// set the members of your application cluster
c := &imdgo.Config{Members: []string{"192.168.10.1", "192.168.10.2", "192.168.10.3"}}
store, err := imdgo.New(c)
if err != nil {
panic(err)
}
defer store.Close()
key := "my-key"
// You can set the value on one node or application instance
err := store.Set(key, "and my value which can be anything, not just string")
if err != nil {
log.Error(err))
}
// And then you can get it on some other application instance, safely replicated
if val, ok := m.Get(key); ok {
fmt.Println(val)
}
For now, imdgo runs with only default preconfigured ports 6701
and 6801
which needs to be available.
Credit goes to otoolep and his hraft for helping me get started quickly with Hashicorp's Raft lib. There is code from hraft in imdgo, I don't change something that is good for the time being.