示例#1
0
static ngx_int_t 
ngx_xlog_redis_header_filter(ngx_http_request_t *r)
{
	ngx_log_redis_loc_conf_t  *conf;
	int rc = 0;
	char ttm[32];

    conf = (ngx_log_redis_loc_conf_t  *)ngx_http_get_module_loc_conf
		(r, ngx_xlog_redis);
	if (conf == NULL)
		return ngx_http_next_header_filter(r);
		
	if (redis == NULL) {
		redis = credis_connect(NULL, 0, 10000);
	
		if (redis == NULL) {
			return ngx_http_next_header_filter(r); 
		}
	}
	ngx_log_debug(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 
			"ngx_log_redis_header_filter:%s", conf->xlog_redis.data);
	snprintf(ttm, sizeof(ttm), "%d", (int)time(NULL));	
	rc = credis_lpush(redis, "xlog_redis", ttm);	
	//rc = credis_hset();
	rc = rc;
	if (r != r->main) {
		return ngx_http_next_header_filter(r);  
	} 

	r->headers_out.content_length_n += sizeof("Nginx-HelightXu\n") - 1;  
	credis_close(redis);
	
	return ngx_http_next_header_filter(r);  
}
示例#2
0
文件: mod_db.c 项目: mcellos/afrimesh
const fexp* db_lpush(closure* c, db* self, const fexp* message, const unsigned char* data)
{
  fexp* reply = fexp_nil;

  string* key  = (string*)send(message, s_fexp_join, self->delimiter);  // generate a key from message
  wprintl(L"POST /db/lpush/%S %s\n", key->buffer, data);

  char* keyc = (char*)send(key, s_string_tochar); // TODO - redis not support UNICODE so much
  const unsigned char* fixed = fix_timestamps(data);
  if (credis_lpush(self->handle, keyc, fixed) != 0) {
    reply = (fexp*)send(VillageBus, s_villagebus_error, L"lpush failed %s: %s", keyc, data);
  }
  free(keyc);

  return reply;
}