Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bsm/planb
Build distributed, low-latency services with a redis-compatible protocol and sentinel client support
https://github.com/bsm/planb
cluster distributed-database go golang low-latency raft redeo redis
Last synced: 2 months ago
JSON representation
Build distributed, low-latency services with a redis-compatible protocol and sentinel client support
- Host: GitHub
- URL: https://github.com/bsm/planb
- Owner: bsm
- License: other
- Created: 2017-09-20T14:22:17.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-01-24T16:33:33.000Z (almost 7 years ago)
- Last Synced: 2024-06-20T06:39:01.487Z (7 months ago)
- Topics: cluster, distributed-database, go, golang, low-latency, raft, redeo, redis
- Language: Go
- Size: 35.2 KB
- Stars: 12
- Watchers: 6
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Plan B
[![GoDoc](https://godoc.org/github.com/bsm/planb?status.svg)](https://godoc.org/github.com/bsm/planb)
[![Build Status](https://travis-ci.org/bsm/planb.png?branch=master)](https://travis-ci.org/bsm/planb)
[![Go Report Card](https://goreportcard.com/badge/github.com/bsm/planb)](https://goreportcard.com/report/github.com/bsm/planb)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)Plan B is a toolkit for building distributed, low-latency services that speak [RESP](https://redis.io/topics/protocol)
(REdis Serialization Protocol). Under the hood, it is wrapping [Redeo](https://github.com/bsm/redeo) and
[Raft](https://github.com/hashicorp/raft) to create a concise interface for custom commands.## Examples
A simple server example:
```go
package mainimport (
"fmt""github.com/bsm/planb"
"github.com/hashicorp/raft")
func main() {
// Open a store
store := planb.NewInmemStore()// Init config
conf := planb.NewConfig()
conf.Sentinel.MasterName = "mymaster" // handle SENTINEL commands// Init server
srv, err := planb.NewServer("10.0.0.1:7230", ".", store, raft.NewInmemStore(), raft.NewInmemStore(), conf)
if err != nil {
panic(err)
}// Setup SET handler
srv.HandleRW("SET", nil, redeo.WrapperFunc(func(cmd *resp.Command) interface{} {
if len(cmd.Args) != 2 {
return redeo.ErrWrongNumberOfArgs(cmd.Name)
}if err := store.Put(cmd.Args[0], cmd.Args[1]); err != nil {
return err
}
return "OK"
}))// Setup GET handler
srv.HandleRO("GET", nil, redeo.WrapperFunc(func(cmd *resp.Command) interface{} {
if len(cmd.Args) != 1 {
return redeo.ErrWrongNumberOfArgs(cmd.Name)
}val, err := store.Get(cmd.Args[0])
if err != nil {
return err
}
return val
}))// Start serving
if err := srv.ListenAndServe(); err != nil {
panic(err)
}
}
```