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
Signed by untrusted user who does not match committer: konrad
GPG key ID: F40E70337AB24C9B
9 changed files with 28 additions and 43 deletions

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