feat kvpair include ttl

This commit is contained in:
Xiang Li 2013-10-26 21:19:51 -07:00
parent 63456b5c4b
commit 7b60f8bdc3
2 changed files with 14 additions and 5 deletions

View File

@ -1,10 +1,16 @@
package store package store
import (
"time"
)
// When user list a directory, we add all the node into key-value pair slice // When user list a directory, we add all the node into key-value pair slice
type KeyValuePair struct { type KeyValuePair struct {
Key string `json:"key, omitempty"` Key string `json:"key, omitempty"`
Value string `json:"value,omitempty"` Value string `json:"value,omitempty"`
Dir bool `json:"dir,omitempty"` Dir bool `json:"dir,omitempty"`
Expiration *time.Time `json:"expiration,omitempty"`
TTL int64 `json:"ttl,omitempty"` // Time to live in second
KVPairs kvPairs `json:"kvs,omitempty"` KVPairs kvPairs `json:"kvs,omitempty"`
} }

View File

@ -322,6 +322,7 @@ func (n *Node) Pair(recurisive, sorted bool) KeyValuePair {
Key: n.Path, Key: n.Path,
Dir: true, Dir: true,
} }
pair.Expiration, pair.TTL = n.ExpirationAndTTL()
if !recurisive { if !recurisive {
return pair return pair
@ -354,10 +355,12 @@ func (n *Node) Pair(recurisive, sorted bool) KeyValuePair {
return pair return pair
} }
return KeyValuePair{ pair := KeyValuePair{
Key: n.Path, Key: n.Path,
Value: n.Value, Value: n.Value,
} }
pair.Expiration, pair.TTL = n.ExpirationAndTTL()
return pair
} }
func (n *Node) UpdateTTL(expireTime time.Time) { func (n *Node) UpdateTTL(expireTime time.Time) {