• Stars
    star
    430
  • Rank 97,278 (Top 2 %)
  • Language
    Go
  • License
    Apache License 2.0
  • Created about 10 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

High-performance framework for building redis-protocol compatible TCP servers/services

Redeo

Go Reference License

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 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 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:

package main

import (
  "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:

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:

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
	}))
}

More Repositories

1

redislock

Simplified distributed locking implementation using Redis
Go
1,246
star
2

sarama-cluster

Cluster extensions for Sarama, the Go client library for Apache Kafka 0.9 [DEPRECATED]
Go
1,007
star
3

openrtb

OpenRTB protocol defintions for Go
Go
278
star
4

grpclb

External Load Balancing Service solution for gRPC written in Go
Go
264
star
5

grape-kaminari

kaminari paginator integration for grape API framework
Ruby
159
star
6

redis-lock

[DEPRECATED] Please see https://github.com/bsm/redislock instead
Go
142
star
7

ratelimit

Simple, thread-safe Go rate-limiter
Go
79
star
8

attribute-defaults

Simple ActiveRecord plugin that allows to specify default values for attributes
Ruby
52
star
9

poseidon_cluster

Poseidon cluster extensions
Ruby
42
star
10

fakengx

Library for testing Lua scripts embedded into Nginx
Lua
40
star
11

sidekiq-datadog

Ruby
31
star
12

lua-resty-http

Lua HTTP client driver for ngx_lua
Lua
31
star
13

activesupport-cache-database

ActiveSupport::Cache::Store implementation backed by a database via ActiveRecord
Ruby
27
star
14

ssdb-rb

Ruby client library for SSDB
Ruby
17
star
15

go-guid

MongoDB style globally unique identifiers in Go
Go
16
star
16

bitmap.lua

Lua bitmaps (aka bitstrings or bitsets) implemented in C
C
13
star
17

bfs

Multi-adapter bucket-based file system abstraction. #golang
Go
12
star
18

planb

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

go-geohex

GeoHex implementation in Go
Go
11
star
20

bps

Pub/sub & message processing abstraction
Go
11
star
21

appdash-rb

Ruby client for Appdash
Ruby
10
star
22

redpear

A simple, elegant & efficient ORM for Redis, optimised for speed!
Ruby
9
star
23

preferable

User preference management for ActiveRecord
Ruby
9
star
24

grape-pagy

Ruby
9
star
25

openmetrics

A standalone, dependency-free implementation of OpenMetrics v1.0
Go
8
star
26

qualify

Match a fact against large number of pre-defined rules in Go
Go
8
star
27

paperclip_remote

Plugin for Paperclip: Allows fetching attachments from remote locations
Ruby
8
star
28

fiddle

Ruby
7
star
29

raft-badger

Raft backend implementation using Badger
Go
7
star
30

extsort

External merge sort algorithm, implemented in Go
Go
7
star
31

drone-s3-cache

Go
6
star
32

macdaddy

MAC Daddy is a Go library for generating encrypted messages and verifying their authenticity using the Poly1305 message authentication code with a ChaCha20 cipher
Go
6
star
33

grape-app

Ruby
6
star
34

pivotable

Ruby
6
star
35

datadog-notifications

Ruby
6
star
36

go-sparkey

Go
6
star
37

bitset.lua

Bitsets (aka bitstrings or bitmaps) implemented in pure Lua
Lua
5
star
38

flood

Go
5
star
39

httpx

Useful and opinionated helpers for building secure HTTP services
Go
4
star
40

sntable

Fast, custom SSTable implementation with numeric keys.
Go
4
star
41

redeoraft

Raft transport implementation for Redeo servers #raft #golang #redeo #redis
Go
4
star
42

reason

Go
4
star
43

redis-balancer

Go
4
star
44

constrainable

Filtering for ActiveRecord. Sanitizes readable query parameters - great for building APIs & HTML filters.
Ruby
4
star
45

accord

Go
3
star
46

serialization_scopes

Define output scopes for XML/JSON serialization of your ActiveRecord models
Ruby
3
star
47

histogram

Streamining histograms in Go
Go
3
star
48

sarama

Sarama cluster extensions
3
star
49

streamsort

DEPRECATED: please use https://github.com/bsm/extsort instead
Go
3
star
50

sortable-by

Ruby
3
star
51

ccdb

Go
3
star
52

mlmetrics

Common metrics for evaluation of machine learning models
Go
3
star
53

pgpq

Priority queues with Postgres
Go
3
star
54

fleiss

Ruby
3
star
55

cdb64

Go
3
star
56

ginkgo

Straight copy of the excellent Ginkgo library, stripped to the bare core to be free of third-party dependencies.
Go
3
star
57

zetasketch

Go
2
star
58

cntdb

Go
2
star
59

dbx

Useful extensions to stdlib's database/sql
Go
2
star
60

nanoid

Go
2
star
61

geohex.lua

GeoHex V3 library for Lua
Lua
2
star
62

fluq

Coming soon
Ruby
2
star
63

redis-tools

Simple redis CLI helpers
Ruby
2
star
64

filterable-by

Ruby
2
star
65

grape-apidoc

Ruby
2
star
66

grpctools

Go
2
star
67

go-x

Useful extensions to the Go stdlib.
Go
2
star
68

shutdown

Go
2
star
69

firejwt

Validation for Firebase JWT
Go
2
star
70

pool

Go
2
star
71

strset

Go
2
star
72

multiredis

Go abstraction of various redis client types for simpler testing
Go
2
star
73

devise_imap_authenticatable

Ruby
2
star
74

feedx

Go
2
star
75

pbio

Ruby
1
star
76

gomega

Straight copy of the excellent Gomega library, stripped to the bare core to be free of third-party dependencies
Go
1
star
77

bst

Fast and generic Set and Map implementations using binary-search-trees.
Go
1
star
78

bsm.github.io

HTML
1
star
79

geo_hex

Ruby
1
star
80

pipa

Go
1
star
81

redis_recipes

Collection of Redis LUA recipes. Require Redis 2.6.0 or higher.
Ruby
1
star
82

geohashi

Go(lang) clone of geohash-int
Go
1
star
83

forensiq

Small tool for collecting forensic stats and storing them in Redis.
Go
1
star
84

disquo

Minimalist, threaded high-performance Ruby workers on top of Disque
Ruby
1
star
85

go-benchmark

Go (Awesome) Benchmarks
Go
1
star
86

intset

Go
1
star
87

paperclip_removable

Paperclip plugin: Allows removal of previously uploaded files
Ruby
1
star
88

timed_lru

Simple, thread-safe LRU with (optional) TTLs and constant time operations
Ruby
1
star
89

grape-app-doc

Ruby
1
star
90

gemical

Gemical command-line client.
Ruby
1
star
91

mgmt

Ruby
1
star
92

paperclip_bsm_s3

Custom extensions to Paperclip
Ruby
1
star
93

redpear.lua

Simplistic object mapper for Redis/Lua
Lua
1
star
94

go-vlq

Variable-length quantity encoding
Go
1
star
95

redis-cluster

Go
1
star
96

capistrano-golang

Ruby
1
star
97

quasizero

TCP server (and client) implementation, optimised for low latency and pipelined throughput
Go
1
star
98

tdigest

Implementation of Ted Dunning's t-digest in Go
Go
1
star
99

active-record-atomic

Ruby
1
star