日期:2014-05-16  浏览次数:20407 次

内存数据库Redis的基本安装与使用

官网:
http://www.redis.io
参考文档:
http://www.redis.cn/
http://redis.readthedocs.org/en/latest/index.html

下载
wget http://download.redis.io/releases/redis-2.8.6.tar.gz
解压
tar -zxvf redis-2.8.6.tar.gz
编译
make
(如果不能编译,请先安装 yum install gcc glib*)
yum install gcc automake autoconf libtool make
yum install gcc gcc-c++

切换到su
查看根目录下的REAME文件,里面有安装的提示
切换到su
查看根目录下的REAME文件,里面有安装的提示
例如:
只使用而不安装
cd src
./redis-server
./redis-cli -h 192.168.1.135
安装redis成服务

cd src
make install
cd utils
./install_server
此时发现一个错误。这个错误只在centos下出现
vim /etc/init.d/redis_6379
会现在此文件中第一行有文件没有分隔。我们手动调整,将\n去掉,手动回车。
启动进程
service redis_6379 start
查看进程
service redis_6379 status
ps -ef|grep redis
进入客户端(查看redis-cli的用法用 redis-cli --help )
redis-cli
清空
redis-cli flushall
导出一个key
redis-cli hkeys users >user.txt

安装密码
vim /etc/redis/6379.conf
找到# requirepass foobared 去掉前面的注释#,并把foobared 替换为你自己的密码password

远程登录
redis-cli -h 192.168.1.103 -p 6379 -a password


基本操作。命令输入部分后按Tab键会有提示,这点和linux类似
set name redis
GET name

ZRANGE ref_a 0 -1 withscores

FLUSHALL

keys *
hkeys *


LRANGE fri_b 0 -1 withscores

del users


EXISTS name

HMSET website google www.google.com yahoo www.yahoo.com

lpush "abc" "c"

zadd world 1 "hello 1"