Get 获取互动信息
(ctx context.Context, postId uint)
| 59 | |
| 60 | // Get 获取互动信息 |
| 61 | func (i *interactiveCache) Get(ctx context.Context, postId uint) (domain.Interactive, error) { |
| 62 | key := fmt.Sprintf("interactive:%d", postId) |
| 63 | res, err := i.client.HGetAll(ctx, key).Result() |
| 64 | if err != nil { |
| 65 | return domain.Interactive{}, err |
| 66 | } |
| 67 | if len(res) == 0 { |
| 68 | return domain.Interactive{}, ErrKeyNotExist |
| 69 | } |
| 70 | var di domain.Interactive |
| 71 | di.CollectCount, _ = strconv.ParseInt(res[CollectCount], 10, 64) |
| 72 | di.LikeCount, _ = strconv.ParseInt(res[LikeCount], 10, 64) |
| 73 | di.ReadCount, _ = strconv.ParseInt(res[ReadCount], 10, 64) |
| 74 | return di, nil |
| 75 | } |
| 76 | |
| 77 | // Set 存储互动信息 |
| 78 | func (i *interactiveCache) Set(ctx context.Context, postId uint, res domain.Interactive) error { |
nothing calls this directly
no outgoing calls
no test coverage detected