环境准备
[root@VM_0_13_centos ~]
上传并安装redis
[root@VM_0_13_centos /]
[root@VM_0_13_centos /]
[root@VM_0_13_centos data]
[root@VM_0_13_centos data]
[root@VM_0_13_centos redis]
[root@VM_0_13_centos redis]
[root@VM_0_13_centos redis]
[root@VM_0_13_centos redis]
[root@VM_0_13_centos redis-4.0.10]
[root@VM_0_13_centos bin]
[root@VM_0_13_centos redis-4.0.10]
绑定服务器内网ip
[root@VM_0_13_centos redis-4.0.10]
[root@VM_0_13_centos bin]
[root@VM_0_13_centos bin]

前端启动(会占用当前窗口)
[root@VM_0_13_centos bin]
后端启动(不会占用当前窗口)
[root@VM_0_13_centos bin]
[root@VM_0_13_centos bin]

配置redis密码
[root@VM_0_13_centos bin]
[root@VM_0_13_centos bin]

使用工具连接
[root@VM_0_13_centos bin]
[root@VM_0_13_centos bin]

查看redis进程
[root@VM_0_13_centos bin]
关闭redis
[root@VM_0_13_centos bin]
进入redis的命令行
[root@VM_0_13_centos bin]

退出redis的命令行
127.0.0.1:6379> exit

配置redis操作密码
192.168.64.131:6379>config set requirepass redis
Java代码连接redis
[root@localhost redis]
[root@localhost redis]
import org.junit.Test;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
public class TestRedis {
@Test
public void testJedisSingle(){
Jedis jedis = new Jedis("192.168.163.128",6379);
jedis.set("nama", "jedis test");
String string = jedis.get("name");
System.out.println(string);
jedis.close();
}
@Test
public void testJedisPool(){
JedisPool pool = new JedisPool("192.168.163.128",6379);
Jedis jedis1 = pool.getResource();
Jedis jedis2 = pool.getResource();
jedis1.set("age", "20");
String age = jedis2.get("age");
System.out.println(age);
jedis1.close();
jedis2.close();
pool.close();
}
}
redis常用命令