forked from TrueCloudLab/neoneo-go
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:
parent
5ff1399d54
commit
7779ad6c28
2 changed files with 8 additions and 1 deletions
|
@ -41,7 +41,11 @@ func (s *LevelDBStore) Put(key, value []byte) error {
|
||||||
|
|
||||||
// Get implements the Store interface.
|
// Get implements the Store interface.
|
||||||
func (s *LevelDBStore) Get(key []byte) ([]byte, error) {
|
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.
|
// PutBatch implements the Store interface.
|
||||||
|
|
|
@ -40,6 +40,9 @@ func (s *RedisStore) Batch() Batch {
|
||||||
func (s *RedisStore) Get(k []byte) ([]byte, error) {
|
func (s *RedisStore) Get(k []byte) ([]byte, error) {
|
||||||
val, err := s.client.Get(string(k)).Result()
|
val, err := s.client.Get(string(k)).Result()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if err == redis.Nil {
|
||||||
|
err = ErrKeyNotFound
|
||||||
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return []byte(val), nil
|
return []byte(val), nil
|
||||||
|
|
Loading…
Reference in a new issue