gedis:自己实现go语言的redis客户端

刚刚学习go语言,分享下实践过程,一步步实现一个平民版的redis客户端。

特性:
基于原生golang开发
连接池管理
keepalive支持
redisTemplate提供多种命令支持

 

实验测试:

package main

import (
	"tcp"
	"fmt"
	"template"
)

func main() {
	testPool()
}

func testPool(){
	var config = tcp.ConnConfig{"10.10.5.239:6379","123456"}
	pool,err:=tcp.NewConnPool(1,config)
	if err!=nil{
		fmt.Println(err)
	}

	conn,_:=tcp.GetConn(pool)
	fmt.Println(conn.RemoteAddr())
	sendResult := template.Set("name", "james", conn)
	fmt.Println("send result:" + sendResult)
	result := template.Get("name", conn)
	fmt.Println("get result:" + result)

	pool.PutConn(conn)

	conn1,_:=tcp.GetConn(pool)
	fmt.Println(conn1.RemoteAddr())
	sendResult1 := template.Set("name", "james", conn)
	fmt.Println("send result:" + sendResult1)
	result1 := template.Get("name", conn)
	fmt.Println("get result:" + result1)
	/*conn1,_:=tcp.GetConn(pool)
	fmt.Println(conn1.RemoteAddr())

	conn2,_:=tcp.GetConn(pool)
	fmt.Println(conn2.RemoteAddr())

	conn3,_:=tcp.GetConn(pool)
	fmt.Println(conn3.RemoteAddr())

	_, err = tcp.GetConn(pool)
	fmt.Println(err)

	size:=tcp.PoolSize(pool)
	fmt.Println("连接数",size)
	if size<1{
		pool.PutConn(conn3)
	}
	size1:=tcp.PoolSize(pool)
	fmt.Println("连接数",size1)

	conn4,_:=tcp.GetConn(pool)
	fmt.Println(conn4.RemoteAddr())*/
}

func testRedis(){
	conn := tcp.Connect("10.10.5.239:6379")
	authResult := template.Auth("123456", conn)
	fmt.Println("auth result:" + authResult)
	sendResult := template.Set("name", "james", conn)
	fmt.Println("send result:" + sendResult)
	result := template.Get("name", conn)
	fmt.Println("get result:" + result)
}

测试结果:

平民版go语言redis客户端第一阶段实现到此为止,后续会继续更新、完善。感兴趣的朋友们欢迎沟通交流、一起学习!

项目地址:

https://github.com/zhangxiaomin1993/gedis

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值