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,11 +1,17 @@
package store
import (
"time"
)
// When user list a directory, we add all the node into key-value pair slice
type KeyValuePair struct {
Key string `json:"key, omitempty"`
Value string `json:"value,omitempty"`
Dir bool `json:"dir,omitempty"`
KVPairs kvPairs `json:"kvs,omitempty"`
Key string `json:"key, omitempty"`
Value string `json:"value,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"`
}
type kvPairs []KeyValuePair

View File

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