1.安装
默认是在linux环境下
$ wget http://download.redis.io/releases/redis-2.8.17.tar.gz
$ tar xzf redis-2.8.17.tar.gz
$ cd redis-2.8.17
$ make
2.启动
正常启动是进入到 src 目录,因为我的解压地址是 /opt/redis-2.8.17,所以我应该先进入src目录
cd /opt/redis-2.8.17/src/
然后输入启动命令:
./redis-server
会看到下面的界面,这个时候默认是前端启动的,如果想要进行其他的操作,就必须退出这个redis。所以我们需要将他改为后台运行。
./redis-server
[2222] 07 Dec 11:14:34.548 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 2.8.17 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in stand alone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 2222
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
[2222] 07 Dec 11:14:34.551 # Server started, Redis version 2.8.17
3.后台启动redis
修改config配置,命令如下:
root@:/opt/redis-2.8.17# cd /opt/redis-2.8.17/
root@:/opt/redis-2.8.17# ll
total 148
drwxrwxr-x 6 root root 4096 Dec 6 18:18 ./
drwxr-xr-x 5 root root 4096 Dec 6 16:40 ../
-rw-rw-r-- 1 root root 27587 Sep 19 2014 00-RELEASENOTES
-rw-rw-r-- 1 root root 52 Sep 19 2014 BUGS
-rw-rw-r-- 1 root root 1439 Sep 19 2014 CONTRIBUTING
-rw-rw-r-- 1 root root 1487 Sep 19 2014 COPYING
drwxrwxr-x 6 root root 4096 Dec 6 16:41 deps/
-rw-r--r-- 1 root root 133 Dec 6 17:35 dump.rdb
-rw-rw-r-- 1 root root 332 Sep 19 2014 .gitignore
-rw-rw-r-- 1 root root 11 Sep 19 2014 INSTALL
-rw-rw-r-- 1 root root 151 Sep 19 2014 Makefile
-rw-rw-r-- 1 root root 4223 Sep 19 2014 MANIFESTO
-rw-rw-r-- 1 root root 4404 Sep 19 2014 README
-rw-rw-r-- 1 root root 34014 Dec 6 18:20 redis.conf
-rwxrwxr-x 1 root root 271 Sep 19 2014 runtest*
-rwxrwxr-x 1 root root 281 Sep 19 2014 runtest-sentinel*
-rw-rw-r-- 1 root root 7110 Sep 19 2014 sentinel.conf
drwxrwxr-x 2 root root 4096 Dec 7 11:16 src/
drwxrwxr-x 9 root root 4096 Sep 19 2014 tests/
drwxrwxr-x 3 root root 4096 Sep 19 2014 utils/
root@:/opt/redis-2.8.17# vi redis.conf
然后进行编辑 redis.conf:
将 daemonize 默认值修改为 yes
然后输入启动命令:
redis-server ../redis.conf
然后判断下是否打开: ps -ef | grep redis , 如下图就是已经打开
然后可以自己连一下:如图就是自己设置下 key = "keyA" value="valueA",用set设置一下,再用get取一下。这是最简单的字符,还有hashmap和list其他,可以自己搜一下
4.java连接Demon
package redisDemon;
import redis.clients.jedis.Jedis;
public class redisDemon {
//47.52.58.169
public static void main(String[] args) {
//连接本地的 Redis 服务
Jedis jedis = new Jedis("127.0.0.1",6379);
System.out.println("连接成功");
String password = "1022..";
String name = "aresblank" ;
//设置 redis 字符串数据
jedis.set(name, password);
// 获取存储的数据并输出
System.out.println("redis 存储的字符串为: "+ jedis.get(name));
}
}
redis的maven的jar包如下:
<!-- https://mvnrepository.com/artifact/redis.clients/jedis -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
</dependency>