tidwall / buntdb

BuntDB is an embeddable, in-memory key/value database for Go with custom indexing and geospatial support
MIT License
4.57k stars 289 forks source link

Enhancement: add new method GetWithTTL to return value together with TTL #102

Open kcmvp opened 1 year ago

kcmvp commented 1 year ago

First, thank you very much for the great project!

I am building a disstributed KV(https://github.com/kcmvp/daos) based on buntdb, for data rebalancing when new nodes join , the TTL of an entry need to be syncd as well. right now I am using two api call (Get & TTL) to get value and entry's ttl, it work well, but I found that it will use more time to get entries especially when there are lots of entrie need to be synced.

I would like to raise a PR by adding a new mthod GetWithTTL

func (tx *Tx) GetWithTTL(key string) (string, time.Duration, error)

1: this method will return value for a key together with it's TTL. 2: If the item does not exist or if the item has expired then ErrNotFound is returned. 3: A negative duration will be returned for items that do not have an expiration.

Thank you!