]> 127.0.0.1 Git - part/.git/commitdiff
109
authorqydysky <qydysky@foxmail.com>
Fri, 2 Apr 2021 07:24:07 +0000 (15:24 +0800)
committerqydysky <qydysky@foxmail.com>
Fri, 2 Apr 2021 07:24:07 +0000 (15:24 +0800)
tmplKV/tmplKV.go
tmplKV/tmplKV_test.go

index df65806d87c6857ec50ef5e18bbed643bd635d75..26008d5d8b65a9762cc6dae8885714e09bf6a3f7 100644 (file)
@@ -40,7 +40,7 @@ func (s *tmplKV) Set(key,value interface{},exp int64) {
 }
 
 //获取Value 及是否有效
-func (s *tmplKV) Get(key interface{}) (isLive bool,value interface{}){
+func (s *tmplKV) Get(key interface{}) (value interface{},isLive bool){
        tmp, ok := s.kvt_map.Load(key)
 
        item,_ := tmp.(tmplKV_item)
@@ -53,6 +53,21 @@ func (s *tmplKV) Get(key interface{}) (isLive bool,value interface{}){
        return
 }
 
+//获取Value 及是否有效
+func (s *tmplKV) GetV(key interface{}) (value interface{}){
+       tmp, ok := s.kvt_map.Load(key)
+
+       item,_ := tmp.(tmplKV_item)
+       value = item.kv
+
+       isLive := ok && item.kt < 0 || s.now <= item.kt
+       if !isLive && ok {
+               value = nil
+               s.kvt_map.Delete(key)
+       }
+       return
+}
+
 //检查Key Value是否对应及有效
 func (s *tmplKV) Check(key,value interface{}) bool {
        ok,v := s.Get(key)
index 472ec1a68658190eb95a57dfea3359551dd4cf64..ce09e48643ad9ff493d55c42abc37357c7446b73 100644 (file)
@@ -12,5 +12,10 @@ func Test_tmplKV(t *testing.T) {
        s.Set("a",`b`,-1)
        if !s.Check("a",`b`) {t.Error(`no match2`)}
        time.Sleep(time.Second*time.Duration(1))
-       if !s.Check("a",`b`) {t.Error(`no TO1`)}
+       if v,ok := s.Get("a");!ok {
+               t.Error(`no TO1`)
+       }else if vv,ok := v.(string);!ok{
+               t.Error(`no string`)
+       }
+       if v,ok := s.GetV("a").(string);!ok || v != `a` {t.Error(`no 2`)}
 }