Redis命令汇总

设置服务后台启动

 

cd /usr/local/redis
view redis.conf 将daemonize no改为 daemonize yes保存退出 启动:
./reids-server redis.conf
退出后,使用redis-cli测试

客户端连接服务端命令:
./redis-cli -h 127.0.0.1/ip -p 26537/port

 

 

linux下设置登录密码

 

vim  /etc/redis.conf

#requirepass foobared去掉注释,foobared改为自己的密码,我在这里改为

requirepass 123456

然后保存,重启服务

cd /usr/local/bin

./redis-server /etc/redis.conf

测试连接:./redis-cli 

输入命令 会提示没有权限访问(error) NOAUTH Authentication required

然后输入:auth 123456

登陆成功,可以使用命令了

 

 

常用命令

 

#查看所有key
keys *  或  keys "*"

#查看匹配前缀的keys
keys "miao*"

#清空redis
flushdb

#查看redis正在做什么
monitor

设置值:
set key value:设置key的值,若存在则覆盖 get key:获取key对应的值 MGET key1 key2 ... keyN:获取这些key对应的值 del key:删除元素 有效期: EXPIRE key seconds:设置该元素多少秒后失效 PEXPIRE key milliseconds:设置该元素多少毫秒后失效 TTL key:查看还可以存活多少秒,-2表示key不存在,-1表示永久存储

 

 

其他命令

参考文章:http://www.cnblogs.com/woshimrf/p/5198361.html

Redis教程:http://www.redis.net.cn/tutorial/3503.html

posted @ 2017-10-17 12:16  NewLife365  阅读(335)  评论(0编辑  收藏  举报