1、安装gcc-c++(redis源码编译需要):yum install gcc-c++
2、解压缩redis目录
3、进入解压缩目录,使用make命令进行编译
4、进行安装:make install PREFIX=/usr/local/redis (PREFIX指定安装目录)
5、复制解压目录中的redis.conf到安装目录
6、修改配置文件
修改daemonize=yes,使得redis默认为后台运行
7、启动redis
8、检测redis后台:ps aux|grep redis
9、jedis连接Redis
/**
* 单机版单链接测试
* @throws Exception
*/
@Test
public void testRedis() throws Exception{
//创建jedis连接对象
Jedis jedis = new Jedis("192.168.25.139", 6379);
jedis.set("test", "HelloWorld");
String name = jedis.get("test");
System.out.println(name);
//关闭连接
jedis.close();
}
/**
* 单机版
* 测试jedis连接池
* @throws Exception
*/
@Test
public void testJedisPool() throws Exception {
//创建连接池
JedisPool pool = new JedisPool("192.168.25.139", 6379);
//获取一个连接对象
Jedis jedis = pool.getResource();
jedis.set("test", "HelloWorld");
System.out.println(jedis.get("test"));
//关闭连接,每次使用完毕后关闭连接。连接池回收资源。
jedis.close();
//关闭连接池
pool.close();
}
工具:下载