2024年1月8日发(作者:)
DOC ID:KDSP_T_V4.0
第 1 页 共 8 页
金蝶云星空
分布式缓存使用说明书
修改记录
Ver. No
V1.0
V1.2
V1.3
发版日期
2017/12/08
2018/01/03
2018/02/24
编制人
刘兵
刘兵
刘兵
批准人
赖碧云
赖碧云
赖碧云
修改的章节号
初始版本
6.1.2
6.1
DOC ID:KDSP_T_V4.0
第 2 页 共 8 页
目 录
1.
概述 .................................................................................................................................... 3
1.1.
1.2.
1.3.
1.4.
目的 ............................................................................................................................................... 3
范围 ............................................................................................................................................... 3
适用对象 ....................................................................................................................................... 3
参考资料 ....................................................................................................................................... 3
2.
问题与解决策略 ................................................................................................................ 3
3.
目标和约束 ........................................................................................................................ 3
4.
部署Redis服务 ................................................................................................................. 4
4.1.
4.2.
4.3.
4.4.
4.5.
4.6.
安装服务 --service-install(安装必须的步骤) .............................................................................. 4
卸载服务 --service-uninstall ........................................................................................................ 4
启动服务 --service-start(安装必须的步骤) ................................................................................. 4
停止服务 --service-stop ............................................................................................................... 5
服务配置修改(服务名和端口) ............................................................................................... 5
Redis-cli配置(如果4.1按照2,3小点进行了修改,此节配置可以忽略) ............................. 5
5.
Redis配置文件修改................................................................................................... 5
6.
Redis缓存代码示例 .......................................................................................................... 6
6.1.1.
6.1.2.
写缓存和读缓存 ............................................................................................................. 6
错误的读写缓存 ............................................................................................................. 7
7.
附录 .................................................................................................................................... 8
DOC ID:KDSP_T_V4.0
第 3 页 共 8 页
1. 概述
1.1. 目的
为系统集群及分布式应用提供基础缓存服务。
1.2. 范围
➢ 适用版本:V6.2和后续版本
1.3. 适用对象
本文档适用于:
➢ 开发工程师:部署和开发指导。
➢ 实施人员:部署指导。
1.4. 参考资料
➢ Redis相关资料
2. 问题与解决策略
愿景
关注点
描述与示例
3. 目标和约束
目标:
➢
提供单据和基础数据的分布式缓存支持;
DOC ID:KDSP_T_V4.0
第 4 页 共 8 页
➢
提供系统参数、单据参数、用户参数等数据的分布式缓存支持;
➢
提供分布式缓存接口为其他类型数据提供分布式缓存支持
约束:
➢
分布式缓存开关并非默认开启;
➢
并非所有数据都使用了分布式缓存。
4. 部署Redis服务
首先进入到产品安装目录K3Cloud/website/bin,将以下文件单独拷贝到缓存服务器,新建一目录,例如Redis,拷贝文件如下:,,,,,,然后以管理员身份进入dos系统,将目录定位到Redis目录。如未说明,后续命令都在该目录下执行。
4.1. 安装服务 --service-install(安装必须的步骤)
This must be the first argument on the redis-server command line. Arguments after this are passed in the
order they occur to Redis when the service is launched. The service will be configured as Autostart and
will be launched as "NT AUTHORITYNetworkService". Upon successful installation a success message
will be displayed and Redis will exit.
This command does not start the service.
For instance:
redis-server --service-install --loglevel verbose
默认配置的地址是本地地址 127.0.0.1 端口是6379,如果多应用部署分布式缓存,需要在启动服务前先修改缓存服务器配置文件中的地址为具体的IP。
1) 打开配置文件,找到bind 127.0.0.1,修改IP为具体的IP地址,例如:bind 172.17.2.100
2) 打开配置文件,找到protected-mode yes 修改为protected-mode no
redis缓存服务和k3cloud不在一台服务器时,需要此项设置
3) 打开配置文件,找到stop-writes-on-bgsave-error no 修改为stop-writes-on-bgsave-error no
强制停止快照导致不能持久化错误处理
4.2. 卸载服务 --service-uninstall
This will remove the Redis service configuration information from the registry. Upon successful
uninstallation a success message will be displayed and Redis will exit.
This does command not stop the service.
For instance:
redis-server --service-uninstall
4.3. 启动服务 --service-start(安装必须的步骤)
This will start the Redis service. Upon successful start, a success message will be displayed and Redis will
DOC ID:KDSP_T_V4.0
第 5 页 共 8 页
begin running.
For instance:
redis-server --service-start
4.4. 停止服务 --service-stop
This will stop the Redis service. Upon successful termination a success message will be displayed and
Redis will exit.
For instance:
redis-server --service-stop
4.5. 服务配置修改(服务名和端口)
This optional argument may be used with any of the preceding commands to set the name of the
installed service. This argument should follow the service-install, service-start, service-stop or
service-uninstall commands, and precede any arguments to be passed to Redis via the service-install
command.
The following would install and start three separate instances of Redis as a service:
redis-server --service-install --service-name redisService1 --port 10001
redis-server --service-start --service-name redisService1
4.6. Redis-cli配置(如果4.1按照2,3小点进行了修改,此节配置可以忽略)
使用进行配置时,需要先双击打开(打开前如果之前已经启动了服务,先停止)
打开redis-server后,再双击打开在窗口依次输入以下配置指令:
1)config set protected-mode no
redis缓存服务和k3cloud不在一台服务器时,需要此项设置
2)config set stop-writes-on-bgsave-error no
强制停止快照导致不能持久化错误处理
5. Redis配置文件修改
在金蝶云星空website/app_data/文件中 :
端口号默认使用6379,可以配置多个缓存服务器,如果不想使用Redis缓存,则设置Swith="OFF",多应用服务器部署,需要明确Host的地址。
DOC ID:KDSP_T_V4.0
第 6 页 共 8 页
6. Redis缓存代码示例
6.1.1. 写缓存和读缓存
调用参考:
public CacheProcess GetCacheProcessByVersionId(Context ctx, string versionId)
{
IKCacheManager cacheMgr =
heManager(ey,
aCacheKey());
CacheProcess cacheProcess =
if (cacheProcess == null)
{
WorkflowModelRepository rep = new WorkflowModelRepository();
cacheProcess = ocess(ctx, versionId);
}
return cacheProcess;
}
注意:业务插件代码读写缓存的时候,如果是自己使用KCacheManagerFactory来管理缓存,则需要替换成RCacheManagerFactory,其他的如Put和Get的写法保持不变。使用CacheUtil的代码不需要处理,平台统一进行了处理。另外如果是循环从缓存读写数据,需要参考以下写法,否则可能引发性能问题,如果循环读取使用的是CacheUtil,则建议在循环外使用RCacheManagerFactory来管理缓存。
循环读写缓存示例:(重点关注红色注释)
// 使用using括起来,便于自动释放连接对象
using (IKCacheManager kcmger =
heManager(strUserParameterRegion,
aCacheKey()))
{
IRCacheManager rcmger = kcmger as IRCacheManager;
if (rcmger != null)
{
// SetConnectionCloseFlag,设置Redis连接不自动关闭,减少每次访问Redis都去重新建立连接的开销
nectionCloseFlag(false);
DOC ID:KDSP_T_V4.0
第 7 页 共 8 页
}
DynamicObjectCollection objs = eDynamicObject(ctx, sql, null,
null, , y());
if (objs != null && > 0)
{
//省略代码
foreach (DynamicObject item in objs)
{
//尝试从缓存取
long userId = (item["FUserId"].ToString());
string strCacheKey =
UserParameterCacheKey(userId, parameterFormId, parameterObjId,
RAMETER_KEY);
DynamicObject obj = (strCacheKey) as DynamicObject;
//省略代码
}
//清除所有用户参数缓存
string strUserId = "select FUserId from t_sec_user";
List
ue
foreach (long userid in userIds)
{
(UserParameterCacheKey(userid,
parameterFormId, parameterObjId, RAMETER_KEY));
}
}
6.1.2. 错误的读写缓存
IKCacheManager kcmgr = heManager(region,
);
if (null != kcmgr)
{
try
{
(key, value);
}
catch { }
}
}
以上代码两处需要调整:
1、
KCacheManagerFactory改成RCacheManagerFactory
DOC ID:KDSP_T_V4.0
第 8 页 共 8 页
2、
应该使用aCacheKey
7. 附录


发布评论