Add TsSeqKeyValue::isset.

This commit is contained in:
levlam 2022-08-17 16:52:27 +03:00
parent 5b22effaa6
commit f1c9d69077
2 changed files with 23 additions and 0 deletions

View File

@ -32,6 +32,7 @@ class SeqKeyValue {
}
return next_seq_no();
}
SeqNo erase(const string &key) {
auto it = map_.find(key);
if (it == map_.end()) {
@ -40,9 +41,11 @@ class SeqKeyValue {
map_.erase(it);
return next_seq_no();
}
SeqNo seq_no() const {
return current_id_ + 1;
}
string get(const string &key) const {
auto it = map_.find(key);
if (it == map_.end()) {
@ -51,6 +54,14 @@ class SeqKeyValue {
return it->second;
}
bool isset(const string &key) const {
auto it = map_.find(key);
if (it == map_.end()) {
return false;
}
return true;
}
size_t size() const {
return map_.size();
}

View File

@ -33,29 +33,41 @@ class TsSeqKeyValue {
auto lock = rw_mutex_.lock_write().move_as_ok();
return kv_.set(key, value);
}
std::pair<SeqNo, RwMutex::WriteLock> set_and_lock(Slice key, Slice value) {
auto lock = rw_mutex_.lock_write().move_as_ok();
return std::make_pair(kv_.set(key, value), std::move(lock));
}
SeqNo erase(const string &key) {
auto lock = rw_mutex_.lock_write().move_as_ok();
return kv_.erase(key);
}
std::pair<SeqNo, RwMutex::WriteLock> erase_and_lock(const string &key) {
auto lock = rw_mutex_.lock_write().move_as_ok();
return std::make_pair(kv_.erase(key), std::move(lock));
}
string get(const string &key) {
auto lock = rw_mutex_.lock_read().move_as_ok();
return kv_.get(key);
}
bool isset(const string &key) {
auto lock = rw_mutex_.lock_read().move_as_ok();
return kv_.isset(key);
}
size_t size() const {
return kv_.size();
}
std::unordered_map<string, string> get_all() {
auto lock = rw_mutex_.lock_write().move_as_ok();
return kv_.get_all();
}
// not thread safe method
SeqKeyValue &inner() {
return kv_;