Get Read data according to the key
(key []byte)
| 248 | |
| 249 | // Get Read data according to the key |
| 250 | func (db *DB) Get(key []byte) ([]byte, error) { |
| 251 | zap.L().Info("get", zap.ByteString("key", key)) |
| 252 | db.lock.RLock() |
| 253 | defer db.lock.RUnlock() |
| 254 | |
| 255 | // Determine the validity of the key |
| 256 | if len(key) == 0 { |
| 257 | return nil, _const.ErrKeyIsEmpty |
| 258 | } |
| 259 | |
| 260 | // Retrieves the index of the key from the memory data structure |
| 261 | logRecordPst := db.index.Get(key) |
| 262 | // If key is not in the memory index, it does not exist |
| 263 | if logRecordPst == nil { |
| 264 | return nil, _const.ErrKeyNotFound |
| 265 | } |
| 266 | |
| 267 | // Gets the value from the data file |
| 268 | return db.getValueByPosition(logRecordPst) |
| 269 | } |
| 270 | |
| 271 | // GetListKeys Gets all the keys in the database |
| 272 | func (db *DB) GetListKeys() [][]byte { |