| 41 | } |
| 42 | |
| 43 | func NewPostCache(client redis.Cmdable) PostCache { |
| 44 | rand.Seed(time.Now().UnixNano()) // 初始化随机数种子 |
| 45 | return &postCache{ |
| 46 | client: client, |
| 47 | expiration: time.Minute * 30, // 基础过期时间30分钟 |
| 48 | prefix: "linkeme:post:", |
| 49 | emptyPrefix: "linkeme:post:empty:", |
| 50 | listPrefix: "linkeme:post:list:", |
| 51 | listPubPrefix: "linkeme:post:list:pub:", |
| 52 | pubPrefix: "linkeme:post:pub:", |
| 53 | lockPrefix: "linkeme:post:lock:", |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | // Get 获取帖子缓存 |
| 58 | func (c *postCache) Get(ctx context.Context, key string) (domain.Post, error) { |