goshorly/db/AddViews.go
2022-01-25 19:14:09 +01:00

23 lines
407 B
Go

package db
import (
"strconv"
)
func StatsIncreaseViewsLinks() (int, error) {
val, err := Client_redis().Get(ctx, "total-views").Result()
if err != nil {
err := Client_redis().Set(ctx, "total-views", "0", 0).Err()
if err != nil {
return 0, err
}
}
i, _ := strconv.Atoi(val)
i++
err = Client_redis().Set(ctx, "total-views", i, 0).Err()
if err != nil {
return 0, err
}
return i, nil
}