Exemple #1
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;
}
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)
Exemple #3
0
void median_filter::add_sample(connection::ptr_t connection, const std::string &tag, double value)
{
  connection->append(command("MULTI"));
  connection->append(command("LPUSH") << list_key(tag) << value );
  connection->append(command("LTRIM") << list_key(tag) << 0 << _samples-1 );
  connection->append(command("EXEC"));
  connection->get_replies(4);
}
void connection_pool::put(connection::ptr_t conn)
{
    if (conn->is_valid())
    {
        std::unique_lock<std::mutex> lock(access_mutex);
        connections.insert(conn);
    }
}
    bool endpoint::sort_connection_cmp_fn(const connection::ptr_t &left, const connection::ptr_t &right) {
        int lscore = 0, rscore = 0;
        if (!left->check_flag(connection::flag_t::ACCESS_SHARE_ADDR)) {
            lscore += 0x08;
        }
        if (!left->check_flag(connection::flag_t::ACCESS_SHARE_HOST)) {
            lscore += 0x04;
        }

        if (!right->check_flag(connection::flag_t::ACCESS_SHARE_ADDR)) {
            rscore += 0x08;
        }
        if (!right->check_flag(connection::flag_t::ACCESS_SHARE_HOST)) {
            rscore += 0x04;
        }

        return lscore < rscore;
    }
    bool endpoint::sort_connection_cmp_fn(const connection::ptr_t& left, const connection::ptr_t& right) {
        if (left->check_flag(connection::flag_t::ACCESS_SHARE_ADDR) != right->check_flag(connection::flag_t::ACCESS_SHARE_ADDR)) {
            return left->check_flag(connection::flag_t::ACCESS_SHARE_ADDR);
        }

        if (left->check_flag(connection::flag_t::ACCESS_SHARE_HOST) != right->check_flag(connection::flag_t::ACCESS_SHARE_HOST)) {
            return left->check_flag(connection::flag_t::ACCESS_SHARE_HOST);
        }

        return false;
    }
Exemple #7
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;
        }
    }
}