Skip to content

Commit

Permalink
Handle redis.Nil error in GetVersion function
Browse files Browse the repository at this point in the history
Added error handling for redis.Nil error in GetVersion method in version.go. This change will return 0 and nil, for redis.Nil errors, to prevent unexpected behavior or application crashes.
  • Loading branch information
lueurxax committed May 3, 2024
1 parent 1ed0840 commit ce49de3
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/repo/redis/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package redis
import (
"context"
"encoding/binary"
"errors"

"github.com/redis/go-redis/v9"
)

type version interface {
Expand All @@ -20,6 +23,9 @@ func (d *db) WriteVersion(ctx context.Context, version uint32) error {
func (d *db) GetVersion(ctx context.Context) (uint32, error) {
data, err := d.db.Get(ctx, string(d.keyBuilder.Version())).Result()
if err != nil {
if errors.Is(err, redis.Nil) {
return 0, nil
}
return 0, err
}

Expand Down

0 comments on commit ce49de3

Please sign in to comment.