Commit 8c36debc authored by hujiebin's avatar hujiebin

Merge branch 'feature/group_room_living' into 'master'

Feature/group room living

See merge request !35
parents 484f4349 e3fb3ad7
...@@ -4,7 +4,6 @@ import ( ...@@ -4,7 +4,6 @@ import (
"git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/mylogrus" "git.hilo.cn/hilo-common/mylogrus"
"git.hilo.cn/hilo-common/resource/mysql" "git.hilo.cn/hilo-common/resource/mysql"
"git.hilo.cn/hilo-common/resource/redisCli"
"hilo-user/_const/redis_key/group_k" "hilo-user/_const/redis_key/group_k"
"hilo-user/myerr" "hilo-user/myerr"
"strconv" "strconv"
...@@ -26,7 +25,7 @@ func RoomLivingUserIdFilter(model *domain.Model, userIds []mysql.ID) (map[mysql. ...@@ -26,7 +25,7 @@ func RoomLivingUserIdFilter(model *domain.Model, userIds []mysql.ID) (map[mysql.
return nil, myerr.WrapErr(err) return nil, myerr.WrapErr(err)
} }
groupUserIdstrs, err := redisCli.GetRedis().ZRange(model, key, 0, -1).Result() groupUserIdstrs, err := model.RedisCluster.ZRange(model, key, 0, -1).Result()
if err != nil { if err != nil {
return nil, myerr.WrapErr(err) return nil, myerr.WrapErr(err)
} }
...@@ -34,7 +33,6 @@ func RoomLivingUserIdFilter(model *domain.Model, userIds []mysql.ID) (map[mysql. ...@@ -34,7 +33,6 @@ func RoomLivingUserIdFilter(model *domain.Model, userIds []mysql.ID) (map[mysql.
resultUserSet := map[mysql.ID]string{} resultUserSet := map[mysql.ID]string{}
for i, _ := range groupUserIdstrs { for i, _ := range groupUserIdstrs {
tempGroupUid, userId := analysisMemberStr(groupUserIdstrs[i]) tempGroupUid, userId := analysisMemberStr(groupUserIdstrs[i])
mylogrus.MyLog.Debugf("RoomLivingUserIdFilter, analysisMemberStr %s, %d", tempGroupUid, userId)
if _, flag := userIdSet[userId]; flag { if _, flag := userIdSet[userId]; flag {
resultUserSet[userId] = tempGroupUid resultUserSet[userId] = tempGroupUid
...@@ -44,7 +42,7 @@ func RoomLivingUserIdFilter(model *domain.Model, userIds []mysql.ID) (map[mysql. ...@@ -44,7 +42,7 @@ func RoomLivingUserIdFilter(model *domain.Model, userIds []mysql.ID) (map[mysql.
} }
func ClearExpired(model *domain.Model, key string, expireSec int64) error { func ClearExpired(model *domain.Model, key string, expireSec int64) error {
return model.Redis.ZRemRangeByScore(model, key, return model.RedisCluster.ZRemRangeByScore(model, key,
"0", strconv.FormatInt(time.Now().Unix()-expireSec, 10)).Err() "0", strconv.FormatInt(time.Now().Unix()-expireSec, 10)).Err()
} }
......
...@@ -5,9 +5,11 @@ import ( ...@@ -5,9 +5,11 @@ import (
"git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/mycontext" "git.hilo.cn/hilo-common/mycontext"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/go-redis/redis/v8"
ginSwagger "github.com/swaggo/gin-swagger" ginSwagger "github.com/swaggo/gin-swagger"
"github.com/swaggo/gin-swagger/swaggerFiles" "github.com/swaggo/gin-swagger/swaggerFiles"
"hilo-user/_const/enum/msg_e" "hilo-user/_const/enum/msg_e"
"hilo-user/_const/redis_key/group_k"
_ "hilo-user/docs" _ "hilo-user/docs"
"hilo-user/domain/model/msg_m" "hilo-user/domain/model/msg_m"
"hilo-user/resp" "hilo-user/resp"
...@@ -88,6 +90,7 @@ func InitRouter() *gin.Engine { ...@@ -88,6 +90,7 @@ func InitRouter() *gin.Engine {
innerProp.POST("/ride/send", wrapper(user_r.SendUserRide)) // 下发座驾 innerProp.POST("/ride/send", wrapper(user_r.SendUserRide)) // 下发座驾
} }
r.GET("/test", wrapper(Test)) r.GET("/test", wrapper(Test))
r.GET("/sync/group_room_living", wrapper(SyncGroupRoomLiving))
return r return r
} }
...@@ -103,3 +106,24 @@ func Test(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -103,3 +106,24 @@ func Test(c *gin.Context) (*mycontext.MyContext, error) {
resp.ResponseOk(c, struct{}{}) resp.ResponseOk(c, struct{}{})
return myCtx, nil return myCtx, nil
} }
func SyncGroupRoomLiving(c *gin.Context) (*mycontext.MyContext, error) {
myCtx := mycontext.CreateMyContext(c.Keys)
var model = domain.CreateModelContext(myCtx)
key := group_k.GetPrefixGroupRoomLiving()
res, err := model.Redis.ZRangeWithScores(model, key, 0, -1).Result()
if err != nil {
return myCtx, err
}
for _, v := range res {
err := model.RedisCluster.ZAdd(model, key, &redis.Z{
Score: v.Score,
Member: v.Member,
}).Err()
if err != nil {
return myCtx, err
}
}
resp.ResponseOk(c, struct{}{})
return myCtx, nil
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment