Skip to content

Commit

Permalink
fix: not support redis cluster. CROSSSLOT Keys in request don't hash …
Browse files Browse the repository at this point in the history
…to the same slot
  • Loading branch information
withchao committed Oct 24, 2023
1 parent c08b95f commit e9a6973
Show file tree
Hide file tree
Showing 7 changed files with 721 additions and 782 deletions.
21 changes: 6 additions & 15 deletions pkg/common/db/cache/black.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func NewBlackCacheRedis(
options rockscache.Options,
) BlackCache {
rcClient := rockscache.NewClient(rdb, options)

return &BlackCacheRedis{
expireTime: blackExpireTime,
rcClient: rcClient,
Expand All @@ -61,32 +62,22 @@ func NewBlackCacheRedis(
}

func (b *BlackCacheRedis) NewCache() BlackCache {
return &BlackCacheRedis{
expireTime: b.expireTime,
rcClient: b.rcClient,
blackDB: b.blackDB,
metaCache: NewMetaCacheRedis(b.rcClient, b.metaCache.GetPreDelKeys()...),
}
return &BlackCacheRedis{expireTime: b.expireTime, rcClient: b.rcClient, blackDB: b.blackDB, metaCache: NewMetaCacheRedis(b.rcClient, b.metaCache.GetPreDelKeys()...)}
}

func (b *BlackCacheRedis) getBlackIDsKey(ownerUserID string) string {
return blackIDsKey + ownerUserID
}

func (b *BlackCacheRedis) GetBlackIDs(ctx context.Context, userID string) (blackIDs []string, err error) {
return getCache(
ctx,
b.rcClient,
b.getBlackIDsKey(userID),
b.expireTime,
func(ctx context.Context) ([]string, error) {
return b.blackDB.FindBlackUserIDs(ctx, userID)
},
)
return getCache(ctx, b.rcClient, b.getBlackIDsKey(userID), b.expireTime, func(ctx context.Context) ([]string, error) {
return b.blackDB.FindBlackUserIDs(ctx, userID)
})
}

func (b *BlackCacheRedis) DelBlackIDs(ctx context.Context, userID string) BlackCache {
cache := b.NewCache()
cache.AddKeys(b.getBlackIDsKey(userID))

return cache
}
Loading

0 comments on commit e9a6973

Please sign in to comment.