SetCountCache 将审核记录的数量写入缓存
(ctx context.Context, key string, count int64, ttl time.Duration)
| 154 | |
| 155 | // SetCountCache 将审核记录的数量写入缓存 |
| 156 | func (c *checkCache) SetCountCache(ctx context.Context, key string, count int64, ttl time.Duration) error { |
| 157 | // 设置随机化的TTL,防止缓存雪崩 |
| 158 | randomTTL := ttl + time.Duration(randomInt(0, 300))*time.Second |
| 159 | |
| 160 | // 将计数数据写入Redis |
| 161 | return c.client.Set(ctx, key, count, randomTTL).Err() |
| 162 | } |
| 163 | |
| 164 | // GenerateCacheKey 生成单个审核记录的缓存键 |
| 165 | func (c *checkCache) GenerateCacheKey(id interface{}) string { |