|
|
@ -1218,15 +1218,7 @@ Status DBImpl::Put(const WriteOptions& o, const Slice& key, const Slice& val) { |
|
|
|
|
|
|
|
Status DBImpl::Put(const WriteOptions& opt, const Slice& key, |
|
|
|
const Slice& value, uint64_t ttl) { |
|
|
|
WriteBatch batch; |
|
|
|
auto now = std::chrono::system_clock::now(); |
|
|
|
auto timestamp = std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count(); |
|
|
|
auto microsecondsTimestamp = static_cast<uint64_t>(timestamp) + ttl*1000000; |
|
|
|
std::string value_ttl = value.ToString(); |
|
|
|
value_ttl += "_" + std::to_string(microsecondsTimestamp); |
|
|
|
Slice new_value(value_ttl.c_str(), value_ttl.size()); |
|
|
|
batch.Put(key, new_value); |
|
|
|
return Write(opt, &batch); |
|
|
|
return DB::Put(opt, key, value, ttl); |
|
|
|
} |
|
|
|
|
|
|
|
Status DBImpl::Delete(const WriteOptions& options, const Slice& key) { |
|
|
@ -1521,6 +1513,19 @@ Status DB::Put(const WriteOptions& opt, const Slice& key, const Slice& value) { |
|
|
|
batch.Put(key, value); |
|
|
|
return Write(opt, &batch); |
|
|
|
} |
|
|
|
// for TTL
|
|
|
|
Status DB::Put(const WriteOptions& opt, const Slice& key, |
|
|
|
const Slice& value, uint64_t ttl) { |
|
|
|
WriteBatch batch; |
|
|
|
auto now = std::chrono::system_clock::now(); |
|
|
|
auto timestamp = std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count(); |
|
|
|
auto microsecondsTimestamp = static_cast<uint64_t>(timestamp) + ttl*1000000; |
|
|
|
std::string value_ttl = value.ToString(); |
|
|
|
value_ttl += "_" + std::to_string(microsecondsTimestamp); |
|
|
|
Slice new_value(value_ttl.c_str(), value_ttl.size()); |
|
|
|
batch.Put(key, new_value); |
|
|
|
return Write(opt, &batch); |
|
|
|
} |
|
|
|
|
|
|
|
Status DB::Delete(const WriteOptions& opt, const Slice& key) { |
|
|
|
WriteBatch batch; |
|
|
|