github.com/bsm/planb
go get github.com/bsm/planb

github.com/bsm/planb

Build distributed, low-latency services with a redis-compatible protocol and sentinel client support

by bsm

v0.0.0-20180124163328-bd376ea137d7 (see all)License:Apache-2.0
go get github.com/bsm/planb
Readme

Plan B

GoDoc Build Status Go Report Card License

Plan B is a toolkit for building distributed, low-latency services that speak RESP (REdis Serialization Protocol). Under the hood, it is wrapping Redeo and Raft to create a concise interface for custom commands.

Examples

A simple server example:

package main

import (
  "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)
    }
}

GitHub Stars

11

LAST COMMIT

4yrs ago

MAINTAINERS

0

CONTRIBUTORS

1

OPEN ISSUES

0

OPEN PRs

0
VersionTagPublished
v0.0.0-20180124163328-bd376ea137d7
2yrs ago
No alternatives found
No tutorials found
Add a tutorial