1、使用SpringBoot的RedisTemplate时需要在配置文件中向容器中注入RedisConnectionFactory
2、打开RedisConnectionFactory接口可以如下的方法
/**
* Provides a suitable connection for interacting with Redis Cluster.
* 提供一个连接redis集群的连接
*
* @return
* @since 1.7
*/
RedisClusterConnection getClusterConnection();
3、查看这个方法的实现 只有两个
getClusterConnection()的实现类.png
4、分别查看
getClusterConnection()方法可以看到:
-
JedisConnectionFactory返回的是JedisClusterConnection -
LettuceConnectionFactory返回的是LettuceClusterConnection
5、找到其分别对scriptingCommands()的返回值: -
JedisClusterConnection返回的是JedisClusterScriptingCommands.INSTANCE==JedisClusterScriptingCommands -
LettuceClusterConnection继承了LettuceConnection返回的是LettuceScriptingCommands
6、查看对应的实现 -
JedisClusterScriptingCommands- 所有方法都是直接抛出异常,说明其并不支持集群下的script
- 也可以看到使用
JedisConnectionFactory经常抛出的异常EvalSha is not supported in cluster environment.
-
LettuceScriptingCommands则是有对应的实现










网友评论