Browse Source

feat kvpair include ttl

Xiang Li 12 years ago
parent
commit
7b60f8bdc3
2 changed files with 14 additions and 5 deletions
  1. 10 4
      store/kv_pairs.go
  2. 4 1
      store/node.go

+ 10 - 4
store/kv_pairs.go

@@ -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

+ 4 - 1
store/node.go

@@ -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) {