Skip to content

Commit

Permalink
修复一个不正常报错的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
rroy233 committed Nov 12, 2023
1 parent 93a588e commit 7932327
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion db/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,15 @@ func FindStickerCacheItem(uniqueID string) (*StickerItem, error) {
return item, nil
}

func parseIntoCacheItem(redisData string) (*StickerItem, error) {
item := new(StickerItem)
err := json.Unmarshal([]byte(redisData), item)
if err != nil {
return nil, CacheErrorNotExist
}
return item, nil
}

// ClearCache 清除缓存
// 返回string为结果描述
func ClearCache() (string, error) {
Expand Down Expand Up @@ -235,7 +244,8 @@ func CacheSticker(sticker tgbotapi.Sticker, convertedFilePath string) (*StickerI
}
data := rdb.Get(ctx, fmt.Sprintf("%s:Sticker_Cache:%s", ServicePrefix, utils.MD5Short(sticker.FileUniqueID))).Val()
if data != "" {
return nil, errors.New("failed to save")
//cache已存在
return parseIntoCacheItem(data)
}

item := new(StickerItem)
Expand Down

0 comments on commit 7932327

Please sign in to comment.