// ends static void on_log_exit(int signo) { log_flush(); log_clear(); redis_close(&redis); exit(0); }
static void on_disconnect(redis_conn *conn,int32_t err) { redis_client = NULL; if(err != EACTCLOSE) redis_close(conn); printf("redis client on_disconnect\n"); }
int SimpleRedisClient::reconect() { if(debug > 1) printf("\x1b[31mredis reconect[%s:%d]\x1b[0m\n", host, port); redis_close(); if(!redis_conect()) { return false; } if(lastAuthPw != NULL ) { printf("\x1b[31mredis reconect lastAuthPw=%s\x1b[0m\n", lastAuthPw); if(redis_send( RC_INLINE, "AUTH %s\r\n", lastAuthPw)) { return false; } } if(lastSelectDBIndex != 0 ) { if( !selectDB(lastSelectDBIndex) ) { return false; } } return true; }
SimpleRedisClient::~SimpleRedisClient() { redis_close(); if(buffer != NULL) { delete[] buffer; } if(buf != NULL) { delete[] buf; } buffer_size = 0; if(host != 0) { delete[] host; } if(lastAuthPw != NULL) { delete[] lastAuthPw; } }
int rediscsvmodule_close(UNUSED struct state_conf* c, UNUSED struct state_send *s, UNUSED struct state_recv *r) { if (rediscsvmodule_flush()) { return EXIT_FAILURE; } if (redis_close()) { return EXIT_FAILURE; } return EXIT_SUCCESS; }
static PHP_METHOD(swoole_redis, close) { swRedisClient *redis = swoole_get_object(getThis()); if (redis && redis->context && redis->state != SWOOLE_REDIS_STATE_CLOSED) { if (redis->connecting) { SwooleG.main_reactor->defer(SwooleG.main_reactor, redis_close, redis); } else { redis_close(redis); } } }
struct bbs_msgbuf* log_rcv(int msqid) { static char buf[1024]; struct bbs_msgbuf *msg = (struct bbs_msgbuf *) buf; // grab memory from message queue int retv = msgrcv(msqid, msg, sizeof(buf) - sizeof(msg->mtype) - 2, 0, MSG_NOERROR); while (retv < 0) { fprintf (stderr, "msgrcv failed: %s\n", strerror(errno)); // restart if (errno == EINTR) { retv = msgrcv(msqid, msg, sizeof(buf) - sizeof(msg->mtype) - 2, 0, MSG_NOERROR); } else { bbslog("3error", "bbslogd(rcvlog):%s", strerror(errno)); return NULL; } } if (debug) fprintf (stderr, "msgrcv returned: %d\n", retv); retv -= (char*)msg->mtext - (char*)&msg->msgtime; // Add new line for real logs switch (msg->mtype) { case BBSLOG_POST: case BBSLOG_DELETE: case BBSLOG_UPDATE: case BBSLOG_READ: break; default: while (retv > 0 && msg->mtext[retv - 1] == 0) retv--; if (retv == 0) return NULL; if (msg->mtext[retv - 1] != '\n') { msg->mtext[retv] = '\n'; retv++; } msg->mtext[retv] = 0; return msg; } // guard if (msg->mtype == BBSLOG_POST && retv <= sizeof(struct _new_postlog)) return NULL; // forward and publish to redis int retries = 0; while (retries < 4) { // check connection condition if (!redis.con || redis.con->err) { fprintf (stderr, "Trying to reconnect to redis: %d\n", retries); ++retries; redis_close(&redis); redis_open(&redis); continue; } const int message_len = 64; char message[message_len]; const char *argv[3] = { "PUBLISH", NULL, message }; struct _new_postlog *ppl; // set command switch (msg->mtype) { case BBSLOG_POST: ppl = (struct _new_postlog*)(&msg->mtext[1]) ; argv[1] = "event:post"; snprintf(message, message_len, "%lu:%s:%lu", (unsigned long)msg->msgtime, ppl->boardname, (unsigned long)ppl->articleid); break; case BBSLOG_DELETE: argv[1] = "event:delete"; snprintf(message, message_len, "%lu:%s:%lu", (unsigned long)msg->msgtime, msg->mtext, (unsigned long)msg->pid); break; case BBSLOG_UPDATE: argv[1] = "event:update"; snprintf(message, message_len, "%lu:%s:%lu", (unsigned long)msg->msgtime, msg->mtext, (unsigned long)msg->pid); break; case BBSLOG_READ: argv[1] = "event:read"; argv[2] = msg->mtext; break; } // send command redisReply *reply = redisCommandArgv(redis.con, 3, argv, NULL); // check result of redisCommand if (reply == NULL) { bbslog("3error", "bbslogd(log_rcv) redisCommand %s", redis.con->errstr); continue; } if (debug) fprintf (stderr, "published\n"); if (reply->type == REDIS_REPLY_ERROR) { bbslog("3error", "bbslogd(log_rcv) redisCommand error %s", reply->str); redis_close(&redis); freeReplyObject(reply); continue; } if (reply->type == REDIS_REPLY_INTEGER) fprintf (stderr, "redisCommand: %d\n", (int)reply->integer); freeReplyObject(reply); return msg; } return msg; }