首先需要安装编译Redis的C环境,在命令行执行以下命令:
[root@itzhouq32 tools] yum install gcc-c++进入解压的目录,使用make编译
[root@itzhouq32 tools]# cd /usr/local/ [root@itzhouq32 local]# ls bin games jdk1.8.0_201 lib64 redis-3.0.0 share src etc include lib libexec sbin soft tomcat [root@itzhouq32 local]# cd redis-3.0.0/ [root@itzhouq32 redis-3.0.0]# ls 00-RELEASENOTES COPYING Makefile redis.conf runtest-sentinel tests BUGS deps MANIFESTO runtest sentinel.conf utils CONTRIBUTING INSTALL README runtest-cluster src [root@itzhouq32 redis-3.0.0]# make在原来的目录下安装,当前目录为/usr/local/redis
[root@itzhouq32 redis-3.0.0]# make PREFIX=/usr/local/redis install进入redis-3.0.0的目录,找到redis.conf配置文件,将其拷贝到redis/bin目录下
[root@itzhouq32 local]# ls bin games jdk1.8.0_201 lib64 redis sbin soft tomcat etc include lib libexec redis-3.0.0 share src [root@itzhouq32 local]# cd redis-3.0.0/ [root@itzhouq32 redis-3.0.0]# ls 00-RELEASENOTES COPYING Makefile redis.conf runtest-sentinel tests BUGS deps MANIFESTO runtest sentinel.conf utils CONTRIBUTING INSTALL README runtest-cluster src [root@itzhouq32 redis-3.0.0]# cp redis.conf ../redis/bin/返回redis/bin目录,修改redis.conf配置文件
[root@itzhouq32 redis-3.0.0]# cd ../redis/bin/ [root@itzhouq32 bin]# ls dump.rdb redis-check-aof redis-cli redis-sentinel redis-benchmark redis-check-dump redis.conf redis-server [root@itzhouq32 bin]# vi redis.conf将redis.conf文件中的daemonize从false修改成true表示后台启动
进程中有redis,说明后台启动成功。
如果需要远程访问redis,需要在Linux防火墙中开放6379端口,并将规则保存到防火墙中。
[root@itzhouq32 bin]# /sbin/iptables -I INPUT -p tcp --dport 6379 -j ACCEPT [root@itzhouq32 bin]# /etc/rc.d/init.d/iptables save iptables:将防火墙规则保存到 /etc/sysconfig/iptables: [确定] [root@itzhouq32 bin]#在Eclipse中导入jar包,编写一个测试类。
package com.itzhouq.jedis; import org.junit.Test; import redis.clients.jedis.Jedis; public class JedisTest { @Test public void test01() { //1. 获得连接对象 Jedis jedis = new Jedis("192.168.146.132", 6379); //2. 获得数据 String username = jedis.get("username"); System.out.println(username);//zhangsan //3. 存储 jedis.set("addr", "上海"); System.out.println(jedis.get("addr"));//上海 } }转载于:https://www.cnblogs.com/itzhouq/p/redis.html
相关资源:JAVA上百实例源码以及开源项目