store list in key value database

前端 未结 4 1875
小鲜肉
小鲜肉 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条回答
  •  猫巷女王i
    2021-01-24 19:51

    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.

提交回复
热议问题