From 7779ad6c28ebe718e803ab7ebfc56a52e08d5207 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Fri, 27 Sep 2019 15:40:44 +0300 Subject: [PATCH] storage: always return ErrKeyNotFound when key is not found It was true for MemoryStore and BoltDB, but not for LevelDB and Redis. --- pkg/core/storage/leveldb_store.go | 6 +++++- pkg/core/storage/redis_store.go | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/core/storage/leveldb_store.go b/pkg/core/storage/leveldb_store.go index 1bc6e013b..f024c41d3 100644 --- a/pkg/core/storage/leveldb_store.go +++ b/pkg/core/storage/leveldb_store.go @@ -41,7 +41,11 @@ func (s *LevelDBStore) Put(key, value []byte) error { // Get implements the Store interface. func (s *LevelDBStore) Get(key []byte) ([]byte, error) { - return s.db.Get(key, nil) + value, err := s.db.Get(key, nil) + if err == leveldb.ErrNotFound { + err = ErrKeyNotFound + } + return value, err } // PutBatch implements the Store interface. diff --git a/pkg/core/storage/redis_store.go b/pkg/core/storage/redis_store.go index 069581956..5dd5ac4e0 100644 --- a/pkg/core/storage/redis_store.go +++ b/pkg/core/storage/redis_store.go @@ -40,6 +40,9 @@ func (s *RedisStore) Batch() Batch { func (s *RedisStore) Get(k []byte) ([]byte, error) { val, err := s.client.Get(string(k)).Result() if err != nil { + if err == redis.Nil { + err = ErrKeyNotFound + } return nil, err } return []byte(val), nil