目的
通过搭建一个高可用的redis客户端来学习redis,go语言,以及go一些设计模式
参考资料
go-redis源码
《redis设计与实现》
学习思路
循环渐进,从最简单的一步步迭代
一个最简单的能跑通的redis客户端例子
package main
import (
"fmt"
"net"
"strings"
)
type options struct {
Network string
Addr string
}
func (p *options) init() {
if p.Addr == "" {
p.Addr = "127.0.0.1:6379"
}
if p.Network == "" {
p.Network = "tcp"
}
}
//redis struct
type redisClient struct {
opt options
conn net.Conn
sendCmd string
reply string
}
func (c *redisClient) connect() {
conn, err := net