kv some functions add error check

This commit is contained in:
siddontang 2014-05-14 08:50:19 +08:00
parent 5a5081c34e
commit b0d93f5842
1 changed files with 7 additions and 3 deletions

View File

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