mirror of
https://github.com/duanhf2012/origin.git
synced 2026-03-02 19:37:36 +08:00
添加redis方法
This commit is contained in:
@@ -6,9 +6,10 @@ import (
|
|||||||
"github.com/duanhf2012/origin/network/processor"
|
"github.com/duanhf2012/origin/network/processor"
|
||||||
"github.com/duanhf2012/origin/node"
|
"github.com/duanhf2012/origin/node"
|
||||||
"github.com/duanhf2012/origin/service"
|
"github.com/duanhf2012/origin/service"
|
||||||
|
"github.com/duanhf2012/origin/sysmodule"
|
||||||
"github.com/duanhf2012/origin/sysservice"
|
"github.com/duanhf2012/origin/sysservice"
|
||||||
"github.com/duanhf2012/origin/util/timer"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GateService struct {
|
type GateService struct {
|
||||||
@@ -16,6 +17,8 @@ type GateService struct {
|
|||||||
processor *processor.PBProcessor
|
processor *processor.PBProcessor
|
||||||
processor2 *processor.PBProcessor
|
processor2 *processor.PBProcessor
|
||||||
httpRouter sysservice.IHttpRouter
|
httpRouter sysservice.IHttpRouter
|
||||||
|
|
||||||
|
redisModule *sysmodule.RedisModule
|
||||||
}
|
}
|
||||||
|
|
||||||
func (slf *GateService) OnInit() error{
|
func (slf *GateService) OnInit() error{
|
||||||
@@ -42,8 +45,25 @@ func (slf *GateService) OnInit() error{
|
|||||||
slf.httpRouter.POST("/post/query", slf.HttpTestPost)
|
slf.httpRouter.POST("/post/query", slf.HttpTestPost)
|
||||||
slf.httpRouter.SetServeFile(sysservice.METHOD_GET,"/img/head/","d:/img")
|
slf.httpRouter.SetServeFile(sysservice.METHOD_GET,"/img/head/","d:/img")
|
||||||
|
|
||||||
pCronExpr,_ := timer.NewCronExpr("0 * * * * *")
|
//pCronExpr,_ := timer.NewCronExpr("0 * * * * *")
|
||||||
slf.CronFunc(pCronExpr,slf.Test)
|
//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
|
return nil
|
||||||
}
|
}
|
||||||
@@ -52,6 +72,11 @@ func (slf *GateService) Test(){
|
|||||||
fmt.Print("xxxxx\n")
|
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) {
|
func (slf *GateService) HttpTest(session *sysservice.HttpSession) {
|
||||||
session.SetHeader("a","b")
|
session.SetHeader("a","b")
|
||||||
session.Write([]byte("this is a test"))
|
session.Write([]byte("this is a test"))
|
||||||
|
|||||||
@@ -4,13 +4,13 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/duanhf2012/origin/event"
|
"github.com/duanhf2012/origin/event"
|
||||||
"github.com/duanhf2012/origin/example/GateService"
|
"github.com/duanhf2012/origin/example/GateService"
|
||||||
"github.com/duanhf2012/origin/example/msgpb"
|
//"github.com/duanhf2012/origin/example/msgpb"
|
||||||
"github.com/duanhf2012/origin/log"
|
"github.com/duanhf2012/origin/log"
|
||||||
"github.com/duanhf2012/origin/node"
|
"github.com/duanhf2012/origin/node"
|
||||||
"github.com/duanhf2012/origin/service"
|
"github.com/duanhf2012/origin/service"
|
||||||
"github.com/duanhf2012/origin/sysmodule"
|
"github.com/duanhf2012/origin/sysmodule"
|
||||||
"github.com/duanhf2012/origin/sysservice"
|
"github.com/duanhf2012/origin/sysservice"
|
||||||
"github.com/golang/protobuf/proto"
|
//"github.com/golang/protobuf/proto"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -249,12 +249,12 @@ func (slf *TestService1) RPC_Test(a *Param,b *Param) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (slf *TestService1) RPC_TestPB(a *msgpb.InputRpc,b *msgpb.OutputRpc) error {
|
/*func (slf *TestService1) RPC_TestPB(a *msgpb.InputRpc,b *msgpb.OutputRpc) error {
|
||||||
b.Msg = proto.String(a.GetMsg())
|
b.Msg = proto.String(a.GetMsg())
|
||||||
b.Tag = proto.Int32(a.GetTag())
|
b.Tag = proto.Int32(a.GetTag())
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
func (slf *TestService1) OnInit() error {
|
func (slf *TestService1) OnInit() error {
|
||||||
|
|||||||
@@ -725,6 +725,57 @@ func (slf *RedisModule) GetHashValueByKey(redisKey string, fieldKey string) (str
|
|||||||
return string(str), nil
|
return string(str), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//GetHashValueByHashKeyList ...
|
||||||
|
func (slf *RedisModule) GetHashValueByHashKeyList(fieldKey ...interface{}) ([]string, error) {
|
||||||
|
if len(fieldKey) < 2 {
|
||||||
|
log.Error("GetHashValueByHashKeyList key len less than two!")
|
||||||
|
return nil, errors.New("Key Is Empty")
|
||||||
|
}
|
||||||
|
conn, err := slf.getConn()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
value, err := conn.Do("HMGET", fieldKey...)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("GetHashValueByKey fail,reason:%v", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if value == nil {
|
||||||
|
return nil, errors.New("Reids Get Hash nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
valueList := value.([]interface{})
|
||||||
|
retList := []string{}
|
||||||
|
for _, valueItem := range valueList{
|
||||||
|
valueByte, ok := valueItem.([]byte)
|
||||||
|
if !ok {
|
||||||
|
retList = append(retList, "")
|
||||||
|
} else {
|
||||||
|
retList = append(retList, string(valueByte))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return retList, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
/*func (slf *RedisModule) ScanMatchKeys(cursorValue int, redisKey string, count int) ([]string, error) {
|
||||||
|
retKeys := []string{}
|
||||||
|
if redisKey == "" {
|
||||||
|
log.Error("ScanMatchKeys key is empty!")
|
||||||
|
return nil, errors.New("Key Is Empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
conn, err := slf.getConn()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
return retKeys, nil
|
||||||
|
}*/
|
||||||
|
|
||||||
//SetRedisHashJSON ...
|
//SetRedisHashJSON ...
|
||||||
func (slf *RedisModule) SetHashJSON(redisKey, hsahKey string, value interface{}) error {
|
func (slf *RedisModule) SetHashJSON(redisKey, hsahKey string, value interface{}) error {
|
||||||
temp, err := json.Marshal(value)
|
temp, err := json.Marshal(value)
|
||||||
|
|||||||
Reference in New Issue
Block a user