- add prepare/commit/cancel MCP tools and pending operation state - enforce execution identity, permissions, exact confirmation and audit - support attachments and operation confirmation cards - rewrite Dify DSL for write routing and destructive confirmations
211 lines
7.2 KiB
Java
211 lines
7.2 KiB
Java
package com.imyeyu.api.config;
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.imyeyu.api.modules.common.entity.Multilingual;
|
|
import com.imyeyu.api.modules.gao.ai.entity.GaoAiSession;
|
|
import com.imyeyu.api.modules.gao.ai.operation.GaoAiAttachmentToken;
|
|
import com.imyeyu.api.modules.gao.ai.operation.GaoAiPendingOperation;
|
|
import com.imyeyu.api.modules.gao.bean.GaoUserInviteCache;
|
|
import com.imyeyu.spring.bean.RedisConfigParams;
|
|
import com.imyeyu.spring.config.AbstractRedisConfig;
|
|
import com.imyeyu.spring.util.Redis;
|
|
import com.imyeyu.spring.util.RedisSerializers;
|
|
import com.imyeyu.utils.Time;
|
|
import io.lettuce.core.api.StatefulConnection;
|
|
import lombok.Data;
|
|
import lombok.EqualsAndHashCode;
|
|
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
import org.springframework.cache.interceptor.KeyGenerator;
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import java.time.Duration;
|
|
|
|
/**
|
|
* Redis 配置
|
|
*
|
|
* @author 夜雨
|
|
* @since 2021-02-23 21:36
|
|
*/
|
|
@Data
|
|
@Configuration
|
|
@EqualsAndHashCode(callSuper = true)
|
|
@EnableAutoConfiguration
|
|
@ConfigurationProperties(prefix = "spring.redis")
|
|
public class RedisConfig extends AbstractRedisConfig {
|
|
|
|
@Autowired
|
|
private ObjectMapper jackson;
|
|
|
|
// ---------- 连接配置 ----------
|
|
|
|
/** 地址 */
|
|
private String host;
|
|
|
|
/** 端口 */
|
|
private int port;
|
|
|
|
/** 密码 */
|
|
private String password;
|
|
|
|
/** Redis 逻辑库 */
|
|
private int database;
|
|
|
|
@Override
|
|
protected RedisConfigParams configParams() {
|
|
return new RedisConfigParams() {{
|
|
setHost(host);
|
|
setPort(port);
|
|
setPassword(password);
|
|
setTimeout(Time.SI * 8);
|
|
setMaxActive(8);
|
|
setMinIdle(1);
|
|
setMaxIdle(8);
|
|
}};
|
|
}
|
|
|
|
/** @return 连接池配置 */
|
|
@Bean
|
|
@Override
|
|
public GenericObjectPoolConfig<StatefulConnection<?, ?>> getPoolConfig() {
|
|
RedisConfigParams configArgs = configParams();
|
|
GenericObjectPoolConfig<StatefulConnection<?, ?>> config = new GenericObjectPoolConfig<>();
|
|
config.setMaxTotal(8);
|
|
config.setMinIdle(configArgs.getMinIdle());
|
|
config.setMaxIdle(configArgs.getMaxIdle());
|
|
config.setMaxWait(Duration.ofMillis(-1));
|
|
return config;
|
|
}
|
|
|
|
/** @return key 生成策略 */
|
|
@Bean
|
|
@Override
|
|
public KeyGenerator keyGenerator() {
|
|
return (target, method, params) -> {
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append(target.getClass().getName());
|
|
sb.append(method.getName());
|
|
for (Object obj : params) {
|
|
sb.append(obj.toString());
|
|
}
|
|
return sb.toString();
|
|
};
|
|
}
|
|
|
|
/** @return 分布式锁, ID: 尝试加锁次数 */
|
|
@Bean("redisLocker")
|
|
public Redis<String, Integer> getLockerRedisTemplate() {
|
|
return getRedis(database, RedisSerializers.STRING, RedisSerializers.INTEGER);
|
|
}
|
|
|
|
/** @return 多语言环境,ID: {@link Multilingual} */
|
|
@Bean("redisLanguage")
|
|
public Redis<String, Multilingual> getLanguageRedisTemplate() {
|
|
return getRedis(database, RedisSerializers.STRING, RedisSerializers.jacksonSerializer(jackson, Multilingual.class));
|
|
}
|
|
|
|
@Bean("redisCaptcha")
|
|
public Redis<String, String> getCaptchaRedisTemplate() {
|
|
return getRedis(database, RedisSerializers.STRING, RedisSerializers.STRING);
|
|
}
|
|
|
|
/** @return 文章访问记录,IP: [文章 ID] */
|
|
@Bean("redisLanguageMap")
|
|
public Redis<String, Long> getLanguageMapRedisTemplate() {
|
|
return getRedis(database, RedisSerializers.STRING, RedisSerializers.LONG);
|
|
}
|
|
|
|
/** @return 文章访问记录,IP: [文章 ID] */
|
|
@Bean("redisArticleRead")
|
|
public Redis<String, Long> getArticleReadRedisTemplate() {
|
|
return getRedis(database, RedisSerializers.STRING, RedisSerializers.LONG);
|
|
}
|
|
|
|
/** @return 用户登录经验标记,UID: NULL,暂时没有值,数据死亡时间为次日零时 */
|
|
@Bean("redisUserExpFlag")
|
|
public Redis<Long, String> getUserExpFlagRedisTemplate() {
|
|
return getRedis(database, RedisSerializers.LONG, RedisSerializers.STRING);
|
|
}
|
|
|
|
/** @return 用户登录令牌,令牌: 用户 ID */
|
|
@Bean("redisUserToken")
|
|
public Redis<String, String> getUserTokenRedisTemplate() {
|
|
return getRedis(database, RedisSerializers.STRING, RedisSerializers.STRING);
|
|
}
|
|
|
|
/** @return 用户邮箱验证密钥,密钥: UID */
|
|
@Bean("redisUserEmailVerify")
|
|
public Redis<String, Long> getUserEmailVerifyRedisTemplate() {
|
|
return getRedis(database, RedisSerializers.STRING, RedisSerializers.LONG);
|
|
}
|
|
|
|
/** @return 用户重置密码密钥,密钥: UID */
|
|
@Bean("redisUserResetPWVerify")
|
|
public Redis<String, Long> getUserResetPWVerifyRedisTemplate() {
|
|
return getRedis(database, RedisSerializers.STRING, RedisSerializers.LONG);
|
|
}
|
|
|
|
/** @return 用户手机号验证码,手机号: 验证码 */
|
|
@Bean("redisUserPhoneVerify")
|
|
public Redis<String, String> getUserPhoneVerifyRedisTemplate() {
|
|
return getRedis(database, RedisSerializers.STRING, RedisSerializers.STRING);
|
|
}
|
|
|
|
/** @return 接口访问控制,IP#方法: 生命周期内访问次数 */
|
|
@Bean("redisRateLimit")
|
|
public Redis<String, Integer> getRateLimitRedisTemplate() {
|
|
return getRedis(database, RedisSerializers.STRING, RedisSerializers.INTEGER);
|
|
}
|
|
|
|
/** @return 系统配置,Key 枚举: String 配置值 */
|
|
@Bean("redisSetting")
|
|
public Redis<String, String> getSettingRedisTemplate() {
|
|
return getRedis(database, RedisSerializers.STRING, RedisSerializers.STRING);
|
|
}
|
|
|
|
/** @return Minecraft 登录,令牌: 玩家 ID */
|
|
@Bean("redisMCPlayerToken")
|
|
public Redis<String, Long> getMCPlayerLoginRedisTemplate() {
|
|
return getRedis(database, RedisSerializers.STRING, RedisSerializers.LONG);
|
|
}
|
|
|
|
/** @return 共享剪切板,会话 ID: 内容 */
|
|
@Bean("redisClipboard")
|
|
public Redis<String, String> getClipboardRedisTemplate() {
|
|
return getRedis(database, RedisSerializers.STRING, RedisSerializers.STRING);
|
|
}
|
|
|
|
/// @return GAO 用户邀请,code: 邀请缓存
|
|
@Bean("redisGaoUserInvite")
|
|
public Redis<String, GaoUserInviteCache> getGaoUserInviteRedisTemplate() {
|
|
return getRedis(database, RedisSerializers.STRING, RedisSerializers.jacksonSerializer(jackson, GaoUserInviteCache.class));
|
|
}
|
|
|
|
/// @return AI 会话,AI 会话 ID: 会话授权内容
|
|
@Bean("redisGaoAiSession")
|
|
public Redis<String, GaoAiSession> getGaoAiSessionRedisTemplate() {
|
|
return getRedis(database, RedisSerializers.STRING, RedisSerializers.jacksonSerializer(jackson, GaoAiSession.class));
|
|
}
|
|
|
|
/// @return AI 待确认操作,token 摘要/公开 ID: 待确认操作
|
|
@Bean("redisGaoAiOperation")
|
|
public Redis<String, GaoAiPendingOperation> getGaoAiOperationRedisTemplate() {
|
|
return getRedis(database, RedisSerializers.STRING, RedisSerializers.jacksonSerializer(jackson, GaoAiPendingOperation.class));
|
|
}
|
|
|
|
/// @return AI 待确认操作索引,用户+门店/来源会话: 公开操作 ID
|
|
@Bean("redisGaoAiOperationIndex")
|
|
public Redis<String, String> getGaoAiOperationIndexRedisTemplate() {
|
|
return getRedis(database, RedisSerializers.STRING, RedisSerializers.STRING);
|
|
}
|
|
|
|
/// @return AI 附件凭证,token 摘要: 附件凭证
|
|
@Bean("redisGaoAiAttachment")
|
|
public Redis<String, GaoAiAttachmentToken> getGaoAiAttachmentRedisTemplate() {
|
|
return getRedis(database, RedisSerializers.STRING, RedisSerializers.jacksonSerializer(jackson, GaoAiAttachmentToken.class));
|
|
}
|
|
}
|