簡體   English   中英

無法使用phpredis庫將Elasticache中的Redis集群連接到PHP

[英]Cannot connect Redis Cluster in Elasticache to PHP using phpredis library

我能夠使用ec2實例連接到Elasticache中的Redis集群(在AWS文檔中提供),並且能夠添加和獲取鍵,值。 但是,當我嘗試在同一ec2實例上通過phpredis連接時,我沒有錯誤,也沒有數據。 請幫我解決一下這個。 互聯網上沒有關於此特定問題的大量信息。 我能夠連接到在同一ec2實例上運行的Redis,但無法連接到Elasticache。 如果我能得到一些關於如何更改主機(Redis群集的端點)以外的示例。 謝謝

  1. 使用Predis庫。

  2. 使用Predis以群集模式連接到Redis ElastiCache端點,請參見以下示例。

     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. } 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM