1
0

Change keyvalue.Get to return if a value exists or not instead of an error

This commit is contained in:
kolaente
2021-01-31 12:32:46 +01:00
parent fe72f30b24
commit 2e88600c93
9 changed files with 28 additions and 43 deletions

View File

@ -91,7 +91,7 @@ func SetUserActive(a web.Auth) (err error) {
// getActiveUsers returns the active users from redis
func getActiveUsers() (users activeUsersMap, err error) {
u, err := keyvalue.Get(ActiveUsersKey)
u, _, err := keyvalue.Get(ActiveUsersKey)
if err != nil {
return nil, err
}

View File

@ -20,7 +20,6 @@ import (
"code.vikunja.io/api/pkg/config"
"code.vikunja.io/api/pkg/log"
"code.vikunja.io/api/pkg/modules/keyvalue"
e "code.vikunja.io/api/pkg/modules/keyvalue/error"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
@ -97,13 +96,14 @@ func InitMetrics() {
// GetCount returns the current count from redis
func GetCount(key string) (count int64, err error) {
cnt, err := keyvalue.Get(key)
cnt, exists, err := keyvalue.Get(key)
if err != nil {
if e.IsErrValueNotFoundForKey(err) {
return 0, nil
}
return 0, err
}
if !exists {
return 0, nil
}
count = cnt.(int64)
return