{"record":{"id":"e122290a77de4291","repo":"dromara/Sa-Token","slug":"satoken-alone-redis-pattern-e12229","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/src/main/java/cn/dev33/satoken/dao/alone/SaAloneRedisInject.java","lineNumber":178,"sourceCode":"\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\t// 低版本没有 username 属性，捕获异常给个提示即可，无需退出程序\n\t\t\t\ttry {\n\t\t\t\t\tredisStaticMasterReplicaConfiguration.setUsername(cfg.getUsername());\n\t\t\t\t} catch (NoSuchMethodError e){\n\t\t\t\t\tSystem.err.println(e.getMessage());\n\t\t\t\t}\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\tLettuce lettuce = cfg.getLettuce();\n\t\t\tif(lettuce.getPool() != null) {\n\t\t\t\tRedisProperties.Pool pool = cfg.getLettuce().getPool();\n\t\t\t\t// 连接池最大连接数\n\t\t\t\tpoolConfig.setMaxTotal(pool.getMaxActive());\t\n\t\t\t\t// 连接池中的最大空闲连接 \n\t\t\t\tpoolConfig.setMaxIdle(pool.getMaxIdle());   \t\n\t\t\t\t// 连接池中的最小空闲连接\n\t\t\t\tpoolConfig.setMinIdle(pool.getMinIdle());\t\t\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":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/dromara/Sa-Token/blob/ac2c7f6e94a78573cf0bcb932dd8b04e68fad189/sa-token-plugin/sa-token-alone-redis/src/main/java/cn/dev33/satoken/dao/alone/SaAloneRedisInject.java#L160-L196","documentation":"SaTokenException thrown by the original sa-token-alone-redis plugin's SaAloneRedisInject when sa-token.alone-redis.pattern does not match any supported mode branch (standalone/cluster/sentinel, etc.) and execution falls to the final else. Same semantic as the boot4 variant (error 112) but lives in the legacy injector that binds Spring Boot's RedisProperties.","triggerScenarios":"sa-token.alone-redis.pattern set to an unrecognized string — 'Cluster', 'redis-sentinel', 'master-slave', trailing whitespace — or a mode added in a newer sa-token version while the app runs an older jar that does not know it.","commonSituations":"Copy-pasting pattern values from docs of a different plugin generation; upgrading Spring Boot but keeping the legacy alone-redis plugin whose accepted keywords differ from sa-token-alone-redis-by-spring-boot4.","solutions":["Correct the pattern literal to one supported by this (legacy) injector; check the exact else-if chain in SaAloneRedisInject for the accepted values.","Remove trailing/leading spaces and match case exactly.","If you intended a newer mode, upgrade to sa-token-alone-redis-by-spring-boot4 or the sa-token version that introduced it.","Print the effective property (env var override may be injecting a stray value) to confirm what reached the injector."],"exampleFix":"# before\nsa-token:\n  alone-redis:\n    pattern: sentinel-cluster\n\n# after\nsa-token:\n  alone-redis:\n    pattern: sentinel","handlingStrategy":"validation","validationCode":"String p = props.getPattern();\nif (p == null || p.trim().isEmpty() || !allowedLegacyPatterns.contains(p)) {\n    throw new IllegalStateException(\"unsupported alone-redis pattern: \" + p);\n}","typeGuard":"boolean validLegacyPattern(String p) { return p != null && LEGACY_PATTERNS.contains(p); }","tryCatchPattern":null,"preventionTips":["Do not copy pattern values from the spring-boot4 plugin docs into the legacy plugin (and vice versa).","Print the effective pattern at boot to catch env-var overrides early."],"tags":["alone-redis","configuration","pattern","legacy-plugin"],"backgroundTag":null,"analyzedSha":"ac2c7f6e94a78573cf0bcb932dd8b04e68fad189","analyzedAt":"2026-08-14T14:36:10.271Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}