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
You can use Redis to store list in zset
(sorted set), like this:
// this line is called whenever a user place an order
$redis->zadd($user_1_orders, time(), $order_id);
// list orders of the user
$redis->zrange($user_1_orders, 0, -1);
Redis is fast enough. But one thing you should know about Redis is that it stores all data in memory, so if the data eventually exceed the physical memory, you have to shard the data by your own.
Also you can use SSDB
(https://github.com/ideawu/ssdb), which is a wrapper of leveldb
, has similar APIs to Redis, but stores most data in disk, memory is only used for caching. That means SSDB's capacity is 100 times of Redis' - up to TBs.