Ejemplo n.º 1
0
redisAsyncContext *
redis_nginx_open_context(u_char *host, int port, int database, u_char *password, redisAsyncContext **context)
{
    redisAsyncContext *ac = NULL;

    if ((context == NULL) || (*context == NULL) || (*context)->err) {
        ac = redisAsyncConnect((const char *)host, port);
        if (ac == NULL) {
            ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, 0, "redis_nginx_adapter: could not allocate the redis context for %s:%d", host, port);
            return NULL;
        }

        if (ac->err) {
            ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, 0, "redis_nginx_adapter: could not create the redis context for %s:%d - %s", host, port, ac->errstr);
            redisAsyncFree(ac);
            return NULL;
        }

        redis_nginx_event_attach(ac);

        if (context != NULL) {
            *context = ac;
        }
        if(password) {
          redisAsyncCommand(ac, redis_nginx_auth_callback, context, AUTH_COMMAND, password);
        }
        redisAsyncCommand(ac, redis_nginx_select_callback, context, SELECT_DATABASE_COMMAND, database);
    } else {
        ac = *context;
    }

    return ac;
}
Ejemplo n.º 2
0
int rxs_signal_store_address(rxs_signal* s, int slot, const char* ip, uint16_t port) {
  if (!s)    { return -1; } 
  if (!ip)   { return -2; } 
  if (!port) { return -3; } 

  redisAsyncCommand(s->redis, NULL, NULL, "PUBLISH slot%d address:%s:%d", slot, ip, port);
  redisAsyncCommand(s->redis, NULL, NULL, "HMSET signal:%d ip %s port %d", slot, ip, port);
  return 0;
}
Ejemplo n.º 3
0
static void
rspamd_redis_maybe_auth (struct redis_stat_ctx *ctx, redisAsyncContext *redis)
{
	if (ctx->password) {
		redisAsyncCommand (redis, NULL, NULL, "AUTH %s", ctx->password);
	}
	if (ctx->dbname) {
		redisAsyncCommand (redis, NULL, NULL, "SELECT %s", ctx->dbname);
	}
}
Ejemplo n.º 4
0
void connectAsyncRedis(redisAsyncContext *ctx, EventLoop *loop)
{
	if(redisSayanAttach(ctx, loop)!=REDIS_OK)
		die("Error: %s\n", ctx->errstr);
	redisAsyncSetConnectCallback(ctx, connectCallback);
	redisAsyncSetDisconnectCallback(ctx, disconnectCallback);
	char *test="bonjour";
	redisAsyncCommand(ctx, getCallback, NULL, "SET key %b", test, strlen(test));
	redisAsyncCommand(ctx, getCallback, (char*)"end-1", "GET key");
}
Ejemplo n.º 5
0
void announce(tracker_announce_data *announce_data) {
	// d2:ip15:255.255.255.2557:peer id20:123456789012345678904:porti60001ee
	peer_entry peer;
	memset(&peer, 0, sizeof(peer_entry));
	char ip[INET_ADDRSTRLEN];
	inet_ntop(AF_INET, &(announce_data->ip), ip, INET_ADDRSTRLEN);
	int ip_len = strlen(ip),
	    ip_len_len = intlength(ip_len);

	peer.b_length = 47 + ip_len + ip_len_len + intlength(announce_data->port);
	sprintf(peer.bencoded, "d2:ip%d:%s7:peer id20:", ip_len, ip);
	int i = 18 + ip_len + ip_len_len;
  memcpy(peer.bencoded + i, announce_data->peer_id, 20);
	sprintf(peer.bencoded + i + 20, "4:porti%dee", announce_data->port);

	// compact it, yo
	memcpy(peer.compact, &(announce_data->ip), 4);
	short network_peer_port = htons(announce_data->port);
	memcpy(peer.compact + 4, &network_peer_port, 2);
	unsigned long long now = (unsigned long long)time(0) * 1000;
	unsigned long long then = now - ANNOUNCE_INTERVAL * DROP_COUNT * 1000;
	redisAsyncCommand(redis, NULL, NULL, "MULTI");

	// prune out old entries (peers that haven't announced within DROP_COUNT announce intervals)
	dbg_info("Redis key: torrent:%s", announce_data->info_hash);
	redisAsyncCommand(redis, NULL, NULL, "ZREMRANGEBYSCORE torrent:%s:seeds 0 %llu", announce_data->info_hash, then);
	redisAsyncCommand(redis, NULL, NULL, "ZREMRANGEBYSCORE torrent:%s:peers 0 %llu", announce_data->info_hash, then);
	// used for complete and incomplete fields in response
	redisAsyncCommand(redis, NULL, NULL, "ZCARD torrent:%s:seeds", announce_data->info_hash);
	redisAsyncCommand(redis, NULL, NULL, "ZCARD torrent:%s:peers", announce_data->info_hash);

	announce_data->numwant = (announce_data->numwant <= 0 || announce_data->numwant > 50) ? 50 : announce_data->numwant;
	redisAsyncCommand(redis, NULL, NULL, "ZRANGE torrent:%s:seeds 0 %d", announce_data->info_hash, announce_data->numwant);
	redisAsyncCommand(redis, NULL, NULL, "ZRANGE torrent:%s:peers 0 %d", announce_data->info_hash, announce_data->numwant);

	if (announce_data->left == 0) {
		redisAsyncCommand(redis, NULL, NULL, "ZADD torrent:%s:seeds %llu %b", announce_data->info_hash, now, &peer, sizeof(peer));
	} else {
		redisAsyncCommand(redis, NULL, NULL, "ZADD torrent:%s:peers %llu %b", announce_data->info_hash, now, &peer, sizeof(peer));
	}

	if (announce_data->event == 1 ) {
		char *info_hash = (char*)malloc(sizeof(char)*41);
		memcpy(info_hash, announce_data->info_hash, 41);
		increment_completion_count(announce_data->socket_data, info_hash);
	}
	redisAsyncCommand(redis, send_announce_reply, announce_data, "EXEC");
}
Ejemplo n.º 6
0
gint
rspamd_stat_cache_redis_check (struct rspamd_task *task,
		gboolean is_spam,
		gpointer runtime)
{
	struct rspamd_redis_cache_runtime *rt = runtime;
	struct timeval tv;
	gchar *h;

	h = rspamd_mempool_get_variable (task->task_pool, "words_hash");

	if (h == NULL) {
		return RSPAMD_LEARN_INGORE;
	}

	double_to_tv (rt->ctx->timeout, &tv);

	if (redisAsyncCommand (rt->redis, rspamd_stat_cache_redis_get, rt,
			"HGET %s %s",
			rt->ctx->redis_object, h) == REDIS_OK) {
		rspamd_session_add_event (task->s, rspamd_redis_cache_fin, rt,
				rspamd_stat_cache_redis_quark ());
		event_add (&rt->timeout_event, &tv);
		rt->has_event = TRUE;
	}

	/* We need to return OK every time */
	return RSPAMD_LEARN_OK;
}
Ejemplo n.º 7
0
gint
rspamd_stat_cache_redis_learn (struct rspamd_task *task,
		gboolean is_spam,
		gpointer runtime)
{
	struct rspamd_redis_cache_runtime *rt = runtime;
	struct timeval tv;
	gchar *h;
	gint flag;

	h = rspamd_mempool_get_variable (task->task_pool, "words_hash");
	g_assert (h != NULL);

	double_to_tv (rt->ctx->timeout, &tv);
	flag = (task->flags & RSPAMD_TASK_FLAG_LEARN_SPAM) ? 1 : -1;

	if (redisAsyncCommand (rt->redis, rspamd_stat_cache_redis_set, rt,
			"HSET %s %s %d",
			rt->ctx->redis_object, h, flag) == REDIS_OK) {
		rspamd_session_add_event (task->s, rspamd_redis_cache_fin, rt,
				rspamd_stat_cache_redis_quark ());
		event_add (&rt->timeout_event, &tv);
		rt->has_event = TRUE;
	}

	/* We need to return OK every time */
	return RSPAMD_LEARN_OK;
}
Ejemplo n.º 8
0
void events::redis_read_callback(redisAsyncContext *context, void *reply, void *data) {
    auto _reply = static_cast<redisReply*>(reply);
    auto e_spec = static_cast<event_redis_watcher*>(data);

    e_spec->callback(context, _reply->element[1]->str);
    redisAsyncCommand(e_spec->context, redis_read_callback, data, "BLPOP %s 0 ", _reply->element[0]->str);
}
Ejemplo n.º 9
0
 void GatewayDataMgr::getGatewayProp(const std::string & gwid, QFuncObject * ptFuncObj) {
     //userportal would check user's gw ownship(include checking if gw registerd)
     //so here, we just get
     char tmp[128];
     sprintf(tmp, "%s:%s:%s", ISCRule::iot_gw_dbtag.c_str(), gwid.c_str(), ISCRule::iot_gwprop_dbtag.c_str());
     redisAsyncCommand(mPtRedisAC, queryGWPropCallback, ptFuncObj, "hgetall %s", tmp);
 }
Ejemplo n.º 10
0
/** \brief SCLogRedisWriteAsync() writes string to redis output in async mode
 *  \param file_ctx Log file context allocated by caller
 *  \param string Buffer to output
 */
static int SCLogRedisWriteAsync(LogFileCtx *file_ctx, const char *string, size_t string_len)
{
    SCLogRedisContext *ctx = file_ctx->redis;

    if (! ctx->connected) {
        if (SCConfLogReopenAsyncRedis(file_ctx) == -1) {
            return -1;
        }
        if (ctx->tried == 0) {
           SCLogNotice("Trying to connect to Redis");
        }
        SCLogAsyncRedisSendEcho(ctx);
    }

    if (!ctx->connected) {
        return -1;
    }

    if (ctx->async == NULL) {
        return -1;
    }

    redisAsyncCommand(ctx->async,
            SCRedisAsyncCommandCallback,
            file_ctx,
            "%s %s %s",
            file_ctx->redis_setup.command,
            file_ctx->redis_setup.key,
            string);

    event_base_loop(ctx->ev_base, EVLOOP_NONBLOCK);

    return 0;
}
Ejemplo n.º 11
0
int Stream_update (Stream_t *s,
                   char *field,
                   int value)
{
    char *message;

    if (strcmp(field, "frameLength") == 0) {
        s->frameLength = value;
    } else if (strcmp(field, "frameRate") == 0) {
        s->frameRate = value;
        double interval = 1.0 / value;
        time_t sec = (time_t) floor(interval);
        suseconds_t usec = (suseconds_t) floor((interval-sec) * 1e6);
        s->interval.tv_sec = sec;
        s->interval.tv_usec = usec;
    } else if (strcmp(field, "dimensions") == 0) {
        s->dimensions = value;
    } else return 1;

    redisAsyncCommand(s->redisContext, _onFreeMe, NULL,
        "HSET stream:%s %s %d",
        s->id, field, value
    );

    message = _super_print("{\"%s\":%d}", field, value);
    Stream_publishEvent(s, "update", message);
    free(message);

    return 0;
}
Ejemplo n.º 12
0
void delete_redis_keys(const char *key_pattern)
{
	redisAsyncContext *ac = defaultAsyncContext;
	if(ac) {
		redisAsyncCommand(ac, deleteKeysCallback, ac->ev.data, "keys %s", key_pattern);
	}
}
Ejemplo n.º 13
0
void terminate(void) {
	evtimer_del(&sspPollEvent);
	if(db) {
		redisAsyncCommand(db, NULL, NULL, "SET component:ssp 0");
		redisAsyncDisconnect(db);
		db = NULL;
	}
}
Ejemplo n.º 14
0
static void *redis_subscribe(void *args)
{
	struct cachefs *fs = (struct cachefs *)args;
	redisLibeventAttach(handle->async, handle->event_base);
	redisAsyncCommand(handle->async, on_subscribe_msg, fs, \
			"SUBSCRIBE %s", fs->redis_res_channel);
	event_base_dispatch(handle->event_base);
}
Ejemplo n.º 15
0
int main (int argc, char **argv) {
    signal(SIGPIPE, SIG_IGN);

    redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379);
    if (c->err) {
        /* Let *c leak for now... */
        printf("Error: %s\n", c->errstr);
        return 1;
    }

    redisLibevAttach(EV_DEFAULT_ c);
    redisAsyncSetConnectCallback(c,connectCallback);
    redisAsyncSetDisconnectCallback(c,disconnectCallback);
    redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1]));
    redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key");
    ev_loop(EV_DEFAULT_ 0);
    return 0;
}
Ejemplo n.º 16
0
void redis_disconnect_callback(const redisAsyncContext* c, int status)
{
    struct nbd_handle* handle;

    if (c->data)
    {
       handle = (struct nbd_handle*) c->data;
    }
    else
    {
        fprintf_light_red(stderr, "FATAL: Handle not passed to disconnect "
                                  "callback.\n");
        assert(c->data != NULL);
        return;
    }

    if (status != REDIS_OK)
    {
        if (c->err == REDIS_ERR_EOF) /* probably standard timeout, reconnect */
        {
            fprintf_red(stderr, "Redis server disconnected us.\n");
            if ((handle->redis_c = redisAsyncConnect(handle->redis_server,
                 handle->redis_port)) != NULL)
            {
                fprintf_blue(stderr, "New Redis context, attaching to "
                                    "libevent.\n");
                handle->redis_c->data = c->data;
                redisLibeventAttach(handle->redis_c, handle->eb);
                fprintf_blue(stderr, "Setting disconnect callback.\n");
                if (redisAsyncSetDisconnectCallback(handle->redis_c,
                    &redis_disconnect_callback) != REDIS_ERR)
                {
                    assert(redisAsyncCommand(handle->redis_c,
                           &redis_async_callback, NULL, "select %d",
                           handle->redis_db) == REDIS_OK);
                    fprintf_light_blue(stderr, "Successfully reconnected to "
                                               "the Redis server.\n");
                }
                else
                {
                    fprintf_light_red(stderr, "Error setting disconnect "
                                              "callback handler for Redis.\n");
                }
            }
            else
            {
                fprintf_light_red(stderr, "Error trying to reconnect to "
                                          "Redis.\n");
            }
            return;
        }
        fprintf_light_red(stderr, "FATAL ERROR DISCONNECTION FROM REDIS\n");
        fprintf_light_blue(stderr, "Error: %s\n", c->errstr);
        assert(false);
    }
}
Ejemplo n.º 17
0
static void issueRequest(client c) {
    int op = config.optab[random() % 100];
    long key, hashkey;
    unsigned long datalen;

    config.issued_requests++;
    if (config.issued_requests == config.num_requests) config.done = 1;

    c->start = microseconds();
    if (config.longtail) {
        key = longtailprng(0,config.keyspace-1,config.longtail_order);
        hashkey = longtailprng(0,config.hashkeyspace-1,config.longtail_order);
    } else {
        key = random() % config.keyspace;
        hashkey = random() % config.hashkeyspace;
    }

    c->keyid = key;
    c->reqtype = op;

    if (op == REDIS_IDLE) {
        /* Idle */
    } else if (op == REDIS_SET) {
        datalen = randomData(key);
        redisAsyncCommand(c->context,handleReply,NULL,"SET string:%ld %b",key,config.databuf,datalen);
    } else if (op == REDIS_GET) {
        redisAsyncCommand(c->context,handleReply,NULL,"GET string:%ld",key);
    } else if (op == REDIS_DEL) {
        redisAsyncCommand(c->context,handleReply,NULL,"DEL string:%ld list:%ld hash:%ld",key,key,key);
    } else if (op == REDIS_LPUSH) {
        datalen = randomData(key);
        redisAsyncCommand(c->context,handleReply,NULL,"LPUSH list:%ld %b",key,config.databuf,datalen);
    } else if (op == REDIS_LPOP) {
        redisAsyncCommand(c->context,handleReply,NULL,"LPOP list:%ld",key);
    } else if (op == REDIS_HSET) {
        datalen = randomData(key);
        redisAsyncCommand(c->context,handleReply,NULL,"HSET hash:%ld key:%ld %b",key,hashkey,config.databuf,datalen);
    } else if (op == REDIS_HGET) {
        redisAsyncCommand(c->context,handleReply,NULL,"HGET hash:%ld key:%ld",key,hashkey);
    } else if (op == REDIS_HGETALL) {
        redisAsyncCommand(c->context,handleReply,NULL,"HGETALL hash:%ld",key);
    } else if (op == REDIS_SWAPIN) {
        /* Only accepts a single argument, so for now only works with string keys. */
        redisAsyncCommand(c->context,handleReply,NULL,"DEBUG SWAPIN string:%ld",key);
    } else {
        assert(NULL);
    }
}
Ejemplo n.º 18
0
int main (int argc, char **argv) {
    signal(SIGPIPE, SIG_IGN);
    struct event_base *base = event_base_new();

    redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379);
    if (c->err) {
        /* Let *c leak for now... */
        printf("Error: %s\n", c->errstr);
        return 1;
    }

    redisLibeventAttach(c,base);
    redisAsyncSetConnectCallback(c,connectCallback);
    redisAsyncSetDisconnectCallback(c,disconnectCallback);
    redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1]));
    redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key");
    event_base_dispatch(base);
    return 0;
}
Ejemplo n.º 19
0
void events::onSubscribe(const string& key, 
                         function<void(redisAsyncContext*,
                                       const string& value)> callback) {
    auto e_spec = new event_redis_watcher;
    e_spec->context = this->redis;
    e_spec->callback = callback;
    redis_watchers.push_back(e_spec);
    
    redisAsyncCommand(this->redis_pubsub, redis_subscribe_callback, (void*) redis_watchers.back(), "SUBSCRIBE %s", key.c_str());
}
Ejemplo n.º 20
0
int main (int argc, char **argv) {
    signal(SIGPIPE, SIG_IGN);

    redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379);
    if (c->err) {
        /* Let *c leak for now... */
        printf("Error: %s\n", c->errstr);
        return 1;
    }

    loop = aeCreateEventLoop();
    redisAeAttach(loop, c);
    redisAsyncSetConnectCallback(c,connectCallback);
    redisAsyncSetDisconnectCallback(c,disconnectCallback);
    redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1]));
    redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key");
    aeMain(loop);
    return 0;
}
Ejemplo n.º 21
0
void func(const std::string& commandStr)
{
	g_SubscribeMutex.lock();
	struct event_base *m_base = event_base_new();

	redisAsyncContext *m_redis = redisAsyncConnect("127.0.0.1", 6379);
	if (m_redis->err) {
		/* Let *c leak for now... */
		printf("Error: %s\n", m_redis->errstr);
	}
	redisAsyncCommand(m_redis,authCallback, (char*) "auth", "auth %s", "014006");

	redisLibeventAttach(m_redis, m_base);
	redisAsyncSetConnectCallback(m_redis, connectCallback);
	redisAsyncSetDisconnectCallback(m_redis, disconnectCallback);

	redisAsyncCommand(m_redis, subscribeCallback, (char*) "sub", commandStr.c_str());
	g_SubscribeMutex.unlock();
	event_base_dispatch(m_base);
}
Ejemplo n.º 22
0
void events::onPop(const string& key,
                   function<void(redisAsyncContext*,
                                 const string& value)> callback,
                   int timeout) {
    auto e_spec = new event_redis_watcher;
    e_spec->context = this->redis;
    e_spec->callback = callback;
    redis_watchers.push_back(e_spec);
    
    redisAsyncCommand(this->redis, redis_read_callback, (void*) redis_watchers.back(), "BLPOP %s %d", key.c_str(), timeout);
};
Ejemplo n.º 23
0
 int RedisAsyncConn::Del(const string &key, redis_callback_t callback, void *callback_data) {
     if (m_state != CONNECTED) {
         return REDIS_ASYNC_CONN_ERR;
     }
     int ret = redisAsyncCommand(m_async_context, callback, callback_data, "DEL %b", key.c_str(), key.size());
     if (REDIS_OK != ret) {
         LOG(ERROR) << "RedisAsyncConn::Del(), key=" << key << ", error=" << m_async_context->errstr;
         return REDIS_ASYNC_CONN_ERR;
     }
     return REDIS_ASYNC_CONN_OK;
 }
Ejemplo n.º 24
0
/*Callback para sinalizar a conexao com o Redis*/
void connectCallback( const redisAsyncContext *c, int status ) {
    char subs[256] = {};
    strcpy(subs, "SUBSCRIBE ");
    strcat(subs, globalChannel );
    if (status != REDIS_OK ) {
	   printf("Error: %s\n", c->errstr);
	   exit( EXIT_FAILURE);
    }

   redisAsyncCommand(c, subCallback, (char*) "sub", subs);
}
Ejemplo n.º 25
0
void
redis_nginx_close_context(redisAsyncContext **context)
{
    if ((context != NULL) && (*context != NULL)) {
        redisAsyncContext *ac = *context;
        if (!ac->err) {
            redisAsyncCommand(ac, redis_nginx_ping_callback, NULL, PING_DATABASE_COMMAND);
        }
        *context = NULL;
    }
}
Ejemplo n.º 26
0
Stream_t* Stream_create (redisAsyncContext *c,
                         redisAsyncContext *subs,
                         char *id,
                         void (*callback)(Stream_t *))
{
    Stream_t *s;
    char *message;

    s = (Stream_t*) malloc(sizeof(Stream_t));
    if (s == NULL) return NULL;

    s->frameLength = 1;
    s->frameRate = 1;
    s->dimensions = 1;
    s->id = strdup(id);
    s->redisContext = c;
    s->onCreated = callback;
    s->onUpdated = NULL;
    s->onPolled = NULL;
    s->interval.tv_sec = 1;
    s->interval.tv_usec = 0;
    s->priv = NULL;

    redisAsyncCommand(c, _onFreeMe, NULL, "MULTI");
    redisAsyncCommand(c, _onFreeMe, NULL, "SADD stream %s", s->id);
    redisAsyncCommand(c, _onFreeMe, NULL,
        "HMSET stream:%s frameLength %d frameRate %d dimensions %d",
        s->id, s->frameLength, s->frameRate, s->dimensions
    );
    message = _super_print("{"
        "\"frameLength\": %d,"
        "\"frameRate\": %d,"
        "\"dimensions\": %d"
    "}", s->frameLength, s->frameRate, s->dimensions);
    Stream_publishEvent(s, "create", message);
    free(message);
    redisAsyncCommand(c, _onCreated, s, "EXEC");

    redisAsyncCommand(subs, _onMessage, s, "SUBSCRIBE stream:%s:feed", s->id);
    return s;
}
Ejemplo n.º 27
0
int Stream_sendFrame (Stream_t *s,
                      char *data,
                      size_t length)
{
    redisAsyncCommand(s->redisContext, _onFreeMe, NULL,
        "PUBLISH stream:%s:pipe %b",
        s->id, data, length
    );
    free(data);

    return 0;
}
Ejemplo n.º 28
0
    void GatewayDataMgr::cacheUpRInfoCallback(redisAsyncContext *c, void *r, void *privdata) {

        redisReply *reply = (redisReply *)r;
        if (reply == NULL) {

            LOG(ERROR)<<" -cacheUpRouterInfo: reply null";
            return;
        }

        LOG(TRACE)<<(char *)privdata<<" ret:"<<reply->str;
        redisAsyncCommand(c, expireUpRCacheCallback, NULL, "expire  %s %d", (char *)privdata, 30);
    }
Ejemplo n.º 29
0
gboolean
rspamd_redis_process_tokens (struct rspamd_task *task,
		GPtrArray *tokens,
		gint id, gpointer p)
{
	struct redis_stat_runtime *rt = REDIS_RUNTIME (p);
	rspamd_fstring_t *query;
	struct timeval tv;
	gint ret;

	if (tokens == NULL || tokens->len == 0 || rt->redis == NULL) {
		return FALSE;
	}

	rt->id = id;

	if (redisAsyncCommand (rt->redis, rspamd_redis_connected, rt, "HGET %s %s",
			rt->redis_object_expanded, "learns") == REDIS_OK) {

		rspamd_session_add_event (task->s, rspamd_redis_fin, rt,
				rspamd_redis_stat_quark ());
		rt->has_event = TRUE;

		if (event_get_base (&rt->timeout_event)) {
			event_del (&rt->timeout_event);
		}
		event_set (&rt->timeout_event, -1, EV_TIMEOUT, rspamd_redis_timeout, rt);
		event_base_set (task->ev_base, &rt->timeout_event);
		double_to_tv (rt->ctx->timeout, &tv);
		event_add (&rt->timeout_event, &tv);

		query = rspamd_redis_tokens_to_query (task, tokens,
				"HMGET", rt->redis_object_expanded, FALSE, -1,
				rt->stcf->clcf->flags & RSPAMD_FLAG_CLASSIFIER_INTEGER);
		g_assert (query != NULL);
		rspamd_mempool_add_destructor (task->task_pool,
				(rspamd_mempool_destruct_t)rspamd_fstring_free, query);

		ret = redisAsyncFormattedCommand (rt->redis, rspamd_redis_processed, rt,
				query->str, query->len);

		if (ret == REDIS_OK) {
			return TRUE;
		}
		else {
			msg_err_task ("call to redis failed: %s", rt->redis->errstr);
		}
	}

	return FALSE;
}
Ejemplo n.º 30
0
 int RedisAsyncConn::SetEX(const string &key, int timeout, const string &value,
         redis_callback_t callback, void *callback_data) {
     if (m_state != CONNECTED) {
         return REDIS_ASYNC_CONN_ERR;
     }
     int ret = redisAsyncCommand(m_async_context, callback, callback_data, "SETEX %b %d %b",
         key.c_str(), key.size(), timeout, value.c_str(), value.size());
     if (REDIS_OK != ret) {
         LOG(ERROR) << "RedisAsyncConn::SetEX(), key=" << key << ", timeout=" << timeout
             << ", error=" << m_async_context->errstr;
         return REDIS_ASYNC_CONN_ERR;
     }
     return REDIS_ASYNC_CONN_ERR;
 }