All Projects → tidwall → Redcon

tidwall / Redcon

Licence: mit
Redis compatible server framework for Go

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Redcon

Exscript
A Python module making Telnet and SSH easy
Stars: ✭ 337 (-79.98%)
Mutual labels:  networking, protocol
Ngtcp2
ngtcp2 project is an effort to implement IETF QUIC protocol
Stars: ✭ 589 (-65%)
Mutual labels:  networking, protocol
Ceras
Universal binary serializer for a wide variety of scenarios https://discord.gg/FGaCX4c
Stars: ✭ 374 (-77.78%)
Mutual labels:  networking, protocol
Zenoh
zenoh unifies data in motion, data in-use, data at rest and computations. It carefully blends traditional pub/sub with geo-distributed storages, queries and computations, while retaining a level of time and space efficiency that is well beyond any of the mainstream stacks.
Stars: ✭ 182 (-89.19%)
Mutual labels:  networking, protocol
Anette
Simple haxe network library
Stars: ✭ 35 (-97.92%)
Mutual labels:  networking, protocol
Hazel Networking
Hazel Networking is a low level networking library for C# providing connection orientated, message based communication via TCP, UDP and RUDP.
Stars: ✭ 194 (-88.47%)
Mutual labels:  networking, protocol
Laminar
A simple semi-reliable UDP protocol for multiplayer games
Stars: ✭ 530 (-68.51%)
Mutual labels:  networking, protocol
Enet Csharp
Reliable UDP networking library
Stars: ✭ 464 (-72.43%)
Mutual labels:  networking, protocol
Network Programming
Small Projects on Socket Programming, Website Scanning, Wireless & Network Security
Stars: ✭ 33 (-98.04%)
Mutual labels:  networking, protocol
Metta
An information security preparedness tool to do adversarial simulation.
Stars: ✭ 867 (-48.48%)
Mutual labels:  redis, networking
Quic.net
A .NET C# Implementation of QUIC protocol - Google's experimental transport layer.
Stars: ✭ 173 (-89.72%)
Mutual labels:  networking, protocol
Mqtt
MQTT broker written in D, using vibe.d
Stars: ✭ 59 (-96.49%)
Mutual labels:  networking, protocol
Ruffles
Lightweight and fully managed reliable UDP library.
Stars: ✭ 131 (-92.22%)
Mutual labels:  networking, protocol
Golden Gate
Framework to connect wearables and other IoT devices to mobile phones, tablets and PCs with an IP-based protocol stack over Bluetooth Low Energy
Stars: ✭ 223 (-86.75%)
Mutual labels:  networking, protocol
Awareness
The new architecture of co-computation for data processing and machine learning.
Stars: ✭ 11 (-99.35%)
Mutual labels:  networking, protocol
Ipfsfb
InterPlanetary File System for Business (IPFSfB) is an enterprise blockchain storage network based on InterPlanetary File System.
Stars: ✭ 57 (-96.61%)
Mutual labels:  networking, protocol
Redis Tools
my tools working with redis
Stars: ✭ 104 (-93.82%)
Mutual labels:  redis, protocol
Swiftwebsocket
Fast Websockets in Swift for iOS and OSX
Stars: ✭ 1,483 (-11.88%)
Mutual labels:  networking
Redishappy
Redis Sentinel high availabillity daemon
Stars: ✭ 111 (-93.4%)
Mutual labels:  redis
Projectoa
华理网院本科毕业设计 - 企业OA后台管理系统 基于springboot amazeui等
Stars: ✭ 110 (-93.46%)
Mutual labels:  redis

REDCON
GoDoc

Redis compatible server framework for Go

Features

  • Create a Fast custom Redis compatible server in Go
  • Simple interface. One function ListenAndServe and two types Conn & Command
  • Support for pipelining and telnet commands
  • Works with Redis clients such as redigo, redis-py, node_redis, and jedis
  • TLS Support
  • Compatible pub/sub support
  • Multithreaded

Installing

go get -u github.com/tidwall/redcon

Example

Here's a full example of a Redis clone that accepts:

  • SET key value
  • GET key
  • DEL key
  • PING
  • QUIT
  • PUBLISH channel message
  • SUBSCRIBE channel

You can run this example from a terminal:

go run example/clone.go
package main

import (
	"log"
	"strings"
	"sync"

	"github.com/tidwall/redcon"
)

var addr = ":6380"

func main() {
	var mu sync.RWMutex
	var items = make(map[string][]byte)
	var ps redcon.PubSub
	go log.Printf("started server at %s", addr)
	err := redcon.ListenAndServe(addr,
		func(conn redcon.Conn, cmd redcon.Command) {
			switch strings.ToLower(string(cmd.Args[0])) {
			default:
				conn.WriteError("ERR unknown command '" + string(cmd.Args[0]) + "'")
			case "ping":
				conn.WriteString("PONG")
			case "quit":
				conn.WriteString("OK")
				conn.Close()
			case "set":
				if len(cmd.Args) != 3 {
					conn.WriteError("ERR wrong number of arguments for '" + string(cmd.Args[0]) + "' command")
					return
				}
				mu.Lock()
				items[string(cmd.Args[1])] = cmd.Args[2]
				mu.Unlock()
				conn.WriteString("OK")
			case "get":
				if len(cmd.Args) != 2 {
					conn.WriteError("ERR wrong number of arguments for '" + string(cmd.Args[0]) + "' command")
					return
				}
				mu.RLock()
				val, ok := items[string(cmd.Args[1])]
				mu.RUnlock()
				if !ok {
					conn.WriteNull()
				} else {
					conn.WriteBulk(val)
				}
			case "del":
				if len(cmd.Args) != 2 {
					conn.WriteError("ERR wrong number of arguments for '" + string(cmd.Args[0]) + "' command")
					return
				}
				mu.Lock()
				_, ok := items[string(cmd.Args[1])]
				delete(items, string(cmd.Args[1]))
				mu.Unlock()
				if !ok {
					conn.WriteInt(0)
				} else {
					conn.WriteInt(1)
				}
			case "publish":
				if len(cmd.Args) != 3 {
					conn.WriteError("ERR wrong number of arguments for '" + string(cmd.Args[0]) + "' command")
					return
				}
				conn.WriteInt(ps.Publish(string(cmd.Args[1]), string(cmd.Args[2])))
			case "subscribe", "psubscribe":
				if len(cmd.Args) < 2 {
					conn.WriteError("ERR wrong number of arguments for '" + string(cmd.Args[0]) + "' command")
					return
				}
				command := strings.ToLower(string(cmd.Args[0]))
				for i := 1; i < len(cmd.Args); i++ {
					if command == "psubscribe" {
						ps.Psubscribe(conn, string(cmd.Args[i]))
					} else {
						ps.Subscribe(conn, string(cmd.Args[i]))
					}
				}
			}
		},
		func(conn redcon.Conn) bool {
			// Use this function to accept or deny the connection.
			// log.Printf("accept: %s", conn.RemoteAddr())
			return true
		},
		func(conn redcon.Conn, err error) {
			// This is called when the connection has been closed
			// log.Printf("closed: %s, err: %v", conn.RemoteAddr(), err)
		},
	)
	if err != nil {
		log.Fatal(err)
	}
}

TLS Example

Redcon has full TLS support through the ListenAndServeTLS function.

The same example is also provided for serving Redcon over TLS.

go run example/tls/clone.go

Benchmarks

Redis: Single-threaded, no disk persistence.

$ redis-server --port 6379 --appendonly no
redis-benchmark -p 6379 -t set,get -n 10000000 -q -P 512 -c 512
SET: 941265.12 requests per second
GET: 1189909.50 requests per second

Redcon: Single-threaded, no disk persistence.

$ GOMAXPROCS=1 go run example/clone.go
redis-benchmark -p 6380 -t set,get -n 10000000 -q -P 512 -c 512
SET: 2018570.88 requests per second
GET: 2403846.25 requests per second

Redcon: Multi-threaded, no disk persistence.

$ GOMAXPROCS=0 go run example/clone.go
$ redis-benchmark -p 6380 -t set,get -n 10000000 -q -P 512 -c 512
SET: 1944390.38 requests per second
GET: 3993610.25 requests per second

Running on a MacBook Pro 15" 2.8 GHz Intel Core i7 using Go 1.7

Contact

Josh Baker @tidwall

License

Redcon source code is available under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].