You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
503 B
26 lines
503 B
4 years ago
|
package data
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"fmt"
|
||
|
"github.com/go-redis/redis/v8"
|
||
|
)
|
||
|
|
||
|
func likeKey(id int64) string {
|
||
|
return fmt.Sprintf("like:%d", id)
|
||
|
}
|
||
|
|
||
|
func (ar *articleRepo) GetArticleLike(ctx context.Context, id int64) (rv int64, err error) {
|
||
|
get := ar.data.rdb.Get(ctx, likeKey(id))
|
||
|
rv, err = get.Int64()
|
||
|
if err == redis.Nil {
|
||
|
return 0, nil
|
||
|
}
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func (ar *articleRepo) IncArticleLike(ctx context.Context, id int64) error {
|
||
|
_, err := ar.data.rdb.Incr(ctx, likeKey(id)).Result()
|
||
|
return err
|
||
|
}
|