(ctx context.Context, key string, relations []domain.Relation, ttl time.Duration)
| 48 | } |
| 49 | |
| 50 | func (c *relationCache) SetCache(ctx context.Context, key string, relations []domain.Relation, ttl time.Duration) error { |
| 51 | // 编码数据为JSON格式 |
| 52 | data, err := json.Marshal(relations) |
| 53 | if err != nil { |
| 54 | return err |
| 55 | } |
| 56 | |
| 57 | // 设置缓存并设置过期时间 |
| 58 | return c.client.Set(ctx, key, data, ttl).Err() |
| 59 | } |
| 60 | |
| 61 | func (c *relationCache) GetCountCache(ctx context.Context, key string) (int64, error) { |
| 62 | count, err := c.client.Get(ctx, key).Int64() |