Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bsm/redeo
High-performance framework for building redis-protocol compatible TCP servers/services
https://github.com/bsm/redeo
go low-latency redis rpc service
Last synced: 2 days ago
JSON representation
High-performance framework for building redis-protocol compatible TCP servers/services
- Host: GitHub
- URL: https://github.com/bsm/redeo
- Owner: bsm
- License: apache-2.0
- Created: 2014-03-06T08:46:18.000Z (over 10 years ago)
- Default Branch: main
- Last Pushed: 2023-01-20T16:34:05.000Z (almost 2 years ago)
- Last Synced: 2024-07-31T20:50:52.107Z (3 months ago)
- Topics: go, low-latency, redis, rpc, service
- Language: Go
- Size: 164 KB
- Stars: 435
- Watchers: 28
- Forks: 39
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - redeo - Redis-protocol compatible TCP servers/services. (Database Drivers / NoSQL Database Drivers)
- awesome-go-storage - redis - Redis-protocol compatible TCP servers/services. (Database Drivers)
- awesome-go - redeo - High-performance framework for building redis-protocol compatible TCP servers/services - ★ 227 (Database Drivers)
- awesome-go-extra - redeo - performance framework for building redis-protocol compatible TCP servers/services|416|36|3|2014-03-06T08:46:18Z|2020-12-11T15:22:37Z| (Generators / NoSQL Database Drivers)
- awesome-go-storage - redeo - Redis-protocol compatible TCP servers/services. (Database Drivers)
README
# Redeo
[![Go Reference](https://pkg.go.dev/badge/github.com/bsm/redeo/v2)](https://pkg.go.dev/github.com/bsm/redeo/v2)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)The high-performance Swiss Army Knife for building redis-protocol compatible servers/services.
## Parts
This repository is organised into multiple components:
* [root](./) package contains the framework for building redis-protocol compatible,
high-performance servers.
* [resp](./resp/) implements low-level primitives for dealing with
RESP (REdis Serialization Protocol), client and server-side. It
contains basic wrappers for readers and writers to read/write requests and
responses.
* [client](./client/) contains a minimalist pooled client.For full documentation and examples, please see the individual packages and the
official API documentation: https://godoc.org/github.com/bsm/redeo.## Examples
A simple server example with two commands:
```go
package mainimport (
"net""github.com/bsm/redeo/v2"
)func main() {
srv := redeo.NewServer(nil)// Define handlers
srv.HandleFunc("ping", func(w resp.ResponseWriter, _ *resp.Command) {
w.AppendInlineString("PONG")
})
srv.HandleFunc("info", func(w resp.ResponseWriter, _ *resp.Command) {
w.AppendBulkString(srv.Info().String())
})// More handlers; demo usage of redeo.WrapperFunc
srv.Handle("echo", redeo.WrapperFunc(func(c *resp.Command) interface{} {
if c.ArgN() != 1 {
return redeo.ErrWrongNumberOfArgs(c.Name)
}
return c.Arg(0)
}))// Open a new listener
lis, err := net.Listen("tcp", ":9736")
if err != nil {
panic(err)
}
defer lis.Close()// Start serving (blocking)
srv.Serve(lis)
}
```More complex handlers:
```go
func main() {
mu := sync.RWMutex{}
data := make(map[string]string)
srv := redeo.NewServer(nil)srv.HandleFunc("set", func(w resp.ResponseWriter, c *resp.Command) {
if c.ArgN() != 2 {
w.AppendError(redeo.WrongNumberOfArgs(c.Name))
return
}key := c.Arg(0).String()
val := c.Arg(1).String()mu.Lock()
data[key] = val
mu.Unlock()w.AppendInt(1)
})srv.HandleFunc("get", func(w resp.ResponseWriter, c *resp.Command) {
if c.ArgN() != 1 {
w.AppendError(redeo.WrongNumberOfArgs(c.Name))
return
}key := c.Arg(0).String()
mu.RLock()
val, ok := data[key]
mu.RUnlock()if ok {
w.AppendBulkString(val)
return
}
w.AppendNil()
})
}
```Redeo also supports command wrappers:
```go
func main() {
mu := sync.RWMutex{}
data := make(map[string]string)
srv := redeo.NewServer(nil)srv.Handle("set", redeo.WrapperFunc(func(c *resp.Command) interface{} {
if c.ArgN() != 2 {
return redeo.ErrWrongNumberOfArgs(c.Name)
}key := c.Arg(0).String()
val := c.Arg(1).String()mu.Lock()
data[key] = val
mu.Unlock()return 1
}))srv.Handle("get", redeo.WrapperFunc(func(c *resp.Command) interface{} {
if c.ArgN() != 1 {
return redeo.ErrWrongNumberOfArgs(c.Name)
}key := c.Arg(0).String()
mu.RLock()
val, ok := data[key]
mu.RUnlock()if ok {
return val
}
return nil
}))
}
```