tonglin0325的个人主页

Ubuntu安装redis缓存数据库

参考:http://blog.csdn.net/xiangwanpeng/article/details/54586087

1.在下载目录下

1
2
sudo wget http://download.redis.io/releases/redis-3.2.6.tar.gz

2.解压,并复制到/usr/local目录下

1
2
3
tar -zxvf redis-3.2.6.tar.gz
mv redis-3.2.6 /usr/local/

3.编译和安装

1
2
3
4
cd /redis
sudo make
sudo make install

4.在redis安装文件夹中修改文件redis.conf,使得redis在后台运行

1
2
3
vim redis.conf
#修改daemonize yes

5.启动redis

1
2
3
redis-server redis.conf
redis-cli -p 6379

 

6.安装redis desktop manager

按照 http://blog.csdn.net/u013410747/article/details/51706964 的步骤

安装deb安装包,需要依赖libicu52

/etc/apt/目录下,先拷贝一份cp sources.list sources.list1

然后使用网易的源

1
2
deb http://mirrors.163.com/ubuntu/ trusty main restricted universe multiversedeb http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiversedeb http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiversedeb http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiversedeb http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiversedeb-src http://mirrors.163.com/ubuntu/ trusty main restricted universe multiversedeb-src http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiversedeb-src http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiversedeb-src http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiversedeb-src http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse

 更新源

1
2
sudo apt-get update

1
2
sudo apt-get -f install libicu52

 最后安装 redis-desktop-manager_0.8.3-120_amd64.deb

 

给redis设置密码,需要在redis.conf的配置文件中添加

1
2
requirepass xxxx

否则会报没有权限

1
2
(error) NOAUTH Authentication required

需要添加密码参数

1
2
redis-cli -p 6379 -a xxxx

 

redis默认的databases有16个,可以在配置文件中配置

1
2
databases 16

使用select来选择当前的库

1
2
3
4
5
127.0.0.1:6379> select 1
OK
127.0.0.1:6379[1]> select 0
OK

可以使用 keys *来查看redis中的数据,不过由于redis是单线程的,所以禁止在生产环境中使用keys命令

1
2
keys *

可以使用scan命令来替代keys命令

1
2
scan 0 match user* count 10

查看key的数据类型,不同的key所对应的命令不一样,否则会报 (error) WRONGTYPE Operation against a key holding the wrong kind of value

1
2
type XXXXX

 zset的zcan命令,ZSCAN key cursor [MATCH pattern] [COUNT count]

1
2
https://www.runoob.com/redis/sorted-sets-zscan.html

比如

1
2
ZSCAN XXXX 0