Redis
 sql >> Database >  >> NoSQL >> Redis

Impossibile connettere Redis Cluster in Elasticache a PHP utilizzando la libreria phpredis

  1. Usa la libreria Predis.

  2. Connettiti a Redis ElastiCache Endpoint in modalità Cluster utilizzando Predis, vedi l'esempio seguente.

    try{ 
        // Put your AWS ElastiCache Configuration Endpoint here.
        $servers  = ['aliceredis.8xyzwu.clustercfg.euw2.cache.amazonaws.com:6379'];
        // Tell client to use 'cluster' mode.
        $options  = ['cluster' => 'redis'];
        // Create your redis client
        $redis = new Predis\Client($servers, $options); 
    
        // Do something you want:
        // Set the expiration for 7 seconds
        $redis->set("tm", "I have data for 7s.");
        $redis->expire("tm", 7);
        $ttl = $redis->ttl("tm"); // will be 7 seconds
    
        // Print out value of the key 'tm'
        var_dump(array("msg"=>"Successfully connected to Redis Cluster.", "val"=>$redis->get("tm"))) ;
    
    }
    catch(Exception $ex){ 
        echo ('Error: ' . $ex->getMessage() ); // output error message.
    }