niki/repository/redis/redis_otp/get_code.go

26 lines
537 B
Go
Raw Permalink Normal View History

package redisotp
import (
"context"
"errors"
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
"github.com/redis/go-redis/v9"
)
func (d DB) GetCodeByPhoneNumber(ctx context.Context, phoneNumber string) (string, error) {
const op = "redisotp.GetCodeByPhoneNumber"
value, err := d.adapter.Client().Get(ctx, phoneNumber).Result()
if err != nil {
rErr := redis.Nil
if errors.As(err, &rErr) {
return "", nil
}
return "", richerror.New(op).WithErr(err).WithKind(richerror.KindUnexpected)
}
return value, nil
}