Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Donate
Please sign in before you donate.
Scan WeChat QR to Pay
Cancel
Complete
Prompt
Switch to Alipay.
OK
Cancel
1 Star 0 Fork 0

CandyPop/GateServer

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (1)
master
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
The license selected for the repository is subject to the license used by the main branch of the repository.
master
Branches (1)
master
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (1)
master
gate-server
/
GateServer.cpp
gate-server
/
GateServer.cpp
GateServer.cpp 4.48 KB
Copy Edit Raw Blame History
CandyPop authored 2024年10月13日 23:09 +08:00 . [UPDATE]增加redis验证码服务
#include <iostream>
#include <json/json.h>
#include <json/value.h>
#include <json/reader.h>
#include "CServer.h"
#include "ConfigMgr.h"
#include "RedisMgr.h"
void TestRedis() {
//连接redis 需要启动才可以进行连接
//redis默认监听端口为6387 可以再配置文件中修改
redisContext* c = redisConnect("127.0.0.1", 6379);
if (c->err)
{
printf("Connect to redisServer faile:%s\n", c->errstr);
redisFree(c); return;
}
printf("Connect to redisServer Success\n");
std::string redis_password = "123";
redisReply* r = (redisReply*)redisCommand(c, "AUTH %s", redis_password.c_str());
if (r->type == REDIS_REPLY_ERROR) {
printf("Redis认证失败!\n");
}
else {
printf("Redis认证成功!\n");
}
//为redis设置key
const char* command1 = "set stest1 value1";
//执行redis命令行
r = (redisReply*)redisCommand(c, command1);
//如果返回NULL则说明执行失败
if (NULL == r)
{
printf("Execut command1 failure\n");
redisFree(c); return;
}
//如果执行失败则释放连接
if (!(r->type == REDIS_REPLY_STATUS && (strcmp(r->str, "OK") == 0 || strcmp(r->str, "ok") == 0)))
{
printf("Failed to execute command[%s]\n", command1);
freeReplyObject(r);
redisFree(c); return;
}
//执行成功 释放redisCommand执行后返回的redisReply所占用的内存
freeReplyObject(r);
printf("Succeed to execute command[%s]\n", command1);
const char* command2 = "strlen stest1";
r = (redisReply*)redisCommand(c, command2);
//如果返回类型不是整形 则释放连接
if (r->type != REDIS_REPLY_INTEGER)
{
printf("Failed to execute command[%s]\n", command2);
freeReplyObject(r);
redisFree(c); return;
}
//获取字符串长度
int length = r->integer;
freeReplyObject(r);
printf("The length of 'stest1' is %d.\n", length);
printf("Succeed to execute command[%s]\n", command2);
//获取redis键值对信息
const char* command3 = "get stest1";
r = (redisReply*)redisCommand(c, command3);
if (r->type != REDIS_REPLY_STRING)
{
printf("Failed to execute command[%s]\n", command3);
freeReplyObject(r);
redisFree(c); return;
}
printf("The value of 'stest1' is %s\n", r->str);
freeReplyObject(r);
printf("Succeed to execute command[%s]\n", command3);
const char* command4 = "get stest2";
r = (redisReply*)redisCommand(c, command4);
if (r->type != REDIS_REPLY_NIL)
{
printf("Failed to execute command[%s]\n", command4);
freeReplyObject(r);
redisFree(c); return;
}
freeReplyObject(r);
printf("Succeed to execute command[%s]\n", command4);
//释放连接资源
redisFree(c);
}
void TestRedis1() {
/*assert(RedisMgr::GetInstance()->Connect("127.0.0.1", 6379));
assert(RedisMgr::GetInstance()->Auth("123"));*/
assert(RedisMgr::GetInstance()->Set("blogwebsite", "llfc.club"));
std::string value = "";
assert(RedisMgr::GetInstance()->Get("blogwebsite", value));
assert(RedisMgr::GetInstance()->Get("nonekey", value) == false);
assert(RedisMgr::GetInstance()->HSet("bloginfo", "blogwebsite", "llfc.club"));
assert(RedisMgr::GetInstance()->HGet("bloginfo", "blogwebsite") != "");
assert(RedisMgr::GetInstance()->ExistsKey("bloginfo"));
assert(RedisMgr::GetInstance()->Del("bloginfo"));
assert(RedisMgr::GetInstance()->Del("bloginfo"));
assert(RedisMgr::GetInstance()->ExistsKey("bloginfo") == false);
assert(RedisMgr::GetInstance()->LPush("lpushkey1", "lpushvalue1"));
assert(RedisMgr::GetInstance()->LPush("lpushkey1", "lpushvalue2"));
assert(RedisMgr::GetInstance()->LPush("lpushkey1", "lpushvalue3"));
assert(RedisMgr::GetInstance()->RPop("lpushkey1", value));
assert(RedisMgr::GetInstance()->RPop("lpushkey1", value));
assert(RedisMgr::GetInstance()->LPop("lpushkey1", value));
assert(RedisMgr::GetInstance()->LPop("lpushkey2", value) == false);
RedisMgr::GetInstance()->Close();
}
int main()
{
//TestRedis1();
//读取配置
auto & gCfgMgr = ConfigMgr::Inst();
std::string gate_port_str = gCfgMgr["GateServer"]["Port"];
unsigned short gate_port = atoi(gate_port_str.c_str());
try{
unsigned short port = gate_port;
//初始化上下文,默认1个线程
net::io_context ioc{ 1 };
//生成一个信号集
boost::asio::signal_set signals(ioc, SIGINT, SIGTERM);
//型号集异步等待,例如类似受到键盘上ctrl+c 这样的停止命令后,做出什么反应
signals.async_wait([&ioc](const boost::system::error_code& err,
int signal_number) {
if (err) {
return;
}
// 关闭ioc
ioc.stop();
});
std::make_shared<CServer>(ioc, port)->Start();
std::cout << "Server start at : " << port << std::endl;
// 开始轮询
ioc.run();
}
catch (std::exception const& e) {
std::cerr << "Error" << e.what() << std::endl;
return EXIT_FAILURE;
}
}
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

Releases

No release

Contributors

All

Language(Optional)

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/CandyPop/gate-server.git
git@gitee.com:CandyPop/gate-server.git
CandyPop
gate-server
GateServer
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /