添加redis方法

This commit is contained in:
lifeiyi
2020-04-21 18:09:42 +08:00
parent a189c2c80b
commit c06af0ab4f
3 changed files with 83 additions and 7 deletions

View File

@@ -6,9 +6,10 @@ import (
"github.com/duanhf2012/origin/network/processor"
"github.com/duanhf2012/origin/node"
"github.com/duanhf2012/origin/service"
"github.com/duanhf2012/origin/sysmodule"
"github.com/duanhf2012/origin/sysservice"
"github.com/duanhf2012/origin/util/timer"
"net/http"
"time"
)
type GateService struct {
@@ -16,6 +17,8 @@ type GateService struct {
processor *processor.PBProcessor
processor2 *processor.PBProcessor
httpRouter sysservice.IHttpRouter
redisModule *sysmodule.RedisModule
}
func (slf *GateService) OnInit() error{
@@ -42,8 +45,25 @@ func (slf *GateService) OnInit() error{
slf.httpRouter.POST("/post/query", slf.HttpTestPost)
slf.httpRouter.SetServeFile(sysservice.METHOD_GET,"/img/head/","d:/img")
pCronExpr,_ := timer.NewCronExpr("0 * * * * *")
slf.CronFunc(pCronExpr,slf.Test)
//pCronExpr,_ := timer.NewCronExpr("0 * * * * *")
//slf.CronFunc(pCronExpr,slf.Test)
redisCfg := sysmodule.ConfigRedis{
IP :"192.168.0.5",
Port :"6379",
Password :"",
DbIndex :0,
MaxIdle :50, //最大的空闲连接数表示即使没有redis连接时依然可以保持N个空闲的连接而不被清除随时处于待命状态。
MaxActive :50, //最大的激活连接数表示同时最多有N个连接
IdleTimeout :30, //最大的空闲连接等待时间,超过此时间后,空闲连接将被关闭
SyncRouterNum :10, //异步执行Router数量
}
slf.redisModule = &sysmodule.RedisModule{}
slf.redisModule.Init(&redisCfg)
slf.redisModule.OnInit()
slf.AddModule(slf.redisModule)
slf.AfterFunc(time.Second, slf.TestRedis)
return nil
}
@@ -52,6 +72,11 @@ func (slf *GateService) Test(){
fmt.Print("xxxxx\n")
}
func (slf *GateService) TestRedis() {
slf.redisModule.GetHashValueByHashKeyList("BITGET_2160_LastSetLevelInfo", "SBTC_USD_1", "BTC_SUSDT_1", "SBTC_USD_3")
//slf.redisModule.GetHashValueByKey("BITGET_2160_LastSetLevelInfo", "SBTC_USD_1")
}
func (slf *GateService) HttpTest(session *sysservice.HttpSession) {
session.SetHeader("a","b")
session.Write([]byte("this is a test"))