Connecting to Redis To Go with PHP

前端 未结 3 535
没有蜡笔的小新
没有蜡笔的小新 2020-12-11 23:15

I am a newbie with Redis...I just recently picked up Redisent to work with Redis in PHP...and I am having tons of fun! However, I signed up for the Redis to go service, and

相关标签:
3条回答
  • 2020-12-11 23:36

    predis is the prefered library(active development => 6 Januari 2011) to use.

    redis://$x:$y@$z
    

    Then you need the following code to get it working(I tested it):

    <?php
    
    require('./Predis.php');
    
    #redis://$x:$y@$z
    $redis   = new Predis\Client('redis://$z');
    $redis->auth($y);
    $redis->incr('counter');
    echo $redis->get('counter');
    echo "\n";
    

    The strange thing is $x. It is not needed at all?

    0 讨论(0)
  • 2020-12-11 23:44

    According to the documentation now, you can do this as part of the instantiation...

    $redis = new Predis\Client(array(
        'host'     => '10.0.0.1', 
        'password' => 'secret', 
        'database' => 10, 
    ));
    

    or

    $redis = new Predis\Client('redis://10.0.0.1/?password=secret&database=10');
    
    0 讨论(0)
  • 2020-12-11 23:45
    $db = 1;
    $password='password';
    $aRedisServers['host']="127.0.0.1";
    $aRedisServers['port']= "6379";
    $r = new Predis_Client();
    $r->connect($aRedisServers['host'], $aRedisServers['port']);
    $r->auth($password);
    $r->select($db);
    
    $r->set("set","new");
    echo $r->get("set");
    //output new
    
    0 讨论(0)
提交回复
热议问题