cpp-redis / cpp_redis

C++11 Lightweight Redis client: async, thread-safe, no dependency, pipelining, multi-platform
MIT License
720 stars 199 forks source link

Redis client xrevrange command has an issue with reading n elements from given stream #59

Open dhruvkakadiya opened 4 years ago

dhruvkakadiya commented 4 years ago

As per xrevrange documentation, to get number of elements from given stream "COUNT" word needs to be there before actual value which is missing in current code.

Current code:

    client &
    client::xrevrange(const std::string &key, const range_options_t &range_args, const reply_callback_t &reply_callback) {
        std::vector<std::string> cmd = {"XREVRANGE", key, range_args.Start, range_args.Stop};
        if (range_args.Count > 0) {
            cmd.emplace_back(std::to_string(range_args.Count));
        }
        send(cmd, reply_callback);
        return *this;
    }

Fixed code:

    client &
    client::xrevrange(const std::string &key, const range_options_t &range_args, const reply_callback_t &reply_callback) {
        std::vector<std::string> cmd = {"XREVRANGE", key, range_args.Start, range_args.Stop};
        if (range_args.Count > 0) {
            cmd.emplace_back("COUNT");
            cmd.push_back(std::to_string(range_args.Count));
        }
        send(cmd, reply_callback);
        return *this;
    }