访问redis数据库
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package com.didispace;
|
||||
|
||||
import com.didispace.domain.User;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.*;
|
||||
|
||||
/**
|
||||
* @author 程序猿DD
|
||||
* @version 1.0.0
|
||||
* @date 16/4/15 下午3:19.
|
||||
* @blog http://blog.didispace.com
|
||||
*/
|
||||
@Configuration
|
||||
public class RedisConfig {
|
||||
|
||||
@Bean
|
||||
JedisConnectionFactory jedisConnectionFactory() {
|
||||
return new JedisConnectionFactory();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RedisTemplate<String, User> redisTemplate(RedisConnectionFactory factory) {
|
||||
RedisTemplate<String, User> template = new RedisTemplate<String, User>();
|
||||
template.setConnectionFactory(jedisConnectionFactory());
|
||||
template.setKeySerializer(new StringRedisSerializer());
|
||||
template.setValueSerializer(new RedisObjectSerializer());
|
||||
return template;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user