nurse/protocols/redis/get.go

54 lines
1.1 KiB
Go
Raw Normal View History

2022-04-28 16:35:02 +00:00
package redis
import (
"context"
"github.com/go-redis/redis/v8"
"code.1533b4dc0.de/prskr/nurse/check"
"code.1533b4dc0.de/prskr/nurse/config"
"code.1533b4dc0.de/prskr/nurse/grammar"
"code.1533b4dc0.de/prskr/nurse/validation"
2022-04-28 16:35:02 +00:00
)
var _ check.SystemChecker = (*GetCheck)(nil)
2022-04-28 16:35:02 +00:00
type GetCheck struct {
redis.UniversalClient
2022-06-09 20:12:45 +00:00
validators validation.Validator[redis.Cmder]
2022-04-28 16:35:02 +00:00
Key string
}
func (g *GetCheck) Execute(ctx context.Context) error {
2022-04-28 16:35:02 +00:00
cmd := g.Get(ctx, g.Key)
if err := cmd.Err(); err != nil {
return err
}
return g.validators.Validate(cmd)
}
func (g *GetCheck) UnmarshalCheck(c grammar.Check, lookup config.ServerLookup) error {
2022-04-28 16:35:02 +00:00
const serverAndKeyArgsNumber = 2
inst := c.Initiator
if err := grammar.ValidateParameterCount(inst.Params, serverAndKeyArgsNumber); err != nil {
return err
}
var err error
if g.UniversalClient, err = clientFromParam(inst.Params[0], lookup); err != nil {
2022-04-28 16:35:02 +00:00
return err
}
if g.Key, err = inst.Params[1].AsString(); err != nil {
return err
}
2022-06-09 20:12:45 +00:00
if g.validators, err = registry.ValidatorsForFilters(c.Validators); err != nil {
return err
}
2022-04-28 16:35:02 +00:00
return nil
}