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); }
int main(int argc, char **argv) { REDIS redis; REDIS_INFO info; int rc; redis = credis_connect(NULL, 9999, 10000); if (redis == NULL) { printf("Error connecting to Redis server. Please start server to run tests.\n"); exit(1); } printf("Testing a number of credis functions. To perform a simplistic set-command\n"\ "benchmark, run: `%s <num>' where <num> is the number\n"\ "of set-commands to send.\n\n", argv[0]); printf("\n\n************* misc info ************************************ \n"); rc = credis_ping(redis); printf("ping returned: %d\n", rc); rc = credis_info(redis, &info); printf("info returned %d\n", rc); printf("> redis_version: %s\n", info.redis_version); printf("> arch_bits: %d\n", info.arch_bits); printf("> multiplexing_api: %s\n", info.multiplexing_api); printf("> process_id: %ld\n", info.process_id); printf("> uptime_in_seconds: %ld\n", info.uptime_in_seconds); printf("> uptime_in_days: %ld\n", info.uptime_in_days); printf("> connected_clients: %d\n", info.connected_clients); printf("> connected_slaves: %d\n", info.connected_slaves); printf("> blocked_clients: %d\n", info.blocked_clients); printf("> used_memory: %zu\n", info.used_memory); printf("> used_memory_human: %s\n", info.used_memory_human); printf("> changes_since_last_save: %lld\n", info.changes_since_last_save); printf("> bgsave_in_progress: %d\n", info.bgsave_in_progress); printf("> last_save_time: %ld\n", info.last_save_time); printf("> bgrewriteaof_in_progress: %d\n", info.bgrewriteaof_in_progress); printf("> total_connections_received: %lld\n", info.total_connections_received); printf("> total_commands_processed: %lld\n", info.total_commands_processed); printf("> expired_keys: %lld\n", info.expired_keys); printf("> hash_max_zipmap_entries: %zu\n", info.hash_max_zipmap_entries); printf("> hash_max_zipmap_value: %zu\n", info.hash_max_zipmap_value); printf("> pubsub_channels: %ld\n", info.pubsub_channels); printf("> pubsub_patterns: %u\n", info.pubsub_patterns); printf("> vm_enabled: %d\n", info.vm_enabled); printf("> role: %d\n", info.role); printf("\n\n************* sets ************************************ \n"); rc = credis_sadd(redis, "fruits", "banana"); printf("sadd returned: %d\n", rc); rc = credis_sadd(redis, "fruits", "apple"); printf("sadd returned: %d\n", rc); credis_close(redis); return 0; }
static switch_status_t redis_factory(REDIS *redis) { if (!((*redis) = credis_connect(globals.host, globals.port, globals.timeout))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't connect to redis server at %s:%d timeout:%d\n", globals.host, globals.port, globals.timeout); return SWITCH_STATUS_FALSE; } return SWITCH_STATUS_SUCCESS; }
//----------------------------------------------------------------------------- CRedisClient::CRedisClient( std::string hostname, int port ) { mHostName = hostname; mPort = port; mRedisCon = credis_connect(hostname.c_str(), port, REDIS_TIMEOUT); if (mRedisCon == NULL) PRT_ERR2("Failed to connect to Redis server at %s:%d", mHostName.c_str(), mPort); }
int ZRedis::connect( const char *host) { m_pRedis = credis_connect(host, 0, 10000); if(m_pRedis == NULL) { printf("Connect DB failed, db ip = %s\n", host); } memset(m_charBuf,'\0',CHARSIZE); return m_pRedis != NULL ? true : false; }
/* * Connect to the redis server. If the passed server struct is uninitialize it * will be allocated prior to connection. * Returns PR_CONN if connection succeeded, else PR_FAILED */ static int redis_connect(void) { if (!pgredis) return PR_FAIL; if (pgredis->redis_server != NULL) return PR_CONN; pgredis->redis_server = credis_connect((pgredis->server ? pgredis->server : PR_DEFAULT_HOST), (pgredis->port > 0 ? pgredis->port : PR_DEFAULT_PORT), 2000); return (pgredis->redis_server != NULL ? PR_CONN : PR_FAIL); }
static ErlDrvData start(ErlDrvPort port, char* cmd) { //TODO handle connection errors; REDIS redis = credis_connect(NULL, 0, 10000); redis_drv_t* retval = (redis_drv_t*) driver_alloc(sizeof(redis_drv_t)); retval->port = port; retval->redis = redis; return (ErlDrvData) retval; }
const fexp* db_connect(closure* c, db* self) { if ((self->handle == NULL) || (credis_ping(self->handle) != 0)) { self->handle = credis_connect("localhost", 6379, 2000); // TODO - get redis DB address from config } // check connection if ((self->handle == NULL) || (credis_ping(self->handle) != 0)) { // TODO - try to start up redis server return (fexp*)send(VillageBus, s_villagebus_error, L"Could not connect to redis server"); } return fexp_nil; }
static int redis_read (void) /* {{{ */ { redis_node_t *rn; for (rn = nodes_head; rn != NULL; rn = rn->next) { REDIS rh; REDIS_INFO info; int status; DEBUG ("redis plugin: querying info from node `%s' (%s:%d).", rn->name, rn->host, rn->port); rh = credis_connect (rn->host, rn->port, rn->timeout); if (rh == NULL) { ERROR ("redis plugin: unable to connect to node `%s' (%s:%d).", rn->name, rn->host, rn->port); continue; } if (strlen (rn->passwd) > 0) { DEBUG ("redis plugin: authenticanting node `%s' passwd(%s).", rn->name, rn->passwd); status = credis_auth(rh, rn->passwd); if (status != 0) { WARNING ("redis plugin: unable to authenticate on node `%s'.", rn->name); credis_close (rh); continue; } } memset (&info, 0, sizeof (info)); status = credis_info (rh, &info); if (status != 0) { WARNING ("redis plugin: unable to get info from node `%s'.", rn->name); credis_close (rh); continue; } /* typedef struct _cr_info { * char redis_version[CREDIS_VERSION_STRING_SIZE]; * int bgsave_in_progress; * int connected_clients; * int connected_slaves; * unsigned int used_memory; * long long changes_since_last_save; * int last_save_time; * long long total_connections_received; * long long total_commands_processed; * int uptime_in_seconds; * int uptime_in_days; * int role; * } REDIS_INFO; */ DEBUG ("redis plugin: received info from node `%s': connected_clients = %d; " "connected_slaves = %d; used_memory = %lu; changes_since_last_save = %lld; " "bgsave_in_progress = %d; total_connections_received = %lld; " "total_commands_processed = %lld; uptime_in_seconds = %ld", rn->name, info.connected_clients, info.connected_slaves, info.used_memory, info.changes_since_last_save, info.bgsave_in_progress, info.total_connections_received, info.total_commands_processed, info.uptime_in_seconds); redis_submit_g (rn->name, "current_connections", "clients", info.connected_clients); redis_submit_g (rn->name, "current_connections", "slaves", info.connected_slaves); redis_submit_g (rn->name, "memory", "used", info.used_memory); redis_submit_g (rn->name, "volatile_changes", NULL, info.changes_since_last_save); redis_submit_d (rn->name, "total_connections", NULL, info.total_connections_received); redis_submit_d (rn->name, "total_operations", NULL, info.total_commands_processed); credis_close (rh); } return 0; }
int main(int argc, char **argv) { REDIS redis; REDIS_INFO info; char *val, **valv; const char *keyv[] = {"kalle", "adam", "unknown", "bertil", "none"}; int rc, keyc=5, i; redis = credis_connect(NULL, 0, 10000); if (redis == NULL) { printf("Error connecting to Redis server. Please start server to run tests.\n"); exit(1); } printf("\n\n************* misc info ************************************ \n"); rc = credis_info(redis, &info); printf("info returned %d\n", rc); printf("> redis_version: %s\n", info.redis_version); printf("> arch_bits: %d\n", info.arch_bits); printf("> multiplexing_api: %s\n", info.multiplexing_api); printf("> process_id: %ld\n", info.process_id); printf("> uptime_in_seconds: %ld\n", info.uptime_in_seconds); printf("> uptime_in_days: %ld\n", info.uptime_in_days); printf("> connected_clients: %d\n", info.connected_clients); printf("> connected_slaves: %d\n", info.connected_slaves); printf("> blocked_clients: %d\n", info.blocked_clients); printf("> used_memory: %zu\n", (size_t)info.used_memory); printf("> used_memory_human: %s\n", info.used_memory_human); printf("> changes_since_last_save: %lld\n", info.changes_since_last_save); printf("> bgsave_in_progress: %d\n", info.bgsave_in_progress); printf("> last_save_time: %ld\n", info.last_save_time); printf("> bgrewriteaof_in_progress: %d\n", info.bgrewriteaof_in_progress); printf("> total_connections_received: %lld\n", info.total_connections_received); printf("> total_commands_processed: %lld\n", info.total_commands_processed); printf("> expired_keys: %lld\n", info.expired_keys); printf("> hash_max_zipmap_entries: %zu\n", (size_t)info.hash_max_zipmap_entries); printf("> hash_max_zipmap_value: %zu\n", (size_t)info.hash_max_zipmap_value); printf("> pubsub_channels: %ld\n", info.pubsub_channels); printf("> pubsub_patterns: %u\n", info.pubsub_patterns); printf("> vm_enabled: %d\n", info.vm_enabled); printf("> role: %d\n", info.role); printf("\n\n************* get/set ************************************ \n"); rc = credis_set(redis, "kalle", "kula"); printf("set kalle=kula returned: %d\n", rc); rc = credis_get(redis, "kalle", &val); printf("get kalle returned: %s\n", val); rc = credis_type(redis, "someunknownkey"); printf("get type unknown key returned: %d\n", rc); rc = credis_type(redis, "kalle"); printf("get type known key returned: %d\n", rc); rc = credis_getset(redis, "kalle", "buhu", &val); printf("get set kalle=buhu returned: %s\n", val); rc = credis_get(redis, "kalle", &val); printf("get kalle returned: %s\n", val); rc = credis_del(redis, "kalle"); printf("del kalle returned: %d\n", rc); rc = credis_get(redis, "kalle", &val); printf("get kalle returned: %s\n", val); rc = credis_set(redis, "adam", "aaa"); rc = credis_set(redis, "bertil", "bbbbbbb"); rc = credis_set(redis, "caesar", "cccc"); rc = credis_get(redis, "adam", &val); printf("get adam returned: %s\n", val); rc = credis_get(redis, "bertil", &val); printf("get bertil returned: %s\n", val); rc = credis_get(redis, "caesar", &val); printf("get caesar returned: %s\n", val); rc = credis_mget(redis, keyc, keyv, &valv); printf("mget returned: %d\n", rc); for (i = 0; i < rc; i++) printf(" % 2d: %s\n", i, valv[i]); credis_close(redis); return 0; }