redis 安装和使用
环境:centos6.5安装gcc、gcc-c++编译的环境
1、下载Redis
wget http://download.redis.io/releases/redis-2.8.3.tar.gz
2、解压
tar xf redis-2.8.3.tar.gz -C /usr/src/
cd /usr/src/redis-2.8.3/
3、安装Redis之前测试一下make test(执行make test必须先安装tcl语言包)
wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz
tar xf tcl8.6.1-src.tar.gz
cd tcl8.6.1/unix/
./configure && make && make install
这个时候在命令行就可以输入tclsh进入tcl解释器tcl就可以使用了。
4、安装
# make PREFIX=/usr/local/redis install
# cd /usr/local/redis/
# ls
bin
# cd bin/
# ls
redis-benchmarkredis-check-aofredis-check-dumpredis-cliredis-server
# cp /usr/src/redis-2.8.3/redis.conf /usr/local/redis
# ls
binredis.conf到这里redis已经安装成功了
5、启动Redis
方法一:进入 安装路径下的bin下
# cd bin
# ./redis-server redis.conf
13 Nov 00:43:50.340 * Max number of open files set to 10032
_._
_.-``__ ''-._
_.-`` `.`_.''-._ Redis 2.8.3 (00000000/0) 64 bit
.-`` .-```.```\/ _.,_ ''-._
( ' , .-`| `, ) Running in stand alone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 23753
`-._ `-._`-./_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
13 Nov 00:43:50.342 # Server started, Redis version 2.8.3
13 Nov 00:43:50.342 * DB loaded from disk: 0.000 seconds
13 Nov 00:43:50.342 * The server is now ready to accept connections on port 6379
这样其实已经启动成功了,但是这属于前端启动,启动redis之后,我们的控制台就不能进行任何操作了。只能ctrl+c停止启动。
方法二:后台启动
编辑redis.conf文件daemonize no 改为yes保存退出
再次启动
# ./redis-server redis.conf
查看启动成功没有:
netstat -anptl |grep redis
# netstat -antp|grep redis
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 23767/./bin/redis-s
tcp 0 0 :::6379 :::* LISTEN 23767/./bin/redis-s
6、关闭redis
# ./bin/redis-cli shutdown
7、简单的使用
//连接客户端
# ./bin/redis-cli
127.0.0.1:6379>
//检查网络是否通
127.0.0.1:6379> ping
PONG
//设置一个键值对
127.0.0.1:6379> set name cheny
OK
//获取刚刚设置的键值对
127.0.0.1:6379> get name
"cheny"
//查看所有的键
127.0.0.1:6379> keys *
1) "name"
//删除name这个键
127.0.0.1:6379> del name
(integer)
1127.0.0.1:6379> keys *(empty list or set)
127.0.0.1:6379>
到这里简单的redis安装就好了
页:
[1]