Skip to content

Commit

Permalink
CR's fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeniy-scherbina committed Oct 11, 2023
1 parent 6546bd8 commit 90b88b9
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions clients/cache/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ func (rc *RedisCache) Set(
value []byte,
expiration time.Duration,
) error {
rc.Logger.Trace().Msgf("setting value in redis, key: %v, value: %v, expiration: %v", key, value, expiration)
rc.Logger.Trace().
Str("key", key).
Str("value", string(value)).
Dur("expiration", expiration).
Msg("setting value in redis")

return rc.client.Set(ctx, key, value, expiration).Err()
}
Expand All @@ -56,26 +60,38 @@ func (rc *RedisCache) Get(
ctx context.Context,
key string,
) ([]byte, error) {
rc.Logger.Trace().Msgf("getting value from redis, key: %v", key)
rc.Logger.Trace().
Str("key", key).
Msg("getting value from redis")

val, err := rc.client.Get(ctx, key).Bytes()
if err == redis.Nil {
rc.Logger.Trace().Msgf("value not found in redis, key: %v", key)
rc.Logger.Trace().
Str("key", key).
Msgf("value not found in redis")
return nil, ErrNotFound
}
if err != nil {
rc.Logger.Error().Msgf("error during getting value from redis, key: %v, err: %v", key, err)
rc.Logger.Error().
Str("key", key).
Err(err).
Msg("error during getting value from redis")
return nil, err
}

rc.Logger.Trace().Msgf("successfully got value from redis, key: %v, value: %v", key, val)
rc.Logger.Trace().
Str("key", key).
Str("value", string(val)).
Msg("successfully got value from redis")

return val, nil
}

// Delete deletes the value for the given key in the cache.
func (rc *RedisCache) Delete(ctx context.Context, key string) error {
rc.Logger.Trace().Msgf("deleting value from redis, key: %v", key)
rc.Logger.Trace().
Str("key", key).
Msg("deleting value from redis")

return rc.client.Del(ctx, key).Err()
}
Expand Down

0 comments on commit 90b88b9

Please sign in to comment.