IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    Redis教程系列(4):Redis 命令

    铁匠发表于 2017-04-07 04:11:31
    love 0

    Redis 命令用于在 redis 服务上执行操作。

    要在 redis 服务上执行命令需要一个 redis 客户端。Redis 客户端在我们之前下载的的 redis 的安装包中。

    语法

    Redis 客户端的基本语法为:

    [root@tiejiangSRC2 ~]# redis-cli

    实例

    以下实例讲解了如何启动 redis 客户端:

    启动 redis 客户端,打开终端并输入命令 redis-cli。该命令会连接本地的 redis 服务。

    [root@tiejiangSRC2 ~]# redis-cli 
         127.0.0.1:6379> 
         127.0.0.1:6379> PING
         PONG

    在以上实例中我们连接到本地的 redis 服务并执行 PING 命令,该命令用于检测 redis 服务是否启动。


    在远程服务上执行命令

    如果需要在远程 redis 服务上执行命令,同样我们使用的也是 redis-cli 命令。

    语法

    [root@tiejiangSRC2 ~]# redis-cli -h host -p port -a password

    实例

    以下实例演示了如何连接到主机为 127.0.0.1,端口为 6379 ,密码为 mypass 的 redis 服务上。

    [root@tiejiangSRC2 ~]# redis-cli -h 127.0.0.1 -p 6379 -a "mypass"
         redis 127.0.0.1:6379>
         redis 127.0.0.1:6379> PING
         PONG



沪ICP备19023445号-2号
友情链接