remove redis
This commit is contained in:
parent
6722607bf9
commit
a31dab3f22
6
pom.xml
6
pom.xml
@ -38,7 +38,6 @@
|
|||||||
<module>tigon-model</module>
|
<module>tigon-model</module>
|
||||||
<module>tigon-mybatis</module>
|
<module>tigon-mybatis</module>
|
||||||
<module>tigon-sequence</module>
|
<module>tigon-sequence</module>
|
||||||
<module>tigon-redis</module>
|
|
||||||
<module>tigon-mybatis-cache-redis</module>
|
<module>tigon-mybatis-cache-redis</module>
|
||||||
<module>tigon-shiro-cache</module>
|
<module>tigon-shiro-cache</module>
|
||||||
<module>tigon-shiro-cache-redis</module>
|
<module>tigon-shiro-cache-redis</module>
|
||||||
@ -74,11 +73,6 @@
|
|||||||
<artifactId>tigon-web</artifactId>
|
<artifactId>tigon-web</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>me.chyxion.tigon</groupId>
|
|
||||||
<artifactId>tigon-redis</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>me.chyxion.tigon</groupId>
|
<groupId>me.chyxion.tigon</groupId>
|
||||||
<artifactId>tigon-mybatis-cache-redis</artifactId>
|
<artifactId>tigon-mybatis-cache-redis</artifactId>
|
||||||
|
@ -18,8 +18,8 @@ import org.springframework.data.redis.core.HashOperations;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public final class RedisCache implements Cache {
|
public final class RedisCache implements Cache {
|
||||||
private final String id;
|
private final String id;
|
||||||
private final RedisTemplate<String, Object> redisTpl;
|
private final RedisTemplate<Object, Object> redisTpl;
|
||||||
private final HashOperations<String, String, Object> hashOp;
|
private final HashOperations<Object, String, Object> hashOp;
|
||||||
private final RedisCacheConfig config;
|
private final RedisCacheConfig config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,6 +2,7 @@ package me.chyxion.tigon.mybatis.cache;
|
|||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -13,7 +14,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
*/
|
*/
|
||||||
public class RedisCacheConfig {
|
public class RedisCacheConfig {
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisTemplate<String, Object> redisTpl;
|
@Qualifier("redisTemplate")
|
||||||
|
private RedisTemplate<Object, Object> redisTpl;
|
||||||
private static RedisCacheConfig instance;
|
private static RedisCacheConfig instance;
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
@ -31,7 +33,7 @@ public class RedisCacheConfig {
|
|||||||
/**
|
/**
|
||||||
* @return the redisTpl
|
* @return the redisTpl
|
||||||
*/
|
*/
|
||||||
public RedisTemplate<String, Object> getRedisTpl() {
|
public RedisTemplate<Object, Object> getRedisTpl() {
|
||||||
return redisTpl;
|
return redisTpl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1 +0,0 @@
|
|||||||
# tigon-redis
|
|
@ -1,68 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
|
|
||||||
http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<artifactId>tigon-redis</artifactId>
|
|
||||||
<packaging>jar</packaging>
|
|
||||||
<name>Tigon Redis</name>
|
|
||||||
<description>Tigon Redis</description>
|
|
||||||
|
|
||||||
<parent>
|
|
||||||
<groupId>me.chyxion.tigon</groupId>
|
|
||||||
<artifactId>tigon</artifactId>
|
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
|
||||||
<relativePath>../</relativePath>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.commons</groupId>
|
|
||||||
<artifactId>commons-lang3</artifactId>
|
|
||||||
<version>3.1</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.data</groupId>
|
|
||||||
<artifactId>spring-data-redis</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>redis.clients</groupId>
|
|
||||||
<artifactId>jedis</artifactId>
|
|
||||||
<version>2.9.0</version>
|
|
||||||
</dependency>
|
|
||||||
<!-- Test -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>jcl-over-slf4j</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.logging.log4j</groupId>
|
|
||||||
<artifactId>log4j-slf4j-impl</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.logging.log4j</groupId>
|
|
||||||
<artifactId>log4j-core</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-context</artifactId>
|
|
||||||
<version>${spring.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-test</artifactId>
|
|
||||||
<version>${spring.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
</project>
|
|
@ -1,19 +0,0 @@
|
|||||||
package me.chyxion.tigon.redis.pub;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @version 0.0.1
|
|
||||||
* @since 0.0.1
|
|
||||||
* @author Shaun Chyxion <br>
|
|
||||||
* chyxion@163.com <br>
|
|
||||||
* Nov 7, 2015 5:32:36 PM
|
|
||||||
*/
|
|
||||||
public interface PubProducer {
|
|
||||||
String PUB_QUEUE_SUFFIX = "_QUEUE";
|
|
||||||
String MESSAGE_CHANEL = "__PUBLICATION__";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param topic topic
|
|
||||||
* @param message message
|
|
||||||
*/
|
|
||||||
void publish(String topic, Object message);
|
|
||||||
}
|
|
@ -1,38 +0,0 @@
|
|||||||
package me.chyxion.tigon.redis.pub.support;
|
|
||||||
|
|
||||||
import me.chyxion.tigon.redis.pub.PubProducer;
|
|
||||||
import me.chyxion.tigon.redis.util.PubSubUtils;
|
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @version 0.0.1
|
|
||||||
* @since 0.0.1
|
|
||||||
* @author Shaun Chyxion <br>
|
|
||||||
* chyxion@163.com <br>
|
|
||||||
* Nov 7, 2015 5:07:50 PM
|
|
||||||
*/
|
|
||||||
public class PubProducerSupport
|
|
||||||
implements PubProducer {
|
|
||||||
@Autowired
|
|
||||||
private RedisTemplate<String, Object> redisTpl;
|
|
||||||
@Autowired
|
|
||||||
private RedisTemplate<String, String> strRedisTpl;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void publish(final String topic, final Object message) {
|
|
||||||
if (message != null) {
|
|
||||||
if (message instanceof CharSequence) {
|
|
||||||
strRedisTpl.opsForList().rightPush(PubSubUtils.queueKey(topic),
|
|
||||||
String.valueOf(message));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
redisTpl.opsForList().rightPush(PubSubUtils.queueKey(topic), message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
strRedisTpl.convertAndSend(MESSAGE_CHANEL, topic);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
package me.chyxion.tigon.redis.util;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Shaun Chyxion <br>
|
|
||||||
* chyxion@163.com <br>
|
|
||||||
* Dec 24, 2017 10:54 AM
|
|
||||||
*/
|
|
||||||
public class PubSubUtils {
|
|
||||||
public static final String QUEUE_PREFIX = "__TIGON_REDIS_PUB__";
|
|
||||||
public static final String MESSAGE_CHANEL = "__TIGON_REDIS_PUB__";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* return topic queue
|
|
||||||
* @param topic topic
|
|
||||||
* @return topic queue
|
|
||||||
*/
|
|
||||||
public static String queueKey(final String topic) {
|
|
||||||
return QUEUE_PREFIX + ":" + topic;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xmlns:p="http://www.springframework.org/schema/p"
|
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
|
||||||
http://www.springframework.org/schema/beans/spring-beans.xsd">
|
|
||||||
<description>Tigon Redis</description>
|
|
||||||
|
|
||||||
<!-- Redis Config -->
|
|
||||||
<bean id="redisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
|
|
||||||
p:host-name="${redis.host:localhost}"
|
|
||||||
p:port="${redis.port:6379}"
|
|
||||||
p:password="${redis.password:}"
|
|
||||||
p:database="${redis.database:0}" />
|
|
||||||
<!-- String tpl -->
|
|
||||||
<bean class="org.springframework.data.redis.core.StringRedisTemplate">
|
|
||||||
<constructor-arg ref="redisConnectionFactory" />
|
|
||||||
</bean>
|
|
||||||
<!-- Object tpl -->
|
|
||||||
<bean class="org.springframework.data.redis.core.RedisTemplate">
|
|
||||||
<property name="connectionFactory" ref="redisConnectionFactory" />
|
|
||||||
<property name="keySerializer">
|
|
||||||
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer" />
|
|
||||||
</property>
|
|
||||||
<property name="hashKeySerializer">
|
|
||||||
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer" />
|
|
||||||
</property>
|
|
||||||
<property name="valueSerializer">
|
|
||||||
<bean class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />
|
|
||||||
</property>
|
|
||||||
<property name="hashValueSerializer">
|
|
||||||
<bean class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />
|
|
||||||
</property>
|
|
||||||
</bean>
|
|
||||||
<!-- Pub Producer -->
|
|
||||||
<bean class="me.chyxion.tigon.redis.pub.support.PubProducerSupport" />
|
|
||||||
</beans>
|
|
@ -1,18 +0,0 @@
|
|||||||
package cn.com.flaginfo.echat.redis;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @version 0.0.1
|
|
||||||
* @since 0.0.1
|
|
||||||
* @author chyxion <br>
|
|
||||||
* chyxion@163.com <br>
|
|
||||||
* Mar 14, 2015 3:03:57 PM
|
|
||||||
*/
|
|
||||||
public class TestDriver {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHash() {
|
|
||||||
// System.err.println(new AuthConfig().hashPassword("123", "456"));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,33 +0,0 @@
|
|||||||
package cn.com.flaginfo.echat.redis.test;
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import me.chyxion.tigon.redis.pub.PubProducer;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @version 0.0.1
|
|
||||||
* @since 0.0.1
|
|
||||||
* @author Shaun Chyxion <br>
|
|
||||||
* chyxion@163.com <br>
|
|
||||||
* Nov 9, 2015 9:08:17 AM
|
|
||||||
*/
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
@ContextConfiguration({
|
|
||||||
"classpath:spring/spring-echat-redis.xml",
|
|
||||||
"classpath:spring/spring-redis-test.xml",
|
|
||||||
})
|
|
||||||
public class TestPub {
|
|
||||||
@Autowired
|
|
||||||
private PubProducer pp;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testRun() {
|
|
||||||
pp.publish("MESSAGE", "Hello, Redis Pub!" + new Date());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
package cn.com.flaginfo.echat.redis.test;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import java.util.Scanner;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @version 0.0.1
|
|
||||||
* @since 0.0.1
|
|
||||||
* @author Shaun Chyxion <br>
|
|
||||||
* chyxion@163.com <br>
|
|
||||||
* Nov 9, 2015 9:27:19 AM
|
|
||||||
*/
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
@ContextConfiguration({
|
|
||||||
"classpath:spring/spring-echat-redis.xml",
|
|
||||||
"classpath:spring/spring-redis-test.xml",
|
|
||||||
"classpath:spring/spring-redis-sub-test.xml",
|
|
||||||
})
|
|
||||||
public class TestSub {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testRun() {
|
|
||||||
new Scanner(System.in).next();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
log4j.rootLogger=debug, console
|
|
||||||
|
|
||||||
log4j.appender.console=org.apache.log4j.ConsoleAppender
|
|
||||||
log4j.appender.console.layout=org.apache.log4j.PatternLayout
|
|
||||||
log4j.appender.console.Encoding=utf-8
|
|
||||||
log4j.appender.console.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%F:%L] %m%n
|
|
@ -1,11 +0,0 @@
|
|||||||
# Config Dev
|
|
||||||
|
|
||||||
# Redis
|
|
||||||
redis.host=127.0.0.1
|
|
||||||
#redis.port=6379
|
|
||||||
#redis.password=0211
|
|
||||||
redis.port=6380
|
|
||||||
redis.password=6ca2b1bf0fe311e5:Y24kfEiNJxQFc17D
|
|
||||||
|
|
||||||
#redis.port=6382
|
|
||||||
#redis.password=e1605352ed8511e4:F92dd46acd0fe11e4
|
|
@ -1,11 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xmlns:p="http://www.springframework.org/schema/p"
|
|
||||||
xmlns:context="http://www.springframework.org/schema/context"
|
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
|
||||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
|
||||||
http://www.springframework.org/schema/context
|
|
||||||
http://www.springframework.org/schema/context/spring-context.xsd">
|
|
||||||
<bean class="cn.com.flaginfo.echat.redis.test.MessageSubConsumer" />
|
|
||||||
</beans>
|
|
@ -1,12 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xmlns:p="http://www.springframework.org/schema/p"
|
|
||||||
xmlns:context="http://www.springframework.org/schema/context"
|
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
|
||||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
|
||||||
http://www.springframework.org/schema/context
|
|
||||||
http://www.springframework.org/schema/context/spring-context.xsd">
|
|
||||||
<context:property-placeholder location="classpath:spring/config.properties" />
|
|
||||||
|
|
||||||
</beans>
|
|
@ -14,6 +14,7 @@ import org.apache.shiro.cache.CacheException;
|
|||||||
import me.chyxion.tigon.shiro.model.AuthUser;
|
import me.chyxion.tigon.shiro.model.AuthUser;
|
||||||
import me.chyxion.tigon.shiro.cache.SessionCache;
|
import me.chyxion.tigon.shiro.cache.SessionCache;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,8 +29,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
public class UserIdKeyRedisSessionCache implements SessionCache {
|
public class UserIdKeyRedisSessionCache implements SessionCache {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
protected RedisTemplate<Serializable, Serializable> redisTpl;
|
@Qualifier("redisTemplate")
|
||||||
@Value("${shiro.session.redis.prefix:AUTH_SESSION}")
|
protected RedisTemplate<Object, Object> redisTpl;
|
||||||
|
@Value("${tigon.shiro.session.redis.prefix:AUTH_SESSION}")
|
||||||
protected String prefix;
|
protected String prefix;
|
||||||
protected String userIdSessionPrefix;
|
protected String userIdSessionPrefix;
|
||||||
|
|
||||||
@ -65,9 +67,9 @@ public class UserIdKeyRedisSessionCache implements SessionCache {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Session put(Serializable sessionId, Session session) {
|
public Session put(Serializable sessionId, Session session) {
|
||||||
log.info("Redis Session Cache Put [{}:{}:{}].", prefix, sessionId, session);
|
log.info("Redis session cache put [{}:{}:{}].", prefix, sessionId, session);
|
||||||
valueOp().set(prefix + ":" + sessionId,
|
valueOp().set(prefix + ":" + sessionId,
|
||||||
(Serializable) session,
|
session,
|
||||||
session.getTimeout(),
|
session.getTimeout(),
|
||||||
TimeUnit.MILLISECONDS);
|
TimeUnit.MILLISECONDS);
|
||||||
return session;
|
return session;
|
||||||
@ -78,10 +80,10 @@ public class UserIdKeyRedisSessionCache implements SessionCache {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Session remove(Serializable sessionId) {
|
public Session remove(Serializable sessionId) {
|
||||||
log.info("Redis Session Cache Remove [{}].", sessionId);
|
log.info("Redis session cache remove [{}].", sessionId);
|
||||||
Session session = get(sessionId);
|
Session session = get(sessionId);
|
||||||
if (session != null) {
|
if (session != null) {
|
||||||
log.info("Redis Session Cache Remove [{}].", session);
|
log.info("Redis session cache remove [{}].", session);
|
||||||
redisTpl.delete(prefix + ":" + sessionId);
|
redisTpl.delete(prefix + ":" + sessionId);
|
||||||
}
|
}
|
||||||
return session;
|
return session;
|
||||||
@ -92,7 +94,7 @@ public class UserIdKeyRedisSessionCache implements SessionCache {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void clear() throws CacheException {
|
public void clear() throws CacheException {
|
||||||
log.warn("Redis Session Cache #clear Not Supported");
|
log.warn("Redis session cache #clear not supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -109,7 +111,7 @@ public class UserIdKeyRedisSessionCache implements SessionCache {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Set<Serializable> keys() {
|
public Set<Serializable> keys() {
|
||||||
log.warn("Redis Session Cache #keys Not Supported");
|
log.warn("Redis session cache #keys not supported");
|
||||||
return Collections.emptySet();
|
return Collections.emptySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,7 +120,7 @@ public class UserIdKeyRedisSessionCache implements SessionCache {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Collection<Session> values() {
|
public Collection<Session> values() {
|
||||||
log.warn("Redis Session Cache #values Not Supported");
|
log.warn("Redis session cache #values not supported");
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,15 +129,15 @@ public class UserIdKeyRedisSessionCache implements SessionCache {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Session findByUserId(final Serializable userId) {
|
public Session findByUserId(final Serializable userId) {
|
||||||
log.debug("Find Session By User Id [{}].", userId);
|
log.debug("Find session by user id [{}].", userId);
|
||||||
Serializable sessionId = hashOp().get(userIdSessionPrefix, userId);
|
Serializable sessionId = hashOp().get(userIdSessionPrefix, userId);
|
||||||
Session session = null;
|
Session session = null;
|
||||||
if (sessionId != null) {
|
if (sessionId != null) {
|
||||||
log.debug("User [{}] Session Id [{}] Found.", userId, sessionId);
|
log.debug("User [{}] session id [{}] found.", userId, sessionId);
|
||||||
session = get(sessionId);
|
session = get(sessionId);
|
||||||
log.info("User [{}] Session [{}] Found.", userId, session);
|
log.info("User [{}] session [{}] found.", userId, session);
|
||||||
if (session == null) {
|
if (session == null) {
|
||||||
log.info("No User [{}] Session Found, Remove.");
|
log.info("No user [{}] session found, remove.");
|
||||||
hashOp().delete(userIdSessionPrefix, userId);
|
hashOp().delete(userIdSessionPrefix, userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -147,23 +149,23 @@ public class UserIdKeyRedisSessionCache implements SessionCache {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Session putUserSession(Session session) {
|
public Session putUserSession(Session session) {
|
||||||
log.info("Put User Session [{}].", session);
|
log.info("Put user session [{}].", session);
|
||||||
AuthUser<?> authUser = AuthUser.get(session);
|
AuthUser<?> authUser = AuthUser.get(session);
|
||||||
Assert.state(authUser != null, "Auth User Not Found In Session");
|
Assert.state(authUser != null, "Auth user not found in session");
|
||||||
final Serializable userId = authUser.getUserId();
|
final Serializable userId = authUser.getUserId();
|
||||||
Assert.state(userId != null, "Session Auth User Id Could Not Be Null");
|
Assert.state(userId != null, "Session auth user id could not be null");
|
||||||
log.info("Put User [{}] Session [{}].", userId, session);
|
log.info("Put user [{}] session [{}].", userId, session);
|
||||||
hashOp().put(userIdSessionPrefix, userId, session.getId());
|
hashOp().put(userIdSessionPrefix, userId, session.getId());
|
||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --
|
// --
|
||||||
// private methods
|
// private methods
|
||||||
protected HashOperations<Serializable, Serializable, Serializable> hashOp() {
|
protected HashOperations<Object, Serializable, Serializable> hashOp() {
|
||||||
return redisTpl.<Serializable, Serializable>opsForHash();
|
return redisTpl.<Serializable, Serializable>opsForHash();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ValueOperations<Serializable, Serializable> valueOp() {
|
protected ValueOperations<Object, Object> valueOp() {
|
||||||
return redisTpl.opsForValue();
|
return redisTpl.opsForValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user