Redcon:快速的Redis服务器Go实现
Fast Redis compatible server framework for Go
Redcon is a custom Redis server framework for Go that is fast and simple to use. The reason for this library it to give an efficient server front-end for the BuntDB and Tile38 projects.
Features
- Create a Fast custom Redis compatible server in Go
- Simple interface. One function
ListenAndServeand two typesConn&Command - Support for pipelining and telnet commands
- Works with Redis clients such as redigo, redis-py, node_redis, and jedis
- TLS 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
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)
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)
}
}
},
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
Redcon:快速的Redis服务器Go实现的更多相关文章
- [Windows Azure] 使用 Windows Azure 快速搭建 Redis 服务器
[Windows Azure] 使用 Windows Azure 快速搭建 Redis 服务器 Redis相信玩开源,大数据的朋友们并不陌生,大家最熟悉的使用者就是新浪微博,微博的整体数据缓存都是 ...
- [Azure] 使用 Azure 快速搭建 Redis 服务器
Redis相信玩开源,大数据的朋友们并不陌生,大家最熟悉的使用者就是新浪微博,微博的整体数据缓存都是基于Redis的,而新浪对Redis的使用也非常深,据说是一组64G内存的Redis集群.前段时间我 ...
- C#客户端Redis服务器的分布式缓存
介绍 在这篇文章中,我想介绍我知道的一种最紧凑的安装和配置Redis服务器的方式.另外,我想简短地概述一下在.NET / C#客户端下Redis hash(哈希类型)和list(链表)的使用. 在这篇 ...
- 如何在 CentOS 7 上安装 Redis 服务器
大家好,本文的主题是 Redis,我们将要在 CentOS 7 上安装它.编译源代码,安装二进制文件,创建.安装文件.在安装了它的组件之后,我们还会配置 redis ,就像配置操作系统参数一样,目标就 ...
- SpringBoot学习(七)—— springboot快速整合Redis
目录 Redis缓存 简介 引入redis缓存 代码实战 Redis缓存 @ 简介 redis是一个高性能的key-value数据库 优势 性能强,适合高度的读写操作(读的速度是110000次/s,写 ...
- Mysql百万数据量级数据快速导入Redis
前言 随着系统的运行,数据量变得越来越大,单纯的将数据存储在mysql中,已然不能满足查询要求了,此时我们引入Redis作为查询的缓存层,将业务中的热数据保存到Redis,扩展传统关系型数据库的服务能 ...
- Redis数据类型简介(十分钟快速学习Redis)
如何在ubuntu18.04上安装和保护redis 如何连接到Redis数据库 如何管理Redis数据库和Keys 如何在Redis中管理副本和客户端 如何在Redis中管理字符串 如何在Redis中 ...
- Linux部署Redis服务器
一,Redis介绍 Redis如今已经成为Web开发社区最火热的内存数据库之一,随着Web2.0的快速发展,再加上半结构数据比重加大,网站对高效性能的需求也越来越多. 而且大型网站一般都有几百台或者更 ...
- Redis——学习之路二(初识redis服务器命令)
上一章我们已经知道了如果启动redis服务器,现在我们来学习一下,以及如何用客户端连接服务器.接下来我们来学习一下查看操作服务器的命令. 服务器命令: 1.info——当前redis服务器信息 s ...
随机推荐
- this 总结
谁最终调用函数,this指向谁!!! ① this指向的,永远只可能是对象! ② this指向谁,永远不取决于this写在哪!而是取决于函数在哪调用. ③ this指向的对象,我们称之为函数的 ...
- 简述 CGI、FastCGI和php-FPM的区别
1.CGI是联系webserver 跟php解析器的一个桥梁 2.FastCGI是CGI改良的版本 3.php-FPM 是FastCGI 的进程管理器
- Java链接Redis时出现 “ERR Client sent AUTH, but no password is set”
Java链接Redis时出现 “ERR Client sent AUTH, but no password is set” 异常的原因及解决办法. [错误提示] redis.clients.jedis ...
- LOJ P10147 石子合并 题解
Analysis 区间dp+前缀和 #include<iostream> #include<cstdio> #include<cstring> #include&l ...
- Linux core dump 诊断进程奔溃退出
最近项目中出现了一个问题,服务器端程序会突然崩溃退出,我们采取了coredump技术以找到崩溃原因,即确定进程退出时正在执行的函数是哪个,其状态如何. 如果系统开启了core ...
- 【説明する】hash
首先对于判重,我们能想到的方法有什么呢? 1)bool数组 2)set(集) 数组与集合的优缺点: 1.因为集合是对数组做的封装,所以,数组永远比任何一个集合要快. 2.数组声明了它容纳的元素的类型, ...
- angularJs 中controller与sever
网上找到的一个例子,感觉对于初学者理解将controller抽成服务有帮助.主要是方便理解什么时候应该来做服务. html部分 <!DOCTYPE html> <html ng-ap ...
- 关于Scanner调用 sc.nextInt() 异常try后不能二次输入导致死循环问题
先看下简化的代码,引出问题所在: public class Run { public static void main(String[] args) { Scanner sc = new Scanne ...
- 安卓APP在线升级
安卓APP在线升级 通过IDHTTP组件在线下载APP到手机中,然后自动安装这个APP程序. 1)在线下载APP程序 需引用单元: {$IFDEF ANDROID} FMX.Helpers.Andro ...
- gdal 遥感影像水体数据提取