Exemplo n.º 1
0
connection::role_t connection_pool::get_role(connection::ptr_t conn)
{
	static const 
#ifndef NO_BOOST
    boost::regex 
#else
	std::regex 
#endif
	role_searcher("\r\nrole:([a-z]+)\r\n");

    reply r = conn->run(command("ROLE"));
    std::string role_s;

    if (r.type() == reply::type_t::ERROR
#ifndef NO_BOOST
		&& boost::algorithm::find_first(r.str(),"unknown"))
#else
		&& (r.str().find("unknown") != std::string::npos) )
#endif
		
    {
        logging::debug("Old redis, doesn't support ROLE command");
        reply r = conn->run(command("INFO") << "replication");
#ifndef NO_BOOST
        boost::smatch results;
        if (boost::regex_search(r.str(), results, role_searcher))
#else
		std::smatch results;
		if (std::regex_search(r.str(), results, role_searcher))
#endif
        {
            role_s = results[1];
        }
    }
    else if (r.type() == reply::type_t::ARRAY)
Exemplo n.º 2
0
reply patterns::script_exec::exec(connection::ptr_t connection,
                const std::vector<std::string>& keys,
                const std::vector<std::string>& args)
{
    std::vector<std::string> exec_command;
    exec_command.reserve(3+keys.size()+args.size());

    exec_command.push_back("EVALSHA");
    exec_command.push_back(_sha1);
	exec_command.push_back(std::to_string(keys.size()));
    exec_command.insert(exec_command.end(), keys.begin(), keys.end());
    exec_command.insert(exec_command.end(), args.begin(), args.end());
    reply r = connection->run(exec_command);
    if (r.type() == reply::type_t::ERR &&
		r.str().find("NOSCRIPT") == 0
		)
    {
        exec_command[0] = "EVAL";
        if (_is_path)
        {
            exec_command[1] = utils::read_content_of_file(_script);
        }
        else
        {
            exec_command[1] = _script;
        }
        r = connection->run(exec_command);
    }
    return r;
}
Exemplo n.º 3
0
double median_filter::median(connection::ptr_t connection, const std::string &tag)
{
    reply r = connection->run(command("SORT") << list_key(tag));
    const std::vector<reply>& values = r.elements();
    int size = values.size();

    if (size % 2 != 0)
    {
        return boost::lexical_cast<double>(values.at((size-1)/2).str());
    }
    else
    {
        if (size == 0)
        {
            return 0;
        }
        else
        {
            return ( boost::lexical_cast<double>(values.at(size/2-1).str()) +
                boost::lexical_cast<double>(values.at(size/2).str()) ) / 2;
        }
    }
}