dromara/Sa-Token · critical · SaTokenException

SaToken 无法识别 Alone-Redis 配置的模式

Error message

SaToken 无法识别 Alone-Redis 配置的模式: ${pattern}

What it means

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.

Solutions

  1. Correct the pattern literal to one supported by this (legacy) injector; check the exact else-if chain in SaAloneRedisInject for the accepted values.
  2. Remove trailing/leading spaces and match case exactly.
  3. If you intended a newer mode, upgrade to sa-token-alone-redis-by-spring-boot4 or the sa-token version that introduced it.
  4. Print the effective property (env var override may be injecting a stray value) to confirm what reached the injector.

Example fix

# before
sa-token:
  alone-redis:
    pattern: sentinel-cluster

# after
sa-token:
  alone-redis:
    pattern: sentinel
Defensive patterns

Strategy: validation

Validate before calling

String p = props.getPattern();
if (p == null || p.trim().isEmpty() || !allowedLegacyPatterns.contains(p)) {
    throw new IllegalStateException("unsupported alone-redis pattern: " + p);
}

Type guard

boolean validLegacyPattern(String p) { return p != null && LEGACY_PATTERNS.contains(p); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of dromara/Sa-Token@ac2c7f6e94 (2026-08-14). Data as JSON: /api/errors/e122290a77de4291. Report an issue: GitHub.

Appendix: source

Thrown at sa-token-plugin/sa-token-alone-redis/src/main/java/cn/dev33/satoken/dao/alone/SaAloneRedisInject.java:178

			} else if (pattern.equals("aws")) {
				// AWS ElastiCache
				// AWS Redis 远程主机地址: String hoseName = "****.***.****.****.cache.amazonaws.com";
				String hostName = cfg.getHost();
				int port = cfg.getPort();
				RedisStaticMasterReplicaConfiguration redisStaticMasterReplicaConfiguration = new RedisStaticMasterReplicaConfiguration(hostName, port);
				redisStaticMasterReplicaConfiguration.setDatabase(cfg.getDatabase());
				// 低版本没有 username 属性,捕获异常给个提示即可,无需退出程序
				try {
					redisStaticMasterReplicaConfiguration.setUsername(cfg.getUsername());
				} catch (NoSuchMethodError e){
					System.err.println(e.getMessage());
				}
				redisStaticMasterReplicaConfiguration.setPassword(RedisPassword.of(cfg.getPassword()));

				redisAloneConfig = redisStaticMasterReplicaConfiguration;
			} else {
				// 模式无法识别
				throw new SaTokenException("SaToken 无法识别 Alone-Redis 配置的模式: " + pattern);
			}

			// 2. 连接池配置 
			GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
			// pool配置 
			Lettuce lettuce = cfg.getLettuce();
			if(lettuce.getPool() != null) {
				RedisProperties.Pool pool = cfg.getLettuce().getPool();
				// 连接池最大连接数
				poolConfig.setMaxTotal(pool.getMaxActive());	
				// 连接池中的最大空闲连接 
				poolConfig.setMaxIdle(pool.getMaxIdle());   	
				// 连接池中的最小空闲连接
				poolConfig.setMinIdle(pool.getMinIdle());		
				// 连接池最大阻塞等待时间(使用负值表示没有限制)
				poolConfig.setMaxWaitMillis(pool.getMaxWait().toMillis());
			}
			LettucePoolingClientConfiguration.LettucePoolingClientConfigurationBuilder builder = LettucePoolingClientConfiguration.builder();

View on GitHub (pinned to ac2c7f6e94)