github.com/macb/etcd@v0.3.1-0.20140227003422-a60481c6b1a0/store/v2/update_command.go (about)

     1  package v2
     2  
     3  import (
     4  	"github.com/coreos/etcd/log"
     5  	"github.com/coreos/etcd/store"
     6  	"github.com/coreos/etcd/third_party/github.com/coreos/raft"
     7  	"time"
     8  )
     9  
    10  func init() {
    11  	raft.RegisterCommand(&UpdateCommand{})
    12  }
    13  
    14  // Update command
    15  type UpdateCommand struct {
    16  	Key		string		`json:"key"`
    17  	Value		string		`json:"value"`
    18  	ExpireTime	time.Time	`json:"expireTime"`
    19  }
    20  
    21  // The name of the update command in the log
    22  func (c *UpdateCommand) CommandName() string {
    23  	return "etcd:update"
    24  }
    25  
    26  // Create node
    27  func (c *UpdateCommand) Apply(context raft.Context) (interface{}, error) {
    28  	s, _ := context.Server().StateMachine().(store.Store)
    29  
    30  	e, err := s.Update(c.Key, c.Value, c.ExpireTime)
    31  
    32  	if err != nil {
    33  		log.Debug(err)
    34  		return nil, err
    35  	}
    36  
    37  	return e, nil
    38  }