问题描述

使用6379端口连接Azure Redis服务,连接失败。因为默认情况下Azure Redis的设置没有打开6379的端口。需要使用SSL(6380端口)进行连接,但是遇见了无法连接的问题。

使用非SSL(6379端口)的连接代码

<?php
echo "Azure Redis Connect Test";
echo "<br/>"; //连接本地的 Redis 服务
$redis = new Redis();
$redis->connect('xxxxxxxx.redis.cache.chinacloudapi.cn', 6379);
$redis->auth("秘钥"); echo "Connection to server sucessfully";
echo "<br/>"; //设置 redis 字符串数据
$redis->set("test-name", "Redis test value");
// 获取存储的数据并输出
echo "Stored string in redis:: " . $redis->get("test-name");
?>

如果直接修改端口号 6379 为 6380, 报错无法访问。那么使用6380的正确方式为?

问题解答

其实,代码的改动方式非常小。在 connection 方法中添加 TLS及6380端口。

改动前:$redis->connect('xxxxxxxx.redis.cache.chinacloudapi.cn', 6379);

改动后:$redis->connect('tls://xxxxxxxx.redis.cache.chinacloudapi.cn', 6380);

但是一定要注意php redis 扩展,因为扩展版本过低,有可能会引发解析问题。如类似如下的错误消息:

Azure Redis Connect Test<br/>PHP Warning:  
Redis::connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /data/myweb/redis_tes
t2.php on line 6
PHP Fatal error: Uncaught RedisException: php_network_getaddresses: getaddrinfo failed: Name or service not known in /data/myweb/redis_test2.php:6
Stack trace:
#0 /data/myweb/redis_test2.php(6): Redis->connect('tls://xxxx-xxxx...', 6380)
#1 {main}
thrown in /data/myweb/redis_test2.php on line 6

php redis 扩展的版本:

使用TLS 6380 端口连接Redis的示例代码为:

<?php
echo "Azure Redis Connect Test";
echo "<br/>"; //连接本地的 Redis 服务
$redis = new Redis();
//$redis->connect('xxxxxxxx.redis.cache.chinacloudapi.cn', 6379);
$redis->connect('tls://xxxxxxxx.redis.cache.chinacloudapi.cn', 6380);
$redis->auth("秘钥"); echo "Connection to server sucessfully";
echo "<br/>"; //设置 redis 字符串数据
$redis->set("test-name", "Redis test value");
// 获取存储的数据并输出
echo "Stored string in redis:: " . $redis->get("test-name");
?>

参考资料

php redis example : https://github.com/phpredis/phpredis#example-2

php redis extension : https://pecl.php.net/package/redis

【Azure Redis 缓存】Azure Redis服务开启了SSL(6380端口), PHP如何访问缓存呢?的更多相关文章

  1. Linux CentOS7 开启80,443端口外网访问权限

    一.查看系统防火墙状态(如果返回 running 代表防火墙启动正常) firewall-cmd --state 二.开启端口外网访问 1.添加端口 返回 success 代表成功(--permane ...

  2. 【Azure Redis 缓存】Azure Cache for Redis服务中,除开放端口6379,6380外,对13000,13001,15000,15001 为什么也是开放的呢?

    问题描述 在使用安全检测工具对Azure Redis服务端口进行扫描时,发现Redis对外开放了13001, 13000,15000,15001端口.非常不理解的是,在门户上只开放了6379,6380 ...

  3. 【Azure Redis 缓存】云服务Worker Role中调用StackExchange.Redis,遇见莫名异常(RedisConnectionException: UnableToConnect on xxx 或 No connection is available to service this operation: xxx)

    问题描述 在Visual Studio 2019中,通过Cloud Service模板创建了一个Worker Role的角色,在角色中使用StackExchange.Redis来连接Redis.遇见了 ...

  4. 【Azure Redis 缓存】Linux虚拟机中使用6380端口(SSL方式)连接Azure Redis (redis-cli & stunnel)

    问题描述 在Azure Redis的官方文档中,介绍了在Windows下,如何通过redis-cli.exe连接Redis, 包含如何配置stunnel使得通过 6380,SSL方式连接到Redis ...

  5. Azure技术系列之Redis篇---第一章数据缓存

    嘈杂和忙碌的生活占据占据了生活的每一天,好久没有静下心来对自己喜欢的技术进行归纳总结了.痛定思痛,今天开始开荒,把之前研究的技术进行归纳总结,先从Azure的Redis的开发技术开始. Azure 的 ...

  6. 【Azure Redis 缓存 Azure Cache For Redis】在创建高级层Redis(P1)集成虚拟网络(VNET)后,如何测试VNET中资源如何成功访问及配置白名单的效果

    当使用Azure Redis高级版时候,为了能更好的保护Redis的安全,启用了虚拟网路,把Redis集成在Azure中的虚拟网络,只能通过虚拟网络VENT中的资源进行访问,而公网是不可以访问的.但是 ...

  7. 【Azure Redis 缓存 Azure Cache For Redis】使用Redis自带redis-benchmark.exe命令测试Azure Redis的性能

    问题描述 关于Azure Redis的性能问题,在官方文档中,可以查看到不同层级Redis的最大连接数,每秒处理请求的性能. 基本缓存和标准缓存 C0 (250 MB) 缓存 - 最多支持 256 个 ...

  8. 【Azure Redis 缓存 Azure Cache For Redis】Azure Redis由低级别(C)升级到高级别(P)的步骤和注意事项, 及对用户现有应用的潜在影响,是否需要停机时间窗口,以及这个时间窗口需要多少的预估问题

    问题描述 由于Azure Redis的性能在不同级别表现不同,当需要升级/缩放Redis的时候,从使用者的角度,需要知道有那些步骤? 注意事项? 潜在影响?停机事件窗口? 升级预估时间? 解决方案 从 ...

  9. [Windows Azure] 使用 Windows Azure 快速搭建 Redis 服务器

    [Windows Azure] 使用 Windows Azure 快速搭建 Redis 服务器   Redis相信玩开源,大数据的朋友们并不陌生,大家最熟悉的使用者就是新浪微博,微博的整体数据缓存都是 ...

  10. 缓存技术Redis在C#中的使用及Redis的封装

    Redis是一款开源的.高性能的键-值存储(key-value store).它常被称作是一款数据结构服务器(data structure server).Redis的键值可以包括字符串(string ...

随机推荐

  1. vite构建打包产物

    构建打包产物 build: { assetsInlineLimit: 10240, //静态资源(不会包含js,css)不超过10kb 转化为 base64 [不好含css js] outDir: & ...

  2. 【译】PEP-3129 类装饰器

    PEP原文 : https://www.python.org/dev/peps/pep-3129 PEP标题: Class Decorators PEP作者: Collin Winter 创建日期: ...

  3. Gin 框架之Cookie与Session

    目录 一.Cookie和Session的由来 二.Cookie简介 1. 什么是Cookie 2. Cookie规范 3. 安全性 4. Cookie 关键配置 三.Session简介 1. 什么是S ...

  4. Asp.Net MVC中点击按钮导出Excel

    一.Excel导出帮助类,要安装包NPOI 1 using NPOI.HSSF.UserModel; 2 using NPOI.SS.UserModel; 3 using System; 4 usin ...

  5. SqlSugar分组查询

    一.分组查询和使用 1.1 语法 只有在聚合对象需要筛选的时候才会用到Having,一般分组查询用不到可以去掉   var list = db.Queryable<Student>()   ...

  6. C/C++ 感染标志与空字节感染

    C/C++ 通过搜索PE结构中的空隙部分,对指定文件写入感染标志,作用是,如果程序被感染过则不再继续感染,而搜索空字节,则是要将恶意代码动态的填充到可执行文件中,并劫持执行流,以下代码就是这两种代码的 ...

  7. Visual Studio部署C++矩阵库Armadillo的方法

      本文介绍在Visual Studio软件中配置C++环境下线性代数运算库Armadillo的方法.   首先,我们需要在Armadillo库官网下载其源代码,直接点击下图所示红色框内部分即可.   ...

  8. 小知识:Oracle中的层次查询

    使用Oracle中的start with .. connect by prior ..语句可以轻松实现. 下面通过scott用户下的emp来做演示,使用自己的一个19c测试环境,结果发现默认并没有sc ...

  9. delphi中 注意一点,record 类型 参数默认是 值拷贝,class 参数 默认是传地址;值传递,指针传递、引用传递

    作为函数的入参,若是record类型,默认是值拷贝,效率低,若要传指针,需要加 var ; 作为函数的入参,若是 class类型,默认是传地址,不需要加var unit Unit1; interfac ...

  10. Kafka-如何重设消费者位移(重设OFFSET)

    1. 为什么要重设消费者组位移? 我们知道,Kafka 和传统的消息引擎在设计上是有很大区别的,其中一个比较显著的区别就是,Kafka 的消费者读取消息是可以重演的(replayable). 像 Ra ...