无法使用phpredis库将Elasticache中的Redis群集连接到PHP
我能够使用ec2实例(在aws文档中给出)连接到elasticache中的redis集群,并能够添加和获取键、值。但当我尝试在同一个ec2实例上通过phpredis进行连接时,我没有得到任何错误和数据。请帮我做这个。互联网上没有太多关于这个具体问题的信息。我可以连接到运行在同一ec2实例上的redis,但不能连接到elasticache。如果我能得到一些关于除了更改主机(redis集群的端点)之外如何执行的示例。 谢谢无法使用phpredis库将Elasticache中的Redis群集连接到PHP,php,redis,amazon-elasticache,Php,Redis,Amazon Elasticache,我能够使用ec2实例(在aws文档中给出)连接到elasticache中的redis集群,并能够添加和获取键、值。但当我尝试在同一个ec2实例上通过phpredis进行连接时,我没有得到任何错误和数据。请帮我做这个。互联网上没有太多关于这个具体问题的信息。我可以连接到运行在同一ec2实例上的redis,但不能连接到elasticache。如果我能得到一些关于除了更改主机(redis集群的端点)之外如何执行的示例。 谢谢 使用图书馆 使用Predis在集群模式下连接到Redis ElastiCac
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.
}
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.
}
你是说你有一个用Elasticache制作的Redis集群,还有一个单独的EC2实例,上面运行着PHP,你想访问这个Elasticache集群吗?您的PHPRedis connect声明是什么样子的?谢谢您的回复,是的,但vpc相同。我用的是phpredis。它可以在本地连接到redis,但不能连接到elasticache,尽管我可以在同一个ec2实例中使用命令行访问elasticache$redis=新的redis()$redis->pconnect({redis elasticache端点}',6379);你是说你有一个用Elasticache制作的Redis集群,还有一个单独的EC2实例,上面运行着PHP,你想访问这个Elasticache集群吗?您的PHPRedis connect声明是什么样子的?谢谢您的回复,是的,但vpc相同。我用的是phpredis。它可以在本地连接到redis,但不能连接到elasticache,尽管我可以在同一个ec2实例中使用命令行访问elasticache$redis=新的redis()$redis->pconnect({redis elasticache端点}',6379);