81 lines
1.5 KiB
C++
81 lines
1.5 KiB
C++
#ifndef __DBREDIS_H
|
|
#define __DBREDIS_H
|
|
|
|
#include <QtSql>
|
|
|
|
|
|
class DBRedis
|
|
{
|
|
public:
|
|
DBRedis();
|
|
~DBRedis();
|
|
/***
|
|
* @描述 : 设定值
|
|
* @入参 : key 键
|
|
value 值
|
|
expiry 单位为秒 默认为 0
|
|
0 为永不过期
|
|
其他值必须大于0
|
|
* @输出 : 无
|
|
* @返回 : 0 成功
|
|
1 数据库错误
|
|
3 数据库错误
|
|
*/
|
|
static int setData(const QString&key, const QString&value, uint32_t expiry = 0);
|
|
|
|
|
|
|
|
/***
|
|
* @描述 : 获取值
|
|
* @入参 : key 键
|
|
* @输出 : value 值
|
|
* @返回 : 0 成功
|
|
1 数据库错误
|
|
2 不存在该数据或已过期
|
|
3 数据库错误
|
|
*/
|
|
static int getData(const QString&key, QString&value);
|
|
|
|
|
|
/***
|
|
* @描述 : 删除值
|
|
* @入参 : key 键
|
|
* @输出 : 无
|
|
* @返回 : 0 成功
|
|
1 数据库错误
|
|
3 数据库错误
|
|
*/
|
|
static int deleteData(const QString&key);
|
|
private:
|
|
static QSqlDatabase m_DataBase;
|
|
static QString m_ConnectName;
|
|
static bool m_HasInit;
|
|
private:
|
|
/***
|
|
* @描述 : 初始化
|
|
* @入参 : 无
|
|
* @输出 : 无
|
|
* @返回 : 0 成功
|
|
1 数据库错误
|
|
3 数据库错误
|
|
*/
|
|
static int init();
|
|
|
|
|
|
/***
|
|
* @描述 : 删除过期的条目
|
|
* @入参 : 无
|
|
* @输出 : 无
|
|
* @返回 : 0 成功
|
|
1 数据库错误
|
|
3 数据库错误
|
|
*/
|
|
static int deleteExpiredEntries();
|
|
};
|
|
|
|
|
|
|
|
#endif // !__DBREDIS_H
|
|
|
|
|