storage: always return ErrKeyNotFound when key is not found

It was true for MemoryStore and BoltDB, but not for LevelDB and Redis.
This commit is contained in:
Roman Khimov 2019-09-27 15:40:44 +03:00
parent 5ff1399d54
commit 7779ad6c28
2 changed files with 8 additions and 1 deletions

View file

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

View file

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