redis-plus-plus icon indicating copy to clipboard operation
redis-plus-plus copied to clipboard

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

Open movepointsolutions opened this issue 1 year ago • 1 comments

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 96d0653ee0fb (master)

Additional context Add any other context about the problem here.

movepointsolutions avatar Apr 17 '23 12:04 movepointsolutions

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

sewenew avatar Apr 18 '23 14:04 sewenew