Congyuwang / RocksDict

Python fast on-disk dictionary / RocksDB & SpeeDB Python binding
https://congyuwang.github.io/RocksDict/rocksdict.html
MIT License
176 stars 8 forks source link

Add put, get, and delete methods to match python-rocksdb #45

Closed wbarnha closed 1 year ago

wbarnha commented 1 year ago

I'm currently in the process of replacing python-rocksdb in the Faust-Streaming project with rocksdict. Since I can't subclass Rdict, it'd be appreciated if we could have similar put, get, and delete calls to make the transition much easier. Thoughts?

Congyuwang commented 1 year ago

Hi. Great.

The current behavior of __getitem__() raise KeyError when the key does not exist, which is the same as python Dict.

The behavior of __delitem__(), however does NOT raise exception when the key does not exist, which is different from python Dict. But this is because RocksDB uses SST and doesn't check key existence upon deletion.

I think maybe we could make get() to have the same interface as python Dict

    @overload
    def get(self, __key: _KT) -> _VT_co | None: ...
    @overload
    def get(self, __key: _KT, default: _VT_co | _T) -> _VT_co | _T: ...

What do you think?

wbarnha commented 1 year ago

My thoughts exactly! I'm not that familiar with Rust yet so I wasn't sure how to go about doing so.

Congyuwang commented 1 year ago

OK, I'll modify it a bit.

Congyuwang commented 1 year ago

Merged into v0.3.8! BTW, what makes you switch to rocksdict from python-rocksdb?

wbarnha commented 1 year ago

Long story short, I made an inefficient CI/CD chain for https://github.com/faust-streaming/python-rocksdb, and the wheels are 66 MB. For each version of Python I need to support, it gets pretty clunky after a while. Especially combined with the fact that the unzipped wheel is 250 MB.

I originally contacted the maintainer of https://github.com/twmht/python-rocksdb to get control over consolidating all python-rocksdb forks, but that never came to fruition. Since I think you're actively maintaining a performant, compact RocksDB driver for Python, I think going with your project is the best solution.

wbarnha commented 1 year ago

Thanks for the fast response by the way, I really appreciate it!