第一步:解压redis-3.0.5.tar
shell>tar -zxvf redis-3.0.5.tar
shell>cd redis-3.0.5
第二步:make
shell>make
可能会出现异常
zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or directory
zmalloc.h:55:2: error: #error "Newer version of jemalloc required"
如果出现了这个问题就安装jemalloc
shell>yum install jemalloc
然后再次
shell>make
Make成功后
shell>cd src
shell>make test
这时如果出现
\o/ All tests passed without errors!
Cleanup: may take some time... OK
则说明是成功的
第三步:安装
shell>cd ..
shell>make install
这种方式安装后redis-server ,redis-cli 等程序会安装到默认目录/usr/local/bin
shell>make PREFIX=/usr/local/redis install
上面的命令是安装到指定目录
安装之后,在我们刚才解压的redis3.0.5 目录中有redis.conf
将这个文件拷到/usr/local/redis3.0.5目录下一份
shell>cp redis.conf /usr/local/redis3.0.5/bin
第四步:启动 redis
shell>cd /usr/local/redis3.0.5/bin
shell>./redis-server
出现下面的字样则说明启动redis 成功
24599:C 21 Dec 14:01:48.697 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 3.0.5 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 24599
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
24599:M 21 Dec 14:01:48.736 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
24599:M 21 Dec 14:01:48.736 # Server started, Redis version 3.0.5
24599:M 21 Dec 14:01:48.736 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
24599:M 21 Dec 14:01:48.736 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
24599:M 21 Dec 14:01:48.736 * The server is now ready to accept connections on port 6379
第五步:验证
启动一个新的shell
shell>cd /usr/local/redis3.0.5/bin
shell>./redis-cli
会连接到本机的redis 服务器
出现这样的界面则说明OK
通过set 命令存入一个key value
通过一个get命令获得一个key 的value
第六步:
Redis 命令大全可以看这个网址
http://redis.io/commands
第七步:Redis 官方推荐Java 客户端jedis
网址:https://github.com/xetorthio/jedis
例子:
1
|
import
redis.clients.jedis.*
|
1
2
3
|
Jedis jedis =
new
Jedis(
"localhost"
);
jedis.set(
"foo"
,
"bar"
);
String value = jedis.get(
"foo"
);
|