You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
595 B
36 lines
595 B
package v20210726
|
|
|
|
import "time"
|
|
|
|
type empty struct{}
|
|
|
|
const (
|
|
AttrExpr = "expr" //过期时间
|
|
AttrNx = "nx" // setNx
|
|
)
|
|
|
|
type OperationAttr struct {
|
|
Name string
|
|
Value interface{}
|
|
}
|
|
|
|
type OperationAttrs []*OperationAttr
|
|
|
|
func (a OperationAttrs) Find(name string) interface{} {
|
|
for _, attr := range a {
|
|
if attr.Name == name {
|
|
return attr.Value
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// WithExpire 过期时间
|
|
func WithExpire(t time.Duration) *OperationAttr {
|
|
return &OperationAttr{Name: AttrExpr, Value: t}
|
|
}
|
|
|
|
func WithNX() *OperationAttr {
|
|
return &OperationAttr{Name: AttrNx, Value: empty{}}
|
|
}
|