2012-03-09 21:38 阅读 50


I'd like know what is the way to connect to redis using php from scratch (without use a client like predis)?


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    dpruwm6206 dpruwm6206 2012-03-09 22:22

    You can connect by using fsockopen and communicate by sending raw commands and reading server response:

    $c = fsockopen('', 6379, $errCode, $errStr);
    $rawCommand = "*2
    hello world!
    fwrite($c, $rawCommand);
    $rawResponse = fgets($c);
    echo $rawResponse; // $12
    $rawResponse = fgets($c);
    echo $rawResponse; // hello world!

    To use it this way, you should get familiar with Redis protocol:

    点赞 评论 复制链接分享
  • dsfsda121545 dsfsda121545 2012-03-09 22:38

    Using a raw TCP connection is one way.

    You could easily reference the Predis code to see how they connect.

    And that is basically a wrapper for : So I would reference that page for the most verbose info.

    If I am not mistaken, it would be the same as making a TELNET connection in the command line and interfacing with Redis in that manner.

    Hope that helps.

    点赞 评论 复制链接分享