update_command.go 750 B

1234567891011121314151617181920212223242526272829303132333435
  1. package command
  2. import (
  3. "time"
  4. "github.com/coreos/etcd/log"
  5. "github.com/coreos/etcd/store"
  6. "github.com/coreos/go-raft"
  7. )
  8. // The UpdateCommand updates the value of a key in the Store.
  9. type UpdateCommand struct {
  10. Key string `json:"key"`
  11. Value string `json:"value"`
  12. ExpireTime time.Time `json:"expireTime"`
  13. }
  14. // The name of the update command in the log
  15. func (c *UpdateCommand) CommandName() string {
  16. return "etcd:update"
  17. }
  18. // Update node
  19. func (c *UpdateCommand) Apply(server *raft.Server) (interface{}, error) {
  20. s, _ := server.StateMachine().(*store.Store)
  21. e, err := s.Update(c.Key, c.Value, c.ExpireTime, server.CommitIndex(), server.Term())
  22. if err != nil {
  23. log.Debug(err)
  24. return nil, err
  25. }
  26. return e, nil
  27. }