Skip to content

Commit cf03ee7

Browse files
committed
[add] Enable mixing key placeholder with string arguments
1 parent 18d2646 commit cf03ee7

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

client.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050

5151
#include "client.h"
5252
#include "cluster_client.h"
53+
#include "config_types.h"
5354

5455

5556
bool client::setup_client(benchmark_config *config, abstract_protocol *protocol, object_generator *objgen)
@@ -256,8 +257,14 @@ void client::create_arbitrary_request(const arbitrary_command* cmd, struct timev
256257

257258
assert(key != NULL);
258259
assert(key_len > 0);
259-
260-
cmd_size += m_connections[conn_id]->send_arbitrary_command(arg, key, key_len);
260+
//when we have static data mixed with the key placeholder
261+
if (arg->data.length() != strlen(KEY_PLACEHOLDER)) {
262+
std::string str (arg->data);
263+
str.replace(str.find(KEY_PLACEHOLDER),strlen(KEY_PLACEHOLDER),key);
264+
cmd_size += m_connections[conn_id]->send_arbitrary_command(arg, str.c_str(), str.length() );
265+
} else{
266+
cmd_size += m_connections[conn_id]->send_arbitrary_command(arg, key, key_len);
267+
}
261268
} else if (arg->type == data_type) {
262269
unsigned int value_len;
263270
const char *value = m_obj_gen->get_value(0, &value_len);

protocol.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -631,11 +631,6 @@ bool redis_protocol::format_arbitrary_command(arbitrary_command &cmd) {
631631

632632
// check arg type
633633
if (current_arg->data.find(KEY_PLACEHOLDER) != std::string::npos) {
634-
if (current_arg->data.length() != strlen(KEY_PLACEHOLDER)) {
635-
benchmark_error_log("error: key placeholder can't combined with other data\n");
636-
return false;
637-
}
638-
639634
current_arg->type = key_type;
640635
} else if (current_arg->data.find(DATA_PLACEHOLDER) != std::string::npos) {
641636
if (current_arg->data.length() != strlen(DATA_PLACEHOLDER)) {

0 commit comments

Comments
 (0)