多活高可用服务 MAS
多活高可用服务 MAS
- 最新动态
- 功能总览
- 产品介绍
- 计费说明
- 快速入门
-
用户指南
- 开始使用多活高可用服务
- 功能模块
- 命名空间
- 多活管理
- 应用管理
- 监控管理
-
工作流管理
- 工作流简介
- 工作流模板
- 创建工作流
- 编排工作流
- 导入工作流
-
工作流插件说明
- DRS灾备切换
- DRS检查RTO&RPO
- RDS实例读写设置
- RDS实例重启
- RDS实例创建备份
- DWS检查容灾任务
- DWS容灾操作
- DCS开启/关闭白名单
- OBS桶存量比较
- OBS跨区域复制任务设置
- OBS桶策略操作授权用户
- DNS添加记录集
- DNS删除记录集
- DNS公网域名记录集权重设置
- Smart Connect任务操作
- 人工卡点
- 等待
- AOM作业执行
- 混沌实验执行
- PerfTest测试任务启动/停止
- HTTP请求
- MAS多活管理切换/回切
- DDM实例创建备份
- DDM实例读写设置
- RDS实例指定用户读写设置
- RDS检查容灾复制状态
- RDS灾备实例升主
- RDS修改实例参数
- DRS任务操作
- DRS检查任务方向和状态
- RDS自动备份策略设置
- RDS检查实例备份信息
- DRS检查任务信息
- DRS数据级/对象级对比
- OpenGauss容灾操作
- OpenGauss检查容灾信息
- 执行工作流
- 查看工作流执行详情
- 编辑工作流
- 复制工作流
- 删除工作流
- 关注工作流
- 混沌工程
- 应用韧性Hub
- 凭证管理
- 事件监控
- 查看审计日志
- 权限管理
- 最佳实践
- 开发指南
- 常见问题
- 视频帮助
- 文档下载
- 通用参考
本文导读
展开导读
链接复制成功!
自定义DcsConnection
使用场景:使用RedisTemplate命令时,DcsConnection中的接口没有覆盖到的情况,可以自定义扩展DcsConnection。
- 自定义DcsConnection。
- type选择为normal时使用。
import com.huawei.devspore.mas.redis.core.MultiZoneClient; import com.huawei.devspore.mas.redis.spring.boot.cache.DcsConnection; public class CusConnection extends DcsConnection { public CusConnection(MultiZoneClient client) { super(client); } // template中不支持但dcs中有的命令,可通过重写相应方法实现 @Override public Long hLen(byte[] key) { return client.hlen(key); } }
- type选择为cluster时使用。
1 2 3 4 5 6 7 8 9 10 11 12 13
import com.huawei.devspore.mas.redis.core.MultiZoneClient; import com.huawei.devspore.mas.redis.spring.boot.cache.DcsClusterConnection; public class CusClusterConnection extends DcsClusterConnection { public CusClusterConnection(MultiZoneClient client) { super(client); } // template中不支持但dcs中有的命令,可通过重写相应方法实现 @Override public Long hLen(byte[] key) { return client.hlen(key); } }
- type选择为normal时使用。
- 自定义RedisConnectionFactory。
import com.huawei.devspore.mas.redis.core.MultiZoneClient; import org.springframework.dao.DataAccessException; import org.springframework.data.redis.connection.RedisClusterConnection; import org.springframework.data.redis.connection.RedisConnection; import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.connection.RedisSentinelConnection; public class CusConnectionFactory implements RedisConnectionFactory { private final MultiZoneClient client; public CusConnectionFactory(MultiZoneClient client) { this.client = client; } @Override public RedisConnection getConnection() { // 单机或主从模式使用 return new CusConnection(client); } @Override public RedisClusterConnection getClusterConnection() { // 集群模式使用 return new CusClusterConnection(client); } @Override public boolean getConvertPipelineAndTxResults() { return false; } @Override public RedisSentinelConnection getSentinelConnection() { return null; } @Override public DataAccessException translateExceptionIfPossible(RuntimeException e) { return null; } }
- 配置类中指定自定义的RedisConnectionFactory。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
@Configuration public class TemplateConfig { @Bean public CusConnectionFactory dcsConnectionFactory(MultiZoneClient client) { return new CusConnectionFactory(client); } @Bean @Primary @ConditionalOnSingleCandidate(CusConnectionFactory.class) public RedisTemplate<Object, Object> RedisTemplate(CusConnectionFactory RedisConnectionFactory) { RedisTemplate<Object, Object> template = new RedisTemplate<>(); template.setConnectionFactory(RedisConnectionFactory); return template; } }
父主题: 客户各场景替换方案