diff --git a/pkg/common/db/redisModel.go b/pkg/common/db/redisModel.go index 3fb8c076a..a9d552699 100644 --- a/pkg/common/db/redisModel.go +++ b/pkg/common/db/redisModel.go @@ -109,7 +109,16 @@ func (d *DataBases) SetMultiConversationMsgOpt(userID string, m map[string]int) _, err := d.Exec("hmset", key, redis.Args{}.Add().AddFlat(m)...) return err } -func (d *DataBases) GetMultiConversationMsgOpt(userID string, conversationIDs []string) ([]int, error) { +func (d *DataBases) GetMultiConversationMsgOpt(userID string, conversationIDs []string) (m map[string]int, err error) { + m = make(map[string]int) key := conversationReceiveMessageOpt + userID - return redis.Ints(d.Exec("hmget", key, redis.Args{}.Add().AddFlat(conversationIDs)...)) + i, err := redis.Ints(d.Exec("hmget", key, redis.Args{}.Add().AddFlat(conversationIDs)...)) + if err != nil { + return m, err + } + for k, v := range conversationIDs { + m[v] = i[k] + } + return m, nil + } diff --git a/pkg/common/db/redisModel_test.go b/pkg/common/db/redisModel_test.go index 7da463a5b..1d9d254b7 100644 --- a/pkg/common/db/redisModel_test.go +++ b/pkg/common/db/redisModel_test.go @@ -19,3 +19,9 @@ func Test_GetTokenMapByUidPid(t *testing.T) { assert.Nil(t, err) fmt.Println(m) } + +func TestDataBases_GetMultiConversationMsgOpt(t *testing.T) { + m, err := DB.GetMultiConversationMsgOpt("fg", []string{"user", "age", "color"}) + assert.Nil(t, err) + fmt.Println(m) +}