forked from etcd-io/etcd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_command.go
41 lines (32 loc) · 834 Bytes
/
set_command.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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(&SetCommand{})
}
// Create command
type SetCommand struct {
Key string `json:"key"`
Value string `json:"value"`
ExpireTime time.Time `json:"expireTime"`
Dir bool `json:"dir"`
}
// The name of the create command in the log
func (c *SetCommand) CommandName() string {
return "etcd:set"
}
// Create node
func (c *SetCommand) Apply(context raft.Context) (interface{}, error) {
s, _ := context.Server().StateMachine().(store.Store)
// create a new node or replace the old node.
e, err := s.Set(c.Key, c.Dir, c.Value, c.ExpireTime)
if err != nil {
log.Debug(err)
return nil, err
}
return e, nil
}