Springboot整合Redis
Springboot整合Redis
redis下载与使用


SpringBoot整合Redis


这里注意密码,看你的配置文件中如果配置了密码,要加上密码的。
比如我的:
spring:data:redis:host: localhostport: 6379password: 123456


@SpringBootTest
class Springboot16RedisApplicationTests {@Autowiredprivate RedisTemplate redisTemplate;@Testvoid set() {ValueOperations ops = redisTemplate.opsForValue();ops.set("age",41);}@Testvoid get() {ValueOperations ops = redisTemplate.opsForValue();Object age = ops.get("age");System.out.println(age);}@Testvoid hset() {HashOperations ops = redisTemplate.opsForHash();ops.put("info","a","aa");}@Testvoid hget() {HashOperations ops = redisTemplate.opsForHash();Object o = ops.get("info", "a");System.out.println(o);}
}



@SpringBootTest
public class SpringRedisTemplateTest {@Autowiredprivate StringRedisTemplate stringRedisTemplate;@Testvoid get(){ValueOperations<String, String> ops = stringRedisTemplate.opsForValue();String name = ops.get("name");System.out.println(name);}
}
springboot操作redis客户端实现技术切换(jedis)
- 导入jedis坐标
<dependency><groupId>redis.clients</groupId><artifactId>jedis</artifactId></dependency>
- 配置profile
spring:data:redis:host: localhostport: 6379password: 123456client-type: jedis

