mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
40 lines
763 B
Go
40 lines
763 B
Go
package v2
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/coreos/etcd/log"
|
|
"github.com/coreos/etcd/store"
|
|
"github.com/coreos/etcd/third_party/github.com/goraft/raft"
|
|
)
|
|
|
|
func init() {
|
|
raft.RegisterCommand(&UpdateCommand{})
|
|
}
|
|
|
|
// Update command
|
|
type UpdateCommand struct {
|
|
Key string `json:"key"`
|
|
Value string `json:"value"`
|
|
ExpireTime time.Time `json:"expireTime"`
|
|
}
|
|
|
|
// The name of the update command in the log
|
|
func (c *UpdateCommand) CommandName() string {
|
|
return "etcd:update"
|
|
}
|
|
|
|
// Create node
|
|
func (c *UpdateCommand) Apply(context raft.Context) (interface{}, error) {
|
|
s, _ := context.Server().StateMachine().(store.Store)
|
|
|
|
e, err := s.Update(c.Key, c.Value, c.ExpireTime)
|
|
|
|
if err != nil {
|
|
log.Debug(err)
|
|
return nil, err
|
|
}
|
|
|
|
return e, nil
|
|
}
|