{"record":{"id":"5347de779a91d90c","repo":"dromara/Sa-Token","slug":"satoken-alone-redis-pattern","errorCode":null,"errorMessage":"SaToken 无法识别 Alone-Redis 配置的模式: ${pattern}","messagePattern":"SaToken 无法识别 Alone-Redis 配置的模式: (.+?)","errorType":"validation","errorClass":"SaTokenException","httpStatus":null,"severity":"critical","filePath":"sa-token-plugin/sa-token-alone-redis-by-spring-boot4/src/main/java/cn/dev33/satoken/dao/alone/SaAloneRedisInject.java","lineNumber":161,"sourceCode":"\t\t\t\tredisSocketConfiguration.setPassword(RedisPassword.of(cfg.getPassword()));\n\t\t\t\tString socket = environment.getProperty(ALONE_PREFIX + \".socket\", \"\");\n\t\t\t\tredisSocketConfiguration.setSocket(socket);\n\n\t\t\t\tredisAloneConfig = redisSocketConfiguration;\n\t\t\t} else if (pattern.equals(\"aws\")) {\n\t\t\t\t// AWS ElastiCache\n\t\t\t\t// AWS Redis 远程主机地址: String hoseName = \"****.***.****.****.cache.amazonaws.com\";\n\t\t\t\tString hostName = cfg.getHost();\n\t\t\t\tint port = cfg.getPort();\n\t\t\t\tRedisStaticMasterReplicaConfiguration redisStaticMasterReplicaConfiguration = new RedisStaticMasterReplicaConfiguration(hostName, port);\n\t\t\t\tredisStaticMasterReplicaConfiguration.setDatabase(cfg.getDatabase());\n\t\t\t\tredisStaticMasterReplicaConfiguration.setUsername(cfg.getUsername());\n\t\t\t\tredisStaticMasterReplicaConfiguration.setPassword(RedisPassword.of(cfg.getPassword()));\n\n\t\t\t\tredisAloneConfig = redisStaticMasterReplicaConfiguration;\n\t\t\t} else {\n\t\t\t\t// 模式无法识别\n\t\t\t\tthrow new SaTokenException(\"SaToken 无法识别 Alone-Redis 配置的模式: \" + pattern);\n\t\t\t}\n\n\t\t\t// 2. 连接池配置\n\t\t\tGenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();\n\t\t\t// pool配置\n\t\t\tDataRedisProperties.Lettuce lettuce = cfg.getLettuce();\n\t\t\tif(lettuce.getPool() != null) {\n\t\t\t\tDataRedisProperties.Pool pool = cfg.getLettuce().getPool();\n\t\t\t\t// 连接池最大连接数\n\t\t\t\tpoolConfig.setMaxTotal(pool.getMaxActive());\n\t\t\t\t// 连接池中的最大空闲连接\n\t\t\t\tpoolConfig.setMaxIdle(pool.getMaxIdle());\n\t\t\t\t// 连接池中的最小空闲连接\n\t\t\t\tpoolConfig.setMinIdle(pool.getMinIdle());\n\t\t\t\t// 连接池最大阻塞等待时间（使用负值表示没有限制）\n\t\t\t\tpoolConfig.setMaxWaitMillis(pool.getMaxWait().toMillis());\n\t\t\t}\n\t\t\tLettucePoolingClientConfiguration.LettucePoolingClientConfigurationBuilder builder = LettucePoolingClientConfiguration.builder();","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/dromara/Sa-Token/blob/ac2c7f6e94a78573cf0bcb932dd8b04e68fad189/sa-token-plugin/sa-token-alone-redis-by-spring-boot4/src/main/java/cn/dev33/satoken/dao/alone/SaAloneRedisInject.java#L143-L179","documentation":"SaTokenException thrown by SaAloneRedisInject (spring-boot4 variant) when sa-token.alone-redis.pattern is none of the recognized values (standalone/cluster/sentinel/socket/aws variants). The if/else chain over pattern falls through to '模式无法识别', so any typo or unsupported deployment mode aborts startup.","triggerScenarios":"Setting sa-token.alone-redis.pattern to a misspelled or unsupported value: 'Cluster' (capitalized), 'redis', 'master-slave', 'replication', or empty string after removing a comment incorrectly.","commonSituations":"Upgrading from the older sa-token-alone-redis plugin whose accepted pattern strings differ; hand-editing yml and introducing a typo; assuming a new Redis deployment mode is supported when only the enumerated ones are.","solutions":["Read the exact pattern string printed in the exception message and compare against the supported list in SaAloneRedisInject.","Use the correct literal (e.g. 'standalone', 'cluster', 'sentinel', 'socket') in lowercase with no surrounding spaces.","If you need master-replica, check whether your version supports the aws/static-master-replica branch and its exact pattern keyword.","Quoted or unquoted scalars are both fine in yaml, but ensure no trailing whitespace via block scalars."],"exampleFix":"# before\nsa-token:\n  alone-redis:\n    pattern: Cluster   # capital C -> unrecognized\n\n# after\nsa-token:\n  alone-redis:\n    pattern: cluster","handlingStrategy":"validation","validationCode":"Set<String> supported = Set.of(\"standalone\", \"cluster\", \"sentinel\", \"socket\"); // per injector version\nString p = props.getPattern();\nif (!supported.contains(p)) { fail fast with the allowed list; }","typeGuard":"boolean supportedPattern(String p, Set<String> allowed) { return p != null && allowed.contains(p.trim().toLowerCase()); }","tryCatchPattern":null,"preventionTips":["Centralize the pattern literal in one property/env var reviewed by both dev and ops.","After upgrading the plugin, diff the accepted pattern values from SaAloneRedisInject's source for your version."],"tags":["alone-redis","configuration","pattern","spring-boot4"],"backgroundTag":null,"analyzedSha":"ac2c7f6e94a78573cf0bcb932dd8b04e68fad189","analyzedAt":"2026-08-14T14:36:10.271Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}