From b0d93f5842cf4adbda4f5b600fa56bba04485feb Mon Sep 17 00:00:00 2001 From: siddontang Date: Wed, 14 May 2014 08:50:19 +0800 Subject: [PATCH] kv some functions add error check --- ledis/t_kv.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ledis/t_kv.go b/ledis/t_kv.go index 7496af5..f575e6d 100644 --- a/ledis/t_kv.go +++ b/ledis/t_kv.go @@ -49,14 +49,16 @@ func (a *App) kv_set(key []byte, value []byte) error { func (a *App) kv_getset(key []byte, value []byte) ([]byte, error) { key = encode_kv_key(key) - var err error t := a.kvTx t.Lock() defer t.Unlock() - oldValue, _ := a.db.Get(key) + oldValue, err := a.db.Get(key) + if err != nil { + return nil, err + } t.Put(key, value) //todo, binlog @@ -77,7 +79,9 @@ func (a *App) kv_setnx(key []byte, value []byte) (int64, error) { t.Lock() defer t.Unlock() - if v, _ := a.db.Get(key); v != nil { + if v, err := a.db.Get(key); err != nil { + return 0, err + } else if v != nil { n = 0 } else { t.Put(key, value)