当前位置:网站首页>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
边栏推荐
- Industrial security experts talk about DDoS countermeasures from the perspective of attack and defense
- Game business DDoS attack and defense confrontation case sharing
- The TKE cluster node reports an error when executing kubectl
- Why do you develop middleware when you are young? "You can choose your own way"
- How to get the response body content in gin?
- A tutorial on how the zblog system obtains user related information based on user ID
- Radiology: contralateral preoperative resting state MRI functional network integration is related to the surgical results of temporal lobe epilepsy
- Customizing security groups using BPF
- FPGA systematic learning notes serialization_ Day8 [design of 4-bit multiplier and 4-bit divider]
- [playing with Tencent cloud] a solution to the impassability of cross-border access to foreign websites using Tencent cloud CVM
猜你喜欢
随机推荐
[log service CLS] Tencent cloud game battle engine mgobe accesses CLS
Development of block hash game guessing system (mature code)
[play with Tencent cloud] play with cloud database mysql
See through the new financial report of Tencent music, online music needs b+c
Markdown syntax -- Formula
How to learn go language happily? Let's go!
After the collective breakthrough, where is the next step of China's public cloud?
Explanation of MySQL indexing principle
Zabix5.0-0 - agent2 monitoring MariaDB database (Linux based)
FPGA systematic learning notes serialization_ Day8 [design of 4-bit multiplier and 4-bit divider]
What is the problem that the data is not displayed on the login web page after the configuration of the RTSP video security intelligent monitoring system easynvr is completed
C4D learning notes
Kubernetes 1.20.5 helm installation Jenkins
Zblog system realizes the tutorial of the number of articles published on the same day when the foreground calls
What is the reason for the worse website SEO ranking?
TRCT test cloud + article online speed
QQ domain name detection API interface sharing (with internal access automatic jump PHP code)
A solution for building live video based on open source real-time audio and video webrtc architecture
Analysis of software supply chain attack package preemption low cost phishing
C language | logical operators

