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 ...
随机推荐
- Greenplum 常用数据字典
一.数据库集群信息 1.gp_segment_configration 2.pg_filespace_entry 这两个表是在pg_global表空间下面的,是全局表. 用来查看集群segment信息 ...
- 066_调整虚拟机内存参数的 shell 脚本
#!/bin/bash#脚本通过调用 virsh 命令实现对虚拟机的管理,如果没有该命令,需要安装 libvirt-client 软件包 cat << EOF1.调整虚拟机最大内存数值2. ...
- 十七.rsync+SSH同步
1. rsync同步操作 • 命令用法 – rsync [选项...] 源目录 目标目录 • 同步与复制的差异 – 复制:完全拷贝源到目标 – 同步:增量拷贝,只传输变化过的数据 • rsyn ...
- KindEditor3.x-自动上传Word图片功能.
Chrome+IE默认支持粘贴剪切板中的图片,但是我要发布的文章存在word里面,图片多达数十张,我总不能一张一张复制吧?Chrome高版本提供了可以将单张图片转换在BASE64字符串的功能.但是无法 ...
- gdisk分区命令
GPT fdisk(由gdisk.cgdisk.sgdisk和fixparts程序组成)是一组用于Linux.FreeBSD.Mac OS X和Windows的文本模式分区工具.gdisk.cgdis ...
- 代码 | 用ALNS框架求解一个TSP问题 - 代码详解
写在前面 前面好多篇文章,我们总算是把整个ALNS的代码框架给大家说明白了.不知道大家对整个框架了解了没有.不过打铁要趁热,心急了要吃热豆腐.今天就来实战一下,教大家怎么用ALNS的代码框架,求解一个 ...
- TensorFlow(十六):TensorFlow GPU准备
一:安装cuda 下载地址 二:安装cuDNN 三:安装GPU版TensorFlow 注意:gpu版的TensorFlow打开tensorboard要使用:tensorboard --logdir C ...
- 接口测试命令Httpie的使用
相比于curl命令,Httpie提供更清晰友好的界面,并支持授权,代理等操作 主要特性 直观的语法 格式化和色彩化的终端输出 内置 JSON 支持 支持上传表单和文件 HTTPS.代理和认证 任意请求 ...
- Java把多个list 合并成一个并去重
开发过程中遇到一个合并去重问题,任务完成后,总结出来一个比较简单的方法.对于List中不同类型的数据,需要采用不同的处理方式.List中如果是基础数据类型,直接合并去重即可:如果是对象类 ...
- C语言应用--数据类型定制一定义和引用
目前,定制正在变的越来越普遍,定制服务.定制衣服.甚至使用的键盘都是定制了.在C语言中虽然也包括了整型.字符型和浮点型等基本类型,也有基本的组合数据类型数组.但是这些类型都是针对某一种特定类型时应用没 ...