@@ -26,6 +26,7 @@ import (
26
26
"github.com/croessner/nauthilus/server/global"
27
27
"github.com/croessner/nauthilus/server/log"
28
28
"github.com/croessner/nauthilus/server/rediscli"
29
+ "github.com/croessner/nauthilus/server/stats"
29
30
"github.com/croessner/nauthilus/server/util"
30
31
"github.com/go-kit/log/level"
31
32
"github.com/redis/go-redis/v9"
@@ -61,6 +62,8 @@ type RedisCache interface {
61
62
func LookupUserAccountFromRedis (ctx context.Context , username string ) (accountName string , err error ) {
62
63
key := config .LoadableConfig .Server .Redis .Prefix + global .RedisUserHashKey
63
64
65
+ defer stats .RedisReadCounter .Inc ()
66
+
64
67
accountName , err = rediscli .ReadHandle .HGet (ctx , key , username ).Result ()
65
68
if err != nil {
66
69
if ! errors .Is (err , redis .Nil ) {
@@ -81,6 +84,8 @@ func LookupUserAccountFromRedis(ctx context.Context, username string) (accountNa
81
84
func LoadCacheFromRedis [T RedisCache ](ctx context.Context , key string , cache * * T ) (isRedisErr bool , err error ) {
82
85
var redisValue []byte
83
86
87
+ defer stats .RedisReadCounter .Inc ()
88
+
84
89
if redisValue , err = rediscli .ReadHandle .Get (ctx , key ).Bytes (); err != nil {
85
90
if errors .Is (err , redis .Nil ) {
86
91
return true , nil
@@ -108,7 +113,7 @@ func LoadCacheFromRedis[T RedisCache](ctx context.Context, key string, cache **T
108
113
109
114
// SaveUserDataToRedis is a generic routine to store a cache object on Redis. The type is a RedisCache, which is a
110
115
// union.
111
- func SaveUserDataToRedis [T RedisCache ](ctx context.Context , guid string , key string , ttl uint , cache * T ) error {
116
+ func SaveUserDataToRedis [T RedisCache ](ctx context.Context , guid string , key string , ttl uint , cache * T ) {
112
117
var result string
113
118
114
119
util .DebugModule (
@@ -124,9 +129,11 @@ func SaveUserDataToRedis[T RedisCache](ctx context.Context, guid string, key str
124
129
global .LogKeyMsg , err ,
125
130
)
126
131
127
- return err
132
+ return
128
133
}
129
134
135
+ defer stats .RedisWriteCounter .Inc ()
136
+
130
137
//nolint:lll // Ignore
131
138
if result , err = rediscli .WriteHandle .Set (ctx , key , redisValue , time .Duration (ttl )* time .Second ).Result (); err != nil {
132
139
level .Error (log .Logger ).Log (
@@ -140,7 +147,7 @@ func SaveUserDataToRedis[T RedisCache](ctx context.Context, guid string, key str
140
147
global .LogKeyGUID , guid ,
141
148
"redis" , result )
142
149
143
- return err
150
+ return
144
151
}
145
152
146
153
// GetCacheNames returns the set of cache names for the requested protocol and cache backends.
@@ -207,6 +214,8 @@ func GetWebAuthnFromRedis(ctx context.Context, uniqueUserId string) (user *User,
207
214
208
215
key := "as_webauthn:user:" + uniqueUserId
209
216
217
+ defer stats .RedisReadCounter .Inc ()
218
+
210
219
if redisValue , err = rediscli .ReadHandle .Get (ctx , key ).Bytes (); err != nil {
211
220
level .Error (log .Logger ).Log (global .LogKeyMsg , err )
212
221
@@ -241,6 +250,8 @@ func SaveWebAuthnToRedis(ctx context.Context, user *User, ttl uint) error {
241
250
242
251
key := "as_webauthn:user:" + user .Id
243
252
253
+ defer stats .RedisWriteCounter .Inc ()
254
+
244
255
//nolint:lll // Ignore
245
256
if result , err = rediscli .WriteHandle .Set (ctx , key , redisValue , time .Duration (ttl )* time .Second ).Result (); err != nil {
246
257
level .Error (log .Logger ).Log (global .LogKeyMsg , err )
0 commit comments