From 604ed3e3e1991ca9ee9d09198675f980479de523 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Thu, 28 Apr 2022 16:19:51 +0800 Subject: [PATCH] cache --- pkg/common/db/redisModel.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/pkg/common/db/redisModel.go b/pkg/common/db/redisModel.go index 4510464c7..8b3cdb4c7 100644 --- a/pkg/common/db/redisModel.go +++ b/pkg/common/db/redisModel.go @@ -6,6 +6,7 @@ import ( pbCommon "Open_IM/pkg/proto/sdk_ws" "encoding/json" "github.com/garyburd/redigo/redis" + "strings" ) const ( @@ -182,31 +183,31 @@ func (d *DataBases) GetUserInfoFromCache(userID string) (*pbCommon.UserInfo, err } func (d *DataBases) AddFriendToCache(userID string, friendIDList ...interface{}) error { - _, err := redis.String(d.Exec("SADD", friendRelationCache+userID, friendIDList...)) + _, err := d.Exec("SADD", friendRelationCache+userID, friendIDList...) return err } func (d *DataBases) ReduceFriendToCache(userID string, friendIDList ...interface{}) error { - _, err := redis.String(d.Exec("SREM", friendRelationCache+userID, friendIDList...)) + _, err := d.Exec("SREM", friendRelationCache+userID, friendIDList...) return err } func (d *DataBases) GetFriendIDListFromCache(userID string) ([]string, error) { - result, err := redis.Strings(d.Exec("SMEMBERS", friendRelationCache+userID)) - return result, err + result, err := redis.String(d.Exec("SMEMBERS", friendRelationCache+userID)) + return strings.Split(result, " "), err } func (d *DataBases) AddBlackUserToCache(userID string, blackList ...interface{}) error { - _, err := redis.String(d.Exec("SADD", blackListCache+userID, blackList...)) + _, err := d.Exec("SADD", blackListCache+userID, blackList...) return err } func (d *DataBases) ReduceBlackUserFromCache(userID string, blackList ...interface{}) error { - _, err := redis.String(d.Exec("SREM", blackListCache+userID, blackList...)) + _, err := d.Exec("SREM", blackListCache+userID, blackList...) return err } func (d *DataBases) GetBlackListFromCache(userID string) ([]string, error) { - result, err := redis.Strings(d.Exec("SMEMBERS", blackListCache+userID)) - return result, err + result, err := redis.String(d.Exec("SMEMBERS", blackListCache+userID)) + return strings.Split(result, " "), err }