This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @EnableRedisHttpSession | |
| public class RedisOperationsSessionRepositoryConfigNoListener { | |
| @Bean | |
| public RedisMessageListenerContainer redisMessageListenerContainer( | |
| RedisConnectionFactory connectionFactory, | |
| RedisOperationsSessionRepository messageListener) { | |
| return new RedisMessageListenerContainer(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @EnableRedisHttpSession | |
| public class RedisOperationsSessionRepositoryConfigNoListener { | |
| /** | |
| * Prevent server from subscription to Redis events (see RedisHttpSessionConfiguration) | |
| * @param connectionFactory | |
| * @param messageListener | |
| * @return | |
| */ | |
| @Bean |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @EnableRedisHttpSession | |
| public class RedisOperationsSessionRepositoryConfigNoOp { | |
| /** | |
| * Avoid changing Redis configuration for publishing specific events (gxE) | |
| * (see EnableRedisKeyspaceNotificationsInitializer - overrides ConfigureNotifyKeyspaceEventsAction which setting default event configuration ) | |
| * @return | |
| */ | |
| @Bean | |
| public static ConfigureRedisAction configureRedisAction() { | |
| return ConfigureRedisAction.NO_OP; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Configuration | |
| @EnableScheduling | |
| public class RedisHttpSessionConfiguration extends SpringHttpSessionConfiguration | |
| implements EmbeddedValueResolverAware, ImportAware { | |
| @Bean | |
| public RedisMessageListenerContainer redisMessageListenerContainer( | |
| RedisConnectionFactory connectionFactory, | |
| RedisOperationsSessionRepository messageListener) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class RedisOperationsSessionRepository implements | |
| FindByIndexNameSessionRepository<RedisOperationsSessionRepository.RedisSession>, | |
| MessageListener { | |
| ... | |
| @SuppressWarnings("unchecked") | |
| public void onMessage(Message message, byte[] pattern) { | |
| byte[] messageChannel = message.getChannel(); | |
| byte[] messageBody = message.getBody(); | |
| if (messageChannel == null || messageBody == null) { | |
| return; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void cleanExpiredSessions() { | |
| long now = System.currentTimeMillis(); | |
| long prevMin = roundDownMinute(now); | |
| if (logger.isDebugEnabled()) { | |
| logger.debug("Cleaning up sessions expiring at " + new Date(prevMin)); | |
| } | |
| String expirationKey = getExpirationKey(prevMin); | |
| Set<Object> sessionsToExpire = this.redis.boundSetOps(expirationKey).members(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Scheduled(cron = "${spring.session.cleanup.cron.expression:0 * * * * *}") | |
| public void cleanupExpiredSessions() { | |
| this.expirationPolicy.cleanExpiredSessions(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # REDIS (RedisProperties) | |
| spring.redis.cluster.max-redirects= # Maximum number of redirects to follow when executing commands across the cluster. | |
| spring.redis.cluster.nodes= # Comma-separated list of "host:port" pairs to bootstrap from. | |
| spring.redis.database=0 # Database index used by the connection factory. | |
| spring.redis.url= # Connection URL, will override host, port and password (user will be ignored), e.g. redis://user:[email protected]:6379 | |
| spring.redis.host=localhost # Redis server host. | |
| spring.redis.password= # Login password of the redis server. | |
| spring.redis.ssl=false # Enable SSL support. | |
| spring.redis.pool.max-active=8 # Max number of connections that can be allocated by the pool at a given time. Use a negative value for no limit. | |
| spring.redis.pool.max-idle=8 # Max number of "idle" connections in the pool. Use a negative value to indicate an unlimited number of idle connections. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| spring: | |
| session: | |
| store-type: redis | |
| security: | |
| user: | |
| name: ms | |
| password: password |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.odedia.springsession.rest; | |
| import java.util.Arrays; | |
| import java.util.List; | |
| import org.springframework.boot.SpringApplication; | |
| import org.springframework.boot.autoconfigure.SpringBootApplication; | |
| import org.springframework.cloud.client.discovery.EnableDiscoveryClient; | |
| import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | |
| import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; |