C/C++教程

RocksDB安装与使用

本文主要是介绍RocksDB安装与使用,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

安装

系统为:Ubuntu18.04

Dependencies:

sudo apt-get install libgflags-dev \
		     libsnappy-dev \
		     zlib1g-dev \
	             libbz2-dev \
	             liblz4-dev \
		     libzstd-dev

参考文档

使用

create_db.cpp

#include <assert.h>
#include "rocksdb/db.h"
int main()
{
  rocksdb::DB* db;
  rocksdb::Options options;
  options.create_if_missing = true;
  rocksdb::Status status = rocksdb::DB::Open(options, "/home/ubuntu/rocksdb_test/testdb", &db);
  assert(status.ok());
  return 0;
}

CMakeLists.txt

# Passed
# PROJECT(CREATEDB)
# LINK_LIBRARIES("/home/ubuntu/3rd/rocksdb/librocksdb.a")
# INCLUDE_DIRECTORIES(/home/ubuntu/3rd/rocksdb/include)

# find_library(LZ4_LIB lz4)
# message(STATUS "finding ${LZ4_LIB}")

# ADD_EXECUTABLE(create_db create_db.cpp)
# TARGET_LINK_LIBRARIES(create_db ${LZ4_LIB} -lpthread -lsnappy -lz -lbz2 -lzstd -ldl)

PROJECT(CREATEDB)
LINK_LIBRARIES("/home/ubuntu/3rd/rocksdb/librocksdb.a")
INCLUDE_DIRECTORIES(/home/ubuntu/3rd/rocksdb/include)

ADD_EXECUTABLE(create_db create_db.cpp)
TARGET_LINK_LIBRARIES(create_db z4 pthread snappy z bz2 zstd dl)

运行create_db创建数据库

(base) ubuntu@VM-8-7-ubuntu:~/rocksdb_test$ tree  testdb/
testdb/
├── 000005.log
├── CURRENT
├── IDENTITY
├── LOCK
├── LOG
├── MANIFEST-000004
└── OPTIONS-000007

0 directories, 7 files
这篇关于RocksDB安装与使用的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!