Merge branch 'dev' of http://git.legu.cc/liwei_3d/go_dreamfactory into dev
This commit is contained in:
commit
ea86522c75
@ -124,3 +124,27 @@ func (this *configureComp) GetChannelRecordMax() (max int32, err error) {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//获取手动加入频道 任务限制
|
||||||
|
func (this *configureComp) GetChannelReadRecordNum() (max int32, err error) {
|
||||||
|
var (
|
||||||
|
v interface{}
|
||||||
|
configure *cfg.Game_chatChannelComData
|
||||||
|
ok bool
|
||||||
|
)
|
||||||
|
if v, err = this.GetConfigure(game_chatchannelcom); err != nil {
|
||||||
|
this.module.Errorf("err:%v", err)
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
if configure, ok = v.(*cfg.Game_chatChannelCom).GetDataMap()["load_chat"]; !ok {
|
||||||
|
err = fmt.Errorf("cfg.Game_chatServerGroupData on found max_chat")
|
||||||
|
this.module.Errorf("err:%v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
max = configure.Value
|
||||||
|
if max <= 0 {
|
||||||
|
err = fmt.Errorf("cfg.Game_chatChannelComData max_chat:%v", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
@ -65,12 +65,13 @@ func (this *modelChatComp) QueryUserMsg(uid string) (result []*pb.DBChat, err er
|
|||||||
//查询用户未读消息
|
//查询用户未读消息
|
||||||
func (this *modelChatComp) GetChatQueue(channel pb.ChatChannel, union, group, area int32) (result []*pb.DBChat, err error) {
|
func (this *modelChatComp) GetChatQueue(channel pb.ChatChannel, union, group, area int32) (result []*pb.DBChat, err error) {
|
||||||
var (
|
var (
|
||||||
key string
|
key string
|
||||||
cdata []map[string]string
|
cdata []map[string]string
|
||||||
find bson.M
|
find bson.M
|
||||||
c *mongo.Cursor
|
c *mongo.Cursor
|
||||||
n int
|
n int
|
||||||
max_chat int32
|
max_chat int32
|
||||||
|
readmax_chat int32
|
||||||
)
|
)
|
||||||
switch channel {
|
switch channel {
|
||||||
case pb.ChatChannel_World:
|
case pb.ChatChannel_World:
|
||||||
@ -90,7 +91,13 @@ func (this *modelChatComp) GetChatQueue(channel pb.ChatChannel, union, group, ar
|
|||||||
find = bson.M{"channel": channel}
|
find = bson.M{"channel": channel}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if cdata, err = this.Batchgetqueues(key); err == nil {
|
if max_chat, err = this.module.configure.GetChannelRecordMax(); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if readmax_chat, err = this.module.configure.GetChannelReadRecordNum(); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if cdata, err = this.Batchgetqueues(key, readmax_chat); err == nil {
|
||||||
result = make([]*pb.DBChat, len(cdata))
|
result = make([]*pb.DBChat, len(cdata))
|
||||||
for i, v := range cdata {
|
for i, v := range cdata {
|
||||||
chat := &pb.DBChat{}
|
chat := &pb.DBChat{}
|
||||||
@ -100,7 +107,6 @@ func (this *modelChatComp) GetChatQueue(channel pb.ChatChannel, union, group, ar
|
|||||||
result[i] = chat
|
result[i] = chat
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
max_chat, err = this.module.configure.GetChannelRecordMax()
|
|
||||||
|
|
||||||
if err == redis.RedisNil {
|
if err == redis.RedisNil {
|
||||||
//query from mgo
|
//query from mgo
|
||||||
|
@ -74,7 +74,8 @@ return "OK"
|
|||||||
//Redis 自定义脚本 批量读取队列数据
|
//Redis 自定义脚本 批量读取队列数据
|
||||||
var LuaScriptgetQueue = `
|
var LuaScriptgetQueue = `
|
||||||
local key = tostring(KEYS[1])
|
local key = tostring(KEYS[1])
|
||||||
local keys = redis.call("LRANGE", key,0,-1)
|
local count = tonumber(ARGV[1]) * -1
|
||||||
|
local keys = redis.call("LRANGE", key,count,-1)
|
||||||
local data = {}
|
local data = {}
|
||||||
for i, v in ipairs(keys) do
|
for i, v in ipairs(keys) do
|
||||||
data[i] = redis.call("HGETALL", v)
|
data[i] = redis.call("HGETALL", v)
|
||||||
@ -121,6 +122,7 @@ for i, v in ipairs(KEYS) do
|
|||||||
end
|
end
|
||||||
redis.call("RPush", k,unpack(keys))
|
redis.call("RPush", k,unpack(keys))
|
||||||
local c = tonumber(redis.call("LLEN", k))
|
local c = tonumber(redis.call("LLEN", k))
|
||||||
|
count = count * 3
|
||||||
if (c > count) then
|
if (c > count) then
|
||||||
local off = c-count
|
local off = c-count
|
||||||
out = redis.call("LRANGE", k,0,off-1)
|
out = redis.call("LRANGE", k,0,off-1)
|
||||||
@ -349,7 +351,7 @@ func (this *MCompModel) ChangeList(uid string, _id string, data map[string]inter
|
|||||||
}
|
}
|
||||||
|
|
||||||
//读取全部数据
|
//读取全部数据
|
||||||
func (this *MCompModel) Get(uid string, data interface{}) (err error) {
|
func (this *MCompModel) Get(uid string, data interface{}, opt ...DBOption) (err error) {
|
||||||
if err = this.Redis.HGetAll(this.ukey(uid), data); err != nil && err != redis.RedisNil {
|
if err = this.Redis.HGetAll(this.ukey(uid), data); err != nil && err != redis.RedisNil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -359,6 +361,10 @@ func (this *MCompModel) Get(uid string, data interface{}) (err error) {
|
|||||||
}
|
}
|
||||||
err = this.Redis.HMSet(this.ukey(uid), data)
|
err = this.Redis.HMSet(this.ukey(uid), data)
|
||||||
}
|
}
|
||||||
|
option := newDBOption(opt...)
|
||||||
|
if option.Expire > 0 {
|
||||||
|
this.Redis.Expire(this.ukey(uid), option.Expire)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -599,9 +605,9 @@ func (this *MCompModel) Batchsetlists(data map[string]map[string]string) (err er
|
|||||||
}
|
}
|
||||||
|
|
||||||
//批量读取队列数据
|
//批量读取队列数据
|
||||||
func (this *MCompModel) Batchgetqueues(key string) (result []map[string]string, err error) {
|
func (this *MCompModel) Batchgetqueues(key string, count int32) (result []map[string]string, err error) {
|
||||||
var data interface{}
|
var data interface{}
|
||||||
ret := this.Redis.EvalSha(this.Redis.Context(), this.getQueueSha1, []string{key})
|
ret := this.Redis.EvalSha(this.Redis.Context(), this.getQueueSha1, []string{key}, count)
|
||||||
if data, err = ret.Result(); err != nil {
|
if data, err = ret.Result(); err != nil {
|
||||||
fmt.Printf("Execute batchgetqueues err: %v", err.Error())
|
fmt.Printf("Execute batchgetqueues err: %v", err.Error())
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user