2022-01-08 16:21:53 +00:00
|
|
|
package db
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
|
|
|
func StatsIncreaseViewsLinks() (int, error) {
|
2022-01-13 19:06:30 +00:00
|
|
|
val, err := Client.Get(ctx, "total-views").Result()
|
2022-01-08 16:21:53 +00:00
|
|
|
|
|
|
|
if err != nil {
|
2022-01-13 19:06:30 +00:00
|
|
|
err := Client.Set(ctx, "total-views", "0", 0).Err()
|
2022-01-08 16:21:53 +00:00
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
i, _ := strconv.Atoi(val)
|
|
|
|
i++
|
2022-01-13 19:06:30 +00:00
|
|
|
err = Client.Set(ctx, "total-views", i, 0).Err()
|
2022-01-08 16:21:53 +00:00
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
return i, nil
|
|
|
|
}
|