org.springframework.data
spring-data-redis
2.1.3.RELEASE
创建:SpringConfig
package the_mass.redis;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
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.core.StringRedisTemplate;
@Configuration //配置
@ComponentScan(“the_mass.redis”) //扫描那个包
public class SpringConfig {
@Bean
RedisConnectionFactory redisConnectionFactory(){ //获取连接工厂
return new JedisConnectionFactory(); //返回
}
@Bean
RedisTemplate redisTemplate(){ //模板
return new StringRedisTemplate(redisConnectionFactory()); //使用连接工厂返回
}
}
创建:RedisService
package the_mass.redis;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisOperations;
import org.springframework.stereotype.Service;
import java.nio.charset.StandardCharsets;
@Service
public class RedisService {
@Autowired
RedisConnectionFactory factory; //通过Redis连接的线程安全工厂
@Autowired
RedisOperations redisOperations; //通过公共接口RedisOperations
public void testRedis() {
RedisConnection connection = factory.getConnection();
byte[] bytes = connection.get(“hello”.getBytes());
System.out.println(new String(bytes, StandardCharsets.UTF_8));
}
小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数初中级Java工程师,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年最新Java开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Java)
最近我根据上述的技术体系图搜集了几十套腾讯、头条、阿里、美团等公司21年的面试题,把技术点整理成了视频(实际上比预期多花了不少精力),包含知识脉络 + 诸多细节,由于篇幅有限,这里以图片的形式给大家展示一部分
230)]
最近我根据上述的技术体系图搜集了几十套腾讯、头条、阿里、美团等公司21年的面试题,把技术点整理成了视频(实际上比预期多花了不少精力),包含知识脉络 + 诸多细节,由于篇幅有限,这里以图片的形式给大家展示一部分
[外链图片转存中…(img-LI1FA2IR-1711005651231)]