当前位置:网站首页>1. Leveldb getting started
1. Leveldb getting started
2022-06-24 17:23:00 【Xiao Lin Gang】
brief introduction
leveldb yes google A high performance of open source kv Data repository .
characteristic
- be based on LSM Mechanism to store data , High reading and writing performance ;
- key、value Support arbitrary byte Type array , Not just strings ;
- A persistent storage KV System , Store most of the data on disk ;
- according to key Values store data sequentially ;
- The operation interface is simple , The main interface is Put、Get、Delete;
- Support data snapshot The snapshot function , Read operations are not affected by write operations , Consistent data is always seen during read operations ;
- Support data compression (snappy Compress ) operation , Effectively reduce storage space 、 And increase speed IO efficiency ;
Use scenarios
- stand-alone kv Storage engine ;
Use samples
compile leveldb library
# git clone https://github.com/google/leveldb.git # cd leveldb/ # git checkout -b 1.20 v1.20 // compile # make // install # cp -rf include/leveldb/ /usr/include/ # cp out-shared/libleveldb.so* /usr/lib64/
Use samples
// test1.cpp
#include <cassert>
#include <iostream>
#include "leveldb/db.h"
int main() {
leveldb::DB *db;
leveldb::Options options;
options.create_if_missing = true;
leveldb::Status status = leveldb::DB::Open(options, "./test.db", &db);
assert(status.ok());
std::cout << "leveldb open success!" << std::endl;
std::string key = "testkey1";
std::string value = "testvalue1";
db->Put(leveldb::WriteOptions(), key, value);
std::cout << "put key " << key << " success" << std::endl;
std::string value2;
leveldb::Status s = db->Get(leveldb::ReadOptions(), key, &value2);
if (s.ok()) {
std::cout << "found key:" << key << ",value:" << value2 << std::endl;
}
s = db->Delete(leveldb::WriteOptions(), key);
if (s.ok()) {
std::cout << "delete key success which key:" << key << std::endl;
}
s = db->Get(leveldb::ReadOptions(), key, &value2);
if (s.IsNotFound()) {
std::cout << "can not found after delete for key:" << key << std::endl;
}
delete db;
return 0;
}compile
# g++ -lpthread -lleveldb -o test1 test1.cpp
function
# ./test1 leveldb open success! put key testkey1 success found key:testkey1,value:testvalue1 delete key success which key:testkey1 can not found after delete for key:testkey1
Data files
# tree test.db/ test.db/ ├── 000003.log ├── CURRENT ├── LOCK ├── LOG └── MANIFEST-000002
边栏推荐
- Quick view of product trends in February 2021
- Sigai intelligent container damage identification products are deployed in Rizhao Port and Yingkou Port
- 跟着Vam一起学习Typescript(第一期)
- C language | logical operators
- ClassNotFoundException v/s NoClassDefFoundError
- Hook graphics kernel subsystem
- zblog判断某个插件是否安装启用的内置函数代码
- One article combs multi task learning (mmoe/ple/dupn/essm, etc.)
- liver failure! My friend made a programming navigation website!
- Why do you develop middleware when you are young? "You can choose your own way"
猜你喜欢
随机推荐
Comparison of similarities and differences between easynvr video edge computing gateway and easynvr software versions
04. Tencent cloud IOT device side learning - network connection and device authentication
One article combs multi task learning (mmoe/ple/dupn/essm, etc.)
See through the new financial report of Tencent music, online music needs b+c
Tencent cloud layer 7 load balancing log analysis and monitoring
Contributed code to famous projects for the first time, a little nervous
[play with Tencent cloud] check 9 popular Tencent cloud products
Tiktok Kwai, e-commerce enters the same river
Several cloud products of Tencent cloud have passed IPv6 enabled cloud logo certification
To redefine the storage architecture, Huawei has used more than five "cores"
Yupi made an AI programming nickname generator!
Erc-20 Standard Specification
C language | logical operators
Create a green city and 3D visualization of digital twin natural gas stations
TRCT test cloud + article online speed
ClassNotFoundException v/s NoClassDefFoundError
Low education without food? As an old Android rookie in the past six years, I was the most difficult one
[play with Tencent cloud] TSF User Guide
[go language development] start to develop Meitu station from 0 - Lesson 5 [receive pictures and upload]
liver failure! My friend made a programming navigation website!

