4 Star 3 Fork 4

Gitee 极速下载/Tiny-httpd

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/Huangtuzhi/Tinyhttpd
克隆/下载
database.cpp 1.52 KB
一键复制 编辑 原始数据 按行查看 历史
Huangtuzhi 提交于 10年前 . a
#include "database.h"
#include <iostream>
#include <sstream>
Database::Database(int port, std::string ip): m_ip(ip), m_port(port)
{
context = redisConnect(m_ip.data(), m_port);
if (context!=NULL && context->err)
std::cout << "Error: %s\n" << context->errstr;
else
std::cout << "Database connected\n";
}
void Database::recordIP(int vistor, std::string time, std::string ip, int port, std::string agent)
{
std::stringstream ss;
std::string vistor_s;
ss << vistor;
ss >> vistor_s;
std::string _vistor = std::string("vistor:") + vistor_s;
std::cout << _vistor.data() << std::endl;
reply = (redisReply*)redisCommand(context, "HMSET %s time %s ip %s port %d agent %s", _vistor.data(), time.data(), ip.data(), port, agent.data());
std::cout << "ERROE INFO: " << reply->str << std::endl;
freeReplyObject(reply);
}
std::string Database::readIP(int vistor)
{
std::stringstream ss;
std::string vistor_s;
ss << vistor;
ss >> vistor_s;
std::string _vistor = std::string("vistor:") + vistor_s;
std::string buffer;
reply = (redisReply*)redisCommand(context, "HMGET %s time ip port", _vistor.data());
if (reply->type == REDIS_REPLY_ARRAY) {
if(reply->element[0]->str == NULL)
return "";
for (unsigned int j = 0; j < reply->elements; j++) {
buffer += std::string(reply->element[j]->str) + " ";
}
}
return buffer;
}
Database::~Database()
{
redisFree(context);
std::cout << "~Database() Called" << std::endl;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C/C++
1
https://gitee.com/mirrors/Tiny-httpd.git
git@gitee.com:mirrors/Tiny-httpd.git
mirrors
Tiny-httpd
Tiny-httpd
master

搜索帮助