여러가지 목표중 가장 만만한 패킷 코드 자동 생성을 완료했다. 하는 동안 떠오른 할것도 추가하자.

  • RedisConnectionPool
  • 회원가입, 로그인 로직 구체적으로 정리 및 구현
  • SQL쿼리 바인더
    현재는 sql인젝션에 취약한 상태임
  • 비밀번호 해싱과 관리
  • 타이머 관리
    타이머를 만들긴 했는데 사용이 불편하고, 적절한 해제방법은 구현하지 않았음
  • 이메일 API 사용
  • 너무 느린 빌드 문제 해결하기
  • Client/Server PacketHandler.h 코드 자동생성 기능 만들기
    게임서버강의에서 배운 Protocol.proto 파일을 파싱해서 패킷핸들러 헤더를 자동으로 만들어주는 프로그램을 만들자.

이번엔 redis연결작업을 해보자.


Redis 공부

Redis란? + Redis 사용해보기

 

Redis

도커 redis:8.2.4 컨테이너 환경에서 작성된 게시글입니다.유튜브 채널 JSCODE의 강의를 보며 공부한걸 정리한 게시글입니다.Redis 란?짱빠른 nosql 데이터베이스. 모든 데이터를 메모리에 저장하기때

dodontak.tistory.com

 

hiredis 라이브러리 사용하기

 

hiredis with.C/C++

debian:trixie 환경에서 공부하며 작성한 게시글입니다.ai의 도움을 받아 공부하며 작성한 게시글입니다. 여기선 hiredis 라이브러리의 사용만 다루기때문에 redis는 아래 게시글에서 알아보자. Redis도

dodontak.tistory.com

RedisConnection

우선 간략한 형태로 만들었다.

#pragma once

#include <hiredis.h>
#include <string>

class RedisConnection
{
public:
	RedisConnection() {}
	~RedisConnection();

	bool		Connect(const char* ip, int port);
	redisReply*	Execute(std::string query);
private:
	redisContext*	_connection = nullptr;
};
#include "RedisConnection.h"
#include <iostream>

RedisConnection::~RedisConnection()
{
	if(_connection)
		redisFree(_connection);
}

bool	RedisConnection::Connect(const char* ip, int port)
{
	_connection = redisConnect(ip, port);
	if (_connection == NULL || _connection->err) {
		if (_connection != NULL)
			std::cout << _connection->errstr << '\n';
		else
			std::cout << "Can't allocate redis context\n";
		return false;
	}
	return true;
}

redisReply*	RedisConnection::Execute(std::string query)
{
	return	(redisReply *)redisCommand(_connection, query.c_str());
}

ConnectionPool

DBConnectionPool에 postgres 풀과 함께 배치했다. 이름이 헷갈려서 postgres 관련 네이밍이 원래 DB~~ 였는데 PG로 변경했다.

class DBConnectionPool
{
public:
	DBConnectionPool() {}
	~DBConnectionPool() {}

	bool	Init(int maxRedis, const char* redisIp, int redisPort,
					int maxPostgres, const char* pgConString);

	void	Push(PGConnection* conn);
	void	Push(RedisConnection* conn);


	PGConnection*		PopPG();
	RedisConnection*	PopRedis();
private:
	std::mutex						_mPostgres;
	int								_maxPostgres;
	std::string						_pgConString;

	std::mutex						_mRedis;
	int								_maxRedis;
	std::string						_redisIp;
	int								_redisPort;

	std::vector<PGConnection*>		_postgresConnections;
	std::vector<RedisConnection*>	_redisConnections;
};

레디스 커넥션 풀 만드는건 별거 없었는데 갑자기 vscode로 컨테이너에 접속해서 사용할 때만 자동완성이 안돼서 그걸 고치는데 시간을 너무 많이 썼다. 구글링, gpt, 제미나이, 클로드, 코파일럿 다 찾아봐도 해결이 안돼서 포기하려다 아주 옛날 글을 보고 해결했는데, 원인은 그냥 버그 라고 한다.... 심지어 제대로 해결된것도 아니고 원래의 자동완성보다 훨씬 질이 떨어졌다. 제대로 해결하려면 vscode의 intellisence에 대해 제대로 공부해야 할 것 같다.

 

Why is visual studio code telling me that cout is not a member of std namespace?

I am trying to setup visual studio code to program in c++. I have already installed the extensions C/C++ and C/C++ Intellisense Following is my code: #include<iostream> using namespace std;...

stackoverflow.com

 

'프로젝트 > Project_Island' 카테고리의 다른 글

18. 회원가입  (0) 2026.03.10
17. Session, EpollEvent 포인터 참조 문제 해결  (0) 2026.03.09
15. 패킷 자동화 (2)  (0) 2026.03.08
14. 패킷 자동화 (1)  (0) 2026.03.08
13. DummyClient <-> AuthServer 통신  (0) 2026.03.07

+ Recent posts