1. cd /usr/local/redis/bin 进入到bin目录,找到redis.conf文件,为启动redis作准备java
2. ./redis-server redis.conf 开启redis服务器redis
3. ./redis-cli -h 192.168.248.59 开启redis客户单,host是本身虚拟机的ip地址spring
4.有密码时,须要输入密码 auth 密码;没有密码时直接进入成功shell
5.若想去掉密码,先执行命令shutdown关闭服务器,再执行quit命令退出客户端vim
6.执行vim redis.conf命令,进入文件中,将设置密码行用#注释掉,从新启动服务器便可。 springboot
<!--springboot整合redis相关依赖引入--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency>
#Redis
spring:
redis: host: 192.168.248.59 port: 6379
@RunWith(SpringRunner.class)
@SpringBootTest(classes = SpringbootdemoApplication.class)
class SpringbootdemoApplicationTests {
@Autowired
private RedisTemplate redisTemplate;
@Test
public void add(){
redisTemplate.opsForValue().set("name","zhangsan");
String name = (String)redisTemplate.opsForValue().get("name");
System.out.println(name);
MUser user = new MUser();
user.setId(1);
user.setUsername("admin");
user.setPassword("123");
user.setName("超人");
redisTemplate.opsForValue().set("user",user);
MUser user1 = (MUser)redisTemplate.opsForValue().get("user");
System.out.println(user1);
}
}