Code Monkey home page Code Monkey logo

Comments (4)

zhengshuxin avatar zhengshuxin commented on May 10, 2024

请把主要代码也贴一下吧,另外,同一个 redis 命令对象(即从 acl::redis_command 继承的子类对象不能跨线程操作),可以通过 acl::redis_client_cluster(网络连接)同一类对象用在多线程中。

from acl.

nicelogic avatar nicelogic commented on May 10, 2024

实际调用函数:
BOOL32 LoadScriptContent(const char* pchScriptContent, string& strSHA)
{
AUTOLOCK;
if (!m_pcRedis) return FALSE;
acl::string strSHA1;
const bool bResult = m_pcRedis->script_load(pchScriptContent, strSHA1);
if (!bResult)
{
OspPrintf(TRUE, FALSE, "[fail] [%s]Load Script content %s Failed!\n", FUNCTION, pchScriptContent);
return bResult;
}
}

封装构造类:
class CRedisImpl
{
public:
CRedisImpl()
{
m_bLogEnable = FALSE;
m_pcRedis = new acl::redis();
}
~CRedisImpl()
{
if (m_bLogEnable)
{
acl::log::close();
}

	if (m_pcRedis->get_client() != NULL)
	{
		delete m_pcRedis->get_client();
	}
	delete m_pcRedis;
}

BOOL32 Init(const s8* pchIp, u16 wPort, const s8* pchPwd = NULL)
{
	AUTOLOCK;
	acl::acl_cpp_init();

	s8 achAddr[30] = { 0 };
	sprintf(achAddr, "%s:%d", pchIp, wPort);
	acl::redis_client* pRedisClient = new acl::redis_client(achAddr);
	if (pchPwd != NULL)
	{
		pRedisClient->set_password(pchPwd);
	}
	m_pcRedis->set_client(pRedisClient);
	return TRUE;
}

private:
OspLock m_cLock;
acl::redis* m_pcRedis;
};

我们的程序是 初始化的时候,直接在堆上构造的acl::redis对象
然后后续的使用基本上是在同一线程里实际使用(load的时候是主线程Load)

from acl.

zhengshuxin avatar zhengshuxin commented on May 10, 2024

最好是你写一个简单而又完整的例子测测。

from acl.

nicelogic avatar nicelogic commented on May 10, 2024

自检发现,自身程序锁保护没做好,存在线程安全问题

from acl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.