Get() retrieves the value for a given key from either the txn operations or the reader store
(key []byte)
| 105 | |
| 106 | // Get() retrieves the value for a given key from either the txn operations or the reader store |
| 107 | func (t *Txn) Get(key []byte) ([]byte, lib.ErrorI) { |
| 108 | t.txn.l.Lock() |
| 109 | defer t.txn.l.Unlock() |
| 110 | // first retrieve from the in-memory txn |
| 111 | if v, found := t.txn.ops[lib.MemHash(key)]; found { |
| 112 | if v.op == opDelete { |
| 113 | return nil, nil |
| 114 | } |
| 115 | // TODO: should a sentinel value be returned when a key is found but the value is nil |
| 116 | return v.value, nil |
| 117 | } |
| 118 | // if not found, retrieve from the parent reader |
| 119 | return t.reader.Get(lib.AppendWithBuffer(&t.txn.rbuf, t.prefix, key)) |
| 120 | } |
| 121 | |
| 122 | // Set() adds or updates the value for a key in the txn operations |
| 123 | func (t *Txn) Set(key, value []byte) lib.ErrorI { |