store list in key value database

前端 未结 4 1911
小鲜肉
小鲜肉 2021-01-24 19:25

I search for best way to store lists associated with key in key value database (like berkleydb or leveldb)

For example: I have users and orders

4条回答
  •  耶瑟儿~
    2021-01-24 19:33

    One way you could model this in a key-value store which supports scans , like leveldb, would be to add the order id to the key for each user. So the new keys would be userId_orderId for each order. Now to get orders for a particular user, you can do a simple prefix scan - scan(userId*). Now this makes the userId range query slow, in that case you can maintain another table just for userIds or use another key convention : Id_userId for getting userIds between [5000-5050]

    Recently I have seen hyperdex adding data types support on top of leveldb : ex: http://hyperdex.org/doc/04.datatypes/#lists , so you could give that a try too.

提交回复
热议问题