在安全組控制臺 新建安全組,點擊 創(chuàng)建安全組,設置安全組名稱,網絡類型選擇 專有網絡,并選擇剛才創(chuàng)建的專有網絡。

創(chuàng)建適合業(yè)務需求的云數(shù)據庫 Redis 版實例可以參考 云數(shù)據庫 Redis 版。
單擊 default 區(qū)域框右側的修改。
在彈出的對話框中,將 函數(shù)計算所在的 VPC 網絡的網段地址配置在白名單輸入框中。


多種語言的客戶端連接阿里云 Redis 可以參考 Redis 客戶端連接。

注意:函數(shù)計算服務所在區(qū)域與公共配置中創(chuàng)建的資源所在區(qū)域一致。
下面演示 Python3 開發(fā)語言訪問 Redis 數(shù)據庫函數(shù)示例創(chuàng)建:
使用 Fun 工具在建立存放代碼和依賴模塊目錄下安裝依賴和項目部署。
ROSTemplateFormatVersion: '2015-09-01'
Transform: 'Aliyun::Serverless-2018-04-03'
Resources:
Redis-test:
Type: 'Aliyun::Serverless::Service'
Properties:
Description: This is Redis service
Role: 'acs:ram::XXX:role/fc-public-test'
LogConfig:
Project: XXX
Logstore: XXXX
VpcConfig:
VpcId: vpc-XXXXX
VSwitchIds:
- vsw-XXXX
SecurityGroupId: sg-XXXX
InternetAccess: true
python-test:
Type: 'Aliyun::Serverless::Function'
Properties:
Initializer: 'index.initializer'
Handler: 'index.handler'
Runtime: python3
Timeout: 10
MemorySize: 128
CodeUri: './'
EnvironmentVariables:
REDIS_HOST: r-XXXXX.redis.rds.aliyuncs.com
REDIS_PASSWORD: XXXXX
REDIS_PORT: '6379'RUNTIME python3
RUN fun-install pip install redis執(zhí)行fun install命令安裝依賴:
$ fun install
using template: template.yml
start installing function dependencies without docker
building Redis-test/python-test
Funfile exist, Fun will use container to build forcely
Step 1/2 : FROM registry.cn-beijing.aliyuncs.com/aliyunfc/runtime-python3.6:build-1.7.7
---> 373f5819463b
Step 2/2 : RUN fun-install pip install redis
---> Running in f26aef48f9e5
Task => PipTask
=> PYTHONUSERBASE=/code/.fun/python pip install --user redis
Removing intermediate container f26aef48f9e5
---> 809c6655f9e9
sha256:809c6655f9e93d137840b1446f46572fbab7548c5c36b6ae66599dfc2e27555b
Successfully built 809c6655f9e9
Successfully tagged fun-cache-78c74899-5497-4205-a670-24e4daf88284:latest
copying function artifact to /Users/txd123/Desktop/Redis/Python
Install Success在函數(shù)根目錄下新建代碼文件,例如 /tmp/code/index.py,在代碼中使用 redis :
# -*- coding: utf-8 -*-
import os,sys
import redis
def initializer(context):
global conn_pool
conn_pool=redis.ConnectionPool(host=os.environ['REDIS_HOST'],password=os.environ['REDIS_PASSWORD'],port=os.environ['REDIS_PORT'],db=1,decode_responses=True)
def handler(event, context):
r = redis.Redis(connection_pool=conn_pool)
r.set('test','89898')
r.set('zyh_info','{"name":"Tanya","password":"123456","account":11234}')
print(r.get('test'))
return r.get('zyh_info')使用 fun 工具部署:
$ fun deploy
using template: template.yml
using region: cn-hangzhou
using accountId: ***********3743
using accessKeyId: ***********Ptgk
using timeout: 60
Waiting for service Redis-test to be deployed...
Waiting for function python-test to be deployed...
Waiting for packaging function python-test code...
The function python-test has been packaged. A total of 25 files files were compressed and the final size was 138.78 KB
function python-test deploy success
service Redis-test deploy success登錄控制臺,即可看到相關的服務、函數(shù)被創(chuàng)建成功,且觸發(fā)執(zhí)行可以返回正確的結果。
另外有需要云服務器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。
網頁名稱:RedisVPC搭建專有網絡-創(chuàng)新互聯(lián)
路徑分享:http://chinadenli.net/article14/dsjsge.html
成都網站建設公司_創(chuàng)新互聯(lián),為您提供服務器托管、App開發(fā)、自適應網站、網頁設計公司、網站改版、ChatGPT
聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)