SSDB介绍
SSDB是一款nosql数据库,使用leveldb作为存储引擎,支持众多的数据结构,如 queue、zset和hash,宣称可用来替代redis,看来性能不可小觑。其作者是位国人,曾在360游戏部门任职过。SSDB被很多知名公司使用,代码质量不错。
http://ssdb.io/zh_cn/,代码托管在github。
queue的实现
leveldb本身是k/v数据库,如何在单纯的k/v上实现queue呢?
来看ssdb中的实现:
下面是ssdb/src/ssdb/ssdb.h 中queue部分的接口
virtual int64_t qsize(const Bytes &name) = 0;
// @return 0: empty queue, 1: item peeked, -1: error
virtual int qfront(const Bytes &name, std::string *item) = 0;
// @return 0: empty queue, 1: item peeked, -1: error
virtual int qback(const Bytes &name, std::string *item) = 0;
// @return -1: error, other: the new length of the queue
virtual int64_t qpush_front(const Bytes &name, const Bytes &item, char log_type=BinlogType::SYNC) = 0;
virtual int64_t qpush_back(const Bytes &name, const Bytes &item, char log_type=BinlogType::SYNC) = 0;
// @return 0: empty queue, 1: item popped, -1: error
virtual int qpop_front(const Bytes &n