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

[BUG] lrange doesn't accept std::ostream_iterator<std::string> #473

Open
movepointsolutions opened this issue Apr 17, 2023 · 1 comment
Open

Comments

@movepointsolutions
Copy link

Describe the bug
I try to concatenate list entries using std::stringstream
And was lazy enough to not try writing custom iterator

To Reproduce

std::stringstream s;
redis.lrange(key, 0, -1, std::ostream_iterator<std::string>(s, "\0"));

Expected behavior
list entries '\0'-separated in stream

Environment:

  • OS: latet xubuntu
  • Compiler: gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
  • hiredis version: v0.14.1-2
  • redis-plus-plus version: commit 96d0653 (master)

Additional context
Add any other context about the problem here.

@sewenew
Copy link
Owner

sewenew commented Apr 18, 2023

The problem is that ostream_iterator<string>::value_type is void not string, and redis-plus-plus cannot correctly parse reply to it.

A workaround is that you can parse the reply to vector<string>, and move these strings to stringstream.

vector<string> vec;
redis.lrange("l", 0, -1, std::back_inserter(vec));
std::stringstream s;
std::copy(std::make_move_iterator(vec.begin()), std::make_move_iterator(vec.end()), std::ostream_iterator<std::string>(s, "\0"));

I'll try to figure out a way to fix the problem.

Regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants