ubuntu16.04 安装 操作 redis

安装redis

apt-get installl redis-server

安装php-redis

apt-get installl php-redis

检查redis进程

ps -aux|grep redis

通过命令行访问redis  基本操作

root@ubuntu16:~# redis-cli

# 查看所有的key列表
127.0.0.1:6319>keys *
(empty list or set)
# 增加一条记录key1
127.0.0.1:6379> set key1 "hello world"
OK
# 打印记录
redis 127.0.0.1:6379> get key1
"hello world"

# 增加一条数字记录
127.0.0.1:6379> set key2 1
OK

# 让数字自增
127.0.0.1:6379> INCR key2
(integer) 2

#增加一个列表记录key3
127.0.0.1:6379> LPUSH key3 a
(integer) 1

# 从左边插入列表
127.0.0.1:6379> LPUSH key3 b
(integer) 2

# 从右边插入列表
127.0.0.1:6379> RPUSH key3 c
(integer) 3

# 打印列表记录,按从左到右的顺序
127.0.0.1:6379> LRANGE key3 0 3
1) "b"
2) "a"
3) "c"

# 删除key1,key2
127.0.0.1:6379> del key1
(integer) 1
127.0.0.1:6379> del key2
(integer) 1

设置redis 密码 123456

vi /etc/redis/redis.conf

#取消注释requirepass foobared
requirepass 123456

#保存退出

密码登录redis

redis-cli -h 127.0.0.1 -a 123456 -p 6379

# 切记 -h -a -p 后面的空格必须有

开启redis远程连接

vi /etc/redis/redis.conf

#注释bind 127.0.0.1
#bind 127.0.0.1

重启Redis服务器

service redis restart

# 或者

/etc/init.d/redis-server restart

检查Redis服务器占用端口

root@ubuntu16:~# netstat -nlt|grep 6379
tcp        0      0 0.0.0.0:6379            0.0.0.0:*               LISTEN

远程连接redis

root@ubuntu:~# redis-cli -h 192.168.159.129 -a 123456 -h 6379
192.168.129.129:6379>

命令号不带密码连接redis

root@ubuntu:~# redis-cli -h 192.168.159.129 -h 6379
192.168.129.129:6379>auth 123456
OK
192.168.129.129:6379>keys *
1) "key2"
1) "key1"

在Redis集群中使用认证密码

如果Redis服务器,使用了集群。除了在master中配置密码外,也需要在slave中进行相应配置。在slave的配置文件中找到如下行,去掉注释并修改与master相同的密码即可:

# masterauth master-password
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值