goshorly/db/AddViews.go

24 lines
407 B
Go
Raw Normal View History

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