Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加lettuce支持,以及优化之前代码,并升级shiro版本,pom文件修改为支持自由选择lettuce或jedis,这个需要怎么配置,麻烦说明一下 #174

Open
gang0713 opened this issue Sep 23, 2024 · 1 comment

Comments

@gang0713
Copy link

No description provided.

@llllllxy
Copy link

`private final RedisProperties redisProperties;

/**

  • 单机配置
  • @return
    */
    @bean
    public LettuceRedisManager lettuceRedisManager() {
    LettuceRedisManager lettuceRedisManager = new LettuceRedisManager();
    String password = redisProperties.getPassword();
    if (StringUtils.isNotBlank(password)) {
    lettuceRedisManager.setPassword(password);
    }
    lettuceRedisManager.setHost(redisProperties.getHost());
    lettuceRedisManager.setPort(redisProperties.getPort());
    lettuceRedisManager.setTimeout(redisProperties.getTimeout());
    lettuceRedisManager.setDatabase(redisProperties.getDatabase());
    // 可选项是否开启异步,默认不开启
    // lettuceRedisClusterManager.setIsAsync();
    // 客户端选项
    // lettuceRedisSentinelManager.setClientOptions();
    // 连接池配置
    // lettuceRedisSentinelManager.setGenericObjectPoolConfig();
    return lettuceRedisManager;
    }

/**

  • 集群配置
  • @return
    */
    @bean
    public LettuceRedisClusterManager lettuceRedisClusterManager() {
    LettuceRedisClusterManager lettuceRedisClusterManager = new LettuceRedisClusterManager();
    lettuceRedisClusterManager.setPassword(redisProperties.getPassword());
    lettuceRedisClusterManager.setDatabase(redisProperties.getDatabase());
    lettuceRedisClusterManager.setNodes(redisProperties.getCluster().getNodes());
    // 可选项是否开启异步,默认开启
    // lettuceRedisClusterManager.setIsAsync();
    // 客户端选项
    // lettuceRedisClusterManager.setClusterClientOptions();
    // 连接池配置
    // lettuceRedisSentinelManager.setGenericObjectPoolConfig();
    return lettuceRedisClusterManager;
    }

/**

  • 哨兵模式
  • @return
    */
    @bean
    public LettuceRedisSentinelManager lettuceRedisSentinelManager() {
    LettuceRedisSentinelManager lettuceRedisSentinelManager = new LettuceRedisSentinelManager();
    lettuceRedisSentinelManager.setPassword(redisProperties.getPassword());
    lettuceRedisSentinelManager.setDatabase(redisProperties.getDatabase());
    lettuceRedisSentinelManager.setMasterName(redisProperties.getSentinel().getMaster());
    lettuceRedisSentinelManager.setNodes(redisProperties.getSentinel().getNodes());
    lettuceRedisSentinelManager.setSentinelPassword(redisProperties.getSentinel().getPassword());
    // 读取模式
    lettuceRedisSentinelManager.setReadFrom(ReadFrom.REPLICA_PREFERRED);
    // 可选项是否开启异步,默认不开启
    // lettuceRedisClusterManager.setIsAsync();
    // 客户端选项
    // lettuceRedisSentinelManager.setClientOptions();
    // 连接池配置
    // lettuceRedisSentinelManager.setGenericObjectPoolConfig();
    return lettuceRedisSentinelManager;
    }

/**

  • 使用Redis实现 shiro sessionDao
  • @return
    */
    @bean
    public RedisSessionDAO redisSessionDAO(LettuceRedisManager lettuceRedisManager) {
    RedisSessionDAO redisSessionDAO = new RedisSessionDAO();
    redisSessionDAO.setRedisManager(lettuceRedisManager);
    return redisSessionDAO;
    }

/**

  • redis实现缓存
  • @return
    */
    @bean
    public RedisCacheManager redisCacheManager(LettuceRedisManager lettuceRedisManager) {
    RedisCacheManager redisCacheManager = new RedisCacheManager();
    redisCacheManager.setRedisManager(lettuceRedisManager);
    return redisCacheManager;
    }`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants