我使用Spring Redis的工作spring-data-redis
与所有默认配置喜欢localhost
默认port
等.
现在我尝试通过在application.properties
文件中配置它来进行相同的配置.但我无法弄清楚我应该如何创建完全符合我的属性值的bean.
Redis配置文件
@EnableRedisHttpSession
@Configuration
public class SpringSessionRedisConfiguration {
@Bean
JedisConnectionFactory connectionFactory() {
return new JedisConnectionFactory();
}
@Autowired
@Bean
RedisCacheManager redisCacheManager(final StringRedisTemplate stringRedisTemplate) {
return new RedisCacheManager(stringRedisTemplate);
}
@Autowired
@Bean
StringRedisTemplate template(final RedisConnectionFactory connectionFactory) {
return new StringRedisTemplate(connectionFactory);
}
}
Run Code Online (Sandbox Code Playgroud)
application.properties中的标准参数
spring.redis.sentinel.master =大师
spring.redis.sentinel.nodes = 192.168.188.231:26379
spring.redis.password = 12345
我试过的,
@PropertySource
然后注入@Value
并获取值.但是我不想这样做,因为这些属性不是由我定义的,而是来自Spring.RedisProperties
应该对我有所帮助,但仍然无法弄清楚究竟如何告诉Spring从属性文件中读取.当用户IntelliJ
在下面显示的对话框中尝试提交或推送更改时,有几个复选框.
我非常了解所有其他选项,但不确定究竟是Cleanup
做什么的?
我尝试阅读文档并找到了这个链接,https://www.jetbrains.com/idea/help/commit-changes-dialog.html 及其编写
清理 - 如果要将当前检查配置文件自动应用于要提交的文件,请选中此复选框.
但仍不确定它的含义以及它在源代码中自动检查或修复的内容.
我的问题是,在分布式Web应用程序中,可以使用Redis Store获取有效会话RedisOperationSessionRepository
.(我的意思是我不想编写显式代码将其放入Redis存储区然后再读取它,我想了解框架或spring-data-redis
库是否提供了这一点).
我知道Spring Redis能够恢复会话和服务器重启,如果会话仍然有效,也会保留登录(因为它由Redis支持)
我正在寻找的功能之一是获取当前在应用程序中的所有可能的登录用户.我知道SessionRegistryImpl
,这个方法.但我注意到Redis不支持此方法,并且在服务器重新启动后,不会返回登录用户.
public List<Object> getAllPrincipals() {
return new ArrayList<Object>(principals.keySet());
}
Run Code Online (Sandbox Code Playgroud)
我可以尝试的功能之一是Spring Session 1.1.0,Spring会话用户名查找.
我试过,它确实返回了我有效的会话结果,但问题是我仍然需要知道使用此应用程序的所有当前有效用户名.(我不知道如何使用Redis Store获取它们,我再次可以存储在Redis中并获取它们,但我想知道是否有更好的方法).
这是一段代码,如果我知道会话ID,这是我可以从当前使用该系统的众多用户之一获得当前用户的方式.
final Session session = redisOperationsSessionRepository.getSession(sessionid);
final Object obj = session.getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY);
if (obj instanceof SecurityContext) {
final SecurityContext context = (SecurityContext) obj;
final Authentication authentication = context.getAuthentication();
if (authentication != null) {
final Object principal = authentication.getPrincipal();
if (principal != null && principal instanceof CurrentUser) {
return (CurrentUser) principal;
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在我可以使用上面的逻辑来获取所有当前用户,但是我应该再次使用所有有效的会话ID,我不知道如何从Redis商店获取.
新更新: …