Skip to content

Commit 93bd52c

Browse files
authored
feat(server): extend populate command with expire, fix bug that expire the same key for multiple time (#4757)
* feat(server): extend populate command with expire, fix bug that expire the same key for multiple time
1 parent ac33cd8 commit 93bd52c

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

src/server/debugcmd.cc

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -195,28 +195,28 @@ void DoPopulateBatch(string_view type, string_view prefix, size_t val_size, bool
195195
stub_tx->InitByArgs(cntx->ns, local_cntx.conn_state.db_index, args_span);
196196

197197
sf->service().InvokeCmd(cid, args_span, &crb, &local_cntx);
198+
}
198199

199-
if (expire_ttl_range.has_value()) {
200-
uint32_t start = expire_ttl_range->first;
201-
uint32_t end = expire_ttl_range->second;
202-
uint32_t expire_ttl = rand() % (end - start) + start;
203-
VLOG(1) << "set key " << key << " expire ttl as " << expire_ttl;
204-
auto cid = sf->service().mutable_registry()->Find("EXPIRE");
205-
absl::InlinedVector<string, 5> args;
206-
args.push_back(std::move(key));
207-
args.push_back(to_string(expire_ttl));
208-
args_view.clear();
209-
for (auto& arg : args) {
210-
args_view.push_back(arg);
211-
}
212-
auto args_span = absl::MakeSpan(args_view);
213-
stub_tx->MultiSwitchCmd(cid);
214-
local_cntx.cid = cid;
215-
crb.SetReplyMode(ReplyMode::NONE);
216-
stub_tx->InitByArgs(cntx->ns, local_cntx.conn_state.db_index, args_span);
217-
218-
sf->service().InvokeCmd(cid, args_span, &crb, &local_cntx);
200+
if (expire_ttl_range.has_value()) {
201+
uint32_t start = expire_ttl_range->first;
202+
uint32_t end = expire_ttl_range->second;
203+
uint32_t expire_ttl = rand() % (end - start) + start;
204+
VLOG(1) << "set key " << key << " expire ttl as " << expire_ttl;
205+
auto cid = sf->service().mutable_registry()->Find("EXPIRE");
206+
absl::InlinedVector<string, 5> args;
207+
args.push_back(std::move(key));
208+
args.push_back(to_string(expire_ttl));
209+
args_view.clear();
210+
for (auto& arg : args) {
211+
args_view.push_back(arg);
219212
}
213+
auto args_span = absl::MakeSpan(args_view);
214+
stub_tx->MultiSwitchCmd(cid);
215+
local_cntx.cid = cid;
216+
crb.SetReplyMode(ReplyMode::NONE);
217+
stub_tx->InitByArgs(cntx->ns, local_cntx.conn_state.db_index, args_span);
218+
219+
sf->service().InvokeCmd(cid, args_span, &crb, &local_cntx);
220220
}
221221
}
222222

0 commit comments

Comments
 (0)