light-pkg/myRedis/OperationAttr.go

53 lines
786 B
Go
Raw Permalink Normal View History

2024-12-18 03:41:30 +08:00
package myRedis
import (
"fmt"
"time"
)
const (
AttrExpr = "expr"
AttrNx = "nx"
AttrXx = "xx"
)
type empty struct {
}
type OperationAttr struct {
Name string
Value interface{}
}
type OperationAttrs []*OperationAttr
func (t OperationAttrs) Find(name string) *InterfaceResult {
for _, attr := range t {
if attr.Name == name {
return NewInterfaceResult(attr.Value, nil)
}
}
return NewInterfaceResult(nil, fmt.Errorf("OperationAttrs found error:%s", name))
}
func WithExpire(t time.Duration) *OperationAttr {
return &OperationAttr{
Name: AttrExpr,
Value: t,
}
}
func WithNX() *OperationAttr {
return &OperationAttr{
Name: AttrNx,
Value: empty{},
}
}
func WithXX() *OperationAttr {
return &OperationAttr{
Name: AttrXx,
Value: empty{},
}
}