<!--Redis Configuration--
<bean id= "ConnectionFactory" class= "Org.springframework.data.redis.connection.jedis.JedisConnectionFactory" Destroy-method= "Destroy" >
<property name= "HostName" value= "${redis.host}"/>
<property name= "Port" value= "${redis.port}"/>
<property name= "Usepool" value= "true"/>
</bean>
<bean id= "Redistemplate" class= "Org.springframework.data.redis.core.RedisTemplate" >
<property name= "ConnectionFactory" ref= "ConnectionFactory"/>
<property name= "Keyserializer" >
<bean class= "Org.springframework.data.redis.serializer.StringRedisSerializer" ></bean>
</property>
<property name= "ValueSerializer" >
<bean class= "Org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" ></bean>
</property>
</bean>
public class Redisdao implements Initializingbean {
@Resource (name= "Redistemplate")
Protected redistemplate<string, object> redistemplate;
Protected Valueoperations<string, object> valueoperations = null;
@Override
public void Afterpropertiesset () throws Exception {
Valueoperations = Redistemplate.opsforvalue ();
}
}
@Repository
public class Sessionredisdao extends Redisdao {
Public sessionentity getsession (String sessionId) {
Return (sessionentity) valueoperations.get (sessionId);
}
public boolean setsessionentity (Sessionentity sessionentity) {
Valueoperations.set (Sessionentity.getsessionid (), sessionentity);
return true;
}
public boolean deletesessionentity (String sessionId) {
if (getsession (sessionId) ==null) {
return true;
}
Redistemplate.delete (SESSIONID);
return true;
}
}
Redis Best Practices