Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support mget for Redis #86

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 31 additions & 2 deletions protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,37 @@ int redis_protocol::write_command_set(const char *key, int key_len, const char *

int redis_protocol::write_command_multi_get(const keylist *keylist)
{
fprintf(stderr, "error: multi get not implemented for redis yet!\n");
assert(0);
assert(keylist != NULL);
assert(keylist->get_keys_count() > 0);

int n = 0;
int size = 0;

size = evbuffer_add_printf(m_write_buf,
"*%u\r\n"
"$4\r\n"
"MGET\r\n", keylist->get_keys_count() + 1);

for (unsigned int i = 0; i < keylist->get_keys_count(); i++) {
const char *key;
unsigned int key_len;

key = keylist->get_key(i, &key_len);
assert(key != NULL);

size += evbuffer_add_printf(m_write_buf,
"$%u\r\n",
key_len);

n = evbuffer_add(m_write_buf, key, key_len);
assert(n != -1);
n = evbuffer_add(m_write_buf, "\r\n", 2);
assert(n != -1);

size += key_len + 2;
}

return size;
}

int redis_protocol::write_command_get(const char *key, int key_len, unsigned int offset)
Expand Down