Redis单点常用命令
- 新安装时redis.conf中需要修改三处内容:
- daemonize -> no
- bind 127.0.0.1注释掉
- protected-mod -> no
-
redis-server redis.conf服务端启动命令 -
redis-cli -p 6379或者直接redis-cli客户端连接命令 -
redis-cli -h host -p port -a password通过IP、端口和密码连接 -
通过客户端关闭服务:
redis-cli -p 6379 shutdown或者直接redis-cli shutdown,或者直接进入到客户端操作入口,使用shutdown命令。 -
实际上凡是以redis-cli开头的命令,都可以直接在客户端操作入口直接使用,redis-cli命令就相当于以客户端的身份发送一条指令
-
scan命令,从海量key中搜索某个匹配的key,相当于分页 -
在redis中,*号为通配符,?为占位符
集群常用命令:(配合本篇文章食用更佳)
- 创建集群命令:
./src/redis-trib.rb create --replicas 2 172.17.0.2:6379 172.17.0.3:6379 172.17.0.4:6379 172.17.0.5:6379 172.17.0.6:6379 172.17.0.7:6379 172.17.0.8:6379 172.17.0.9:6379 172.17.0.10:6379
info replication检查主从状态的指令slaveof 192.168.116.132 6379挂载到master节点redis-sentinel sentinel-6379.conf启动哨兵的命令cluster info打印集群的信息cluster nodes列出集群当前已知的所有节点( node),以及这些节点的相关信息
节点cluster meet <ip> <port>将 ip 和 port 所指定的节点添加到集群当中,让它成为集群的一份子。cluster forget <node_id>从集群中移除 node_id 指定的节点。cluster replicate <master_node_id>将当前从节点设置为 node_id 指定的master节点的slave节点。只能针对slave节点操作。cluster saveconfig将节点的配置文件保存到硬盘里面。
槽(slot)cluster addslots <slot> [slot ...]将一个或多个槽( slot)指派( assign)给当前节点。cluster delslots <slot> [slot ...]:移除一个或多个槽对当前节点的指派。cluster flushslots:移除指派给当前节点的所有槽,让当前节点变成一个没有指派任何槽的节点。cluster setslot <slot> node <node_id>将槽 slot 指派给 node_id 指定的节点,如果槽已经指派给
另一个节点,那么先让另一个节点删除该槽>,然后再进行指派。cluster setslot <slot> migrating <node_id>将本节点的槽 slot 迁移到 node_id 指定的节点中。cluster setslot <slot> importing <node_id>从 node_id 指定的节点中导入槽 slot 到本节点。cluster setslot <slot> stable取消对槽 slot 的导入( import)或者迁移( migrate)。
键cluster keyslot <key>计算键 key 应该被放置在哪个槽上。cluster countkeysinslot <slot>返回槽 slot 目前包含的键值对数量。cluster getkeysinslot <slot> <count>返回 count 个 slot 槽中的键 。
发布订阅
subscribe slgChat创建订阅频道slgChatpublish slgChat "Hello"向slgChat这个频道发送消息psubscribe news.* tweet.*同时订阅多个频道UNSUBSCRIBE [channel [channel …]]退订某个或所有频道PUBSUB CHANNELS [pattern]查看订阅与发布系统状态
Redis单点与集群常用命令汇总

本文介绍了Redis单点和集群的常用命令。单点方面,新安装时需修改redis.conf三处内容,还提及服务端启动、客户端连接及关闭服务等命令。集群方面,涵盖创建集群、检查主从状态、节点操作、槽操作、键操作以及发布订阅等相关命令。
928

被折叠的 条评论
为什么被折叠?



