From 88d4a670d487a553edaa0e4c024dfddccde7d5b5 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Thu, 28 Apr 2022 18:23:55 +0800 Subject: [PATCH] cache --- pkg/common/db/redisModel.go | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/pkg/common/db/redisModel.go b/pkg/common/db/redisModel.go index a49df09d3..0241faa9f 100644 --- a/pkg/common/db/redisModel.go +++ b/pkg/common/db/redisModel.go @@ -182,12 +182,20 @@ func (d *DataBases) GetUserInfoFromCache(userID string) (*pbCommon.UserInfo, err } func (d *DataBases) AddFriendToCache(userID string, friendIDList ...string) error { - _, err := d.Exec("SADD", friendRelationCache+userID, redis.Args{}.Add().AddFlat(friendIDList)...) + var IDList []interface{} + for _, id := range friendIDList { + IDList = append(IDList, id) + } + _, err := d.Exec("SADD", friendRelationCache+userID, IDList...) return err } -func (d *DataBases) ReduceFriendToCache(userID string, friendIDList ...interface{}) error { - _, err := d.Exec("SREM", friendRelationCache+userID, redis.Args{}.Add().AddFlat(friendIDList)...) +func (d *DataBases) ReduceFriendToCache(userID string, friendIDList ...string) error { + var IDList []interface{} + for _, id := range friendIDList { + IDList = append(IDList, id) + } + _, err := d.Exec("SREM", friendRelationCache+userID, IDList...) return err } @@ -196,13 +204,21 @@ func (d *DataBases) GetFriendIDListFromCache(userID string) ([]string, error) { return result, err } -func (d *DataBases) AddBlackUserToCache(userID string, blackList ...interface{}) error { - _, err := d.Exec("SADD", blackListCache+userID, redis.Args{}.Add().AddFlat(blackList)...) +func (d *DataBases) AddBlackUserToCache(userID string, blackList ...string) error { + var IDList []interface{} + for _, id := range blackList { + IDList = append(IDList, id) + } + _, err := d.Exec("SADD", blackListCache+userID, IDList...) return err } -func (d *DataBases) ReduceBlackUserFromCache(userID string, blackList ...interface{}) error { - _, err := d.Exec("SREM", blackListCache+userID, redis.Args{}.Add().AddFlat(blackList)...) +func (d *DataBases) ReduceBlackUserFromCache(userID string, blackList ...string) error { + var IDList []interface{} + for _, id := range blackList { + IDList = append(IDList, id) + } + _, err := d.Exec("SREM", blackListCache+userID, IDList...) return err }