doc-exports/docs/fg/umn/functiongraph_03_0300.html
Chen, Junjie dac566cf2f FG UMN 20230725 version
Reviewed-by: Eotvos, Oliver <oliver.eotvos@t-systems.com>
Co-authored-by: Chen, Junjie <chenjunjie@huawei.com>
Co-committed-by: Chen, Junjie <chenjunjie@huawei.com>
2024-04-03 10:30:56 +00:00

25 lines
2.8 KiB
HTML

<a name="functiongraph_03_0300"></a><a name="functiongraph_03_0300"></a>
<h1 class="topictitle1">How Does a Function Access Redis?</h1>
<div id="body1590129418493"><p id="functiongraph_03_0300__p1332001735016">Perform the following operations:</p>
<ol id="functiongraph_03_0300__ol79191213243"><li id="functiongraph_03_0300__li1886323815246">Check whether the Redis instance is deployed in a VPC.<ul id="functiongraph_03_0300__ul886383810248"><li id="functiongraph_03_0300__li9863143820248">If the Redis instance is deployed in a VPC, configure the same VPC and subnet as the Redis instance for the function by referring to section "Configuring VPC Access".</li><li id="functiongraph_03_0300__li686393852418">If the Redis instance is built on a public network, obtain its public IP address.</li></ul>
</li><li id="functiongraph_03_0300__li19142143272511">Compile code for connecting a function to the Redis instance.<p id="functiongraph_03_0300__p1519119185611"><a name="functiongraph_03_0300__li19142143272511"></a><a name="li19142143272511"></a>FunctionGraph has integrated third-party library <a href="https://github.com/andymccurdy/redis-py" target="_blank" rel="noopener noreferrer">redis-py</a> in its Python 2.7 and Python 3.6 runtimes. Therefore, you do not need to download any other Redis libraries.</p>
<pre class="codeblock" id="functiongraph_03_0300__codeblock10873113918484"># -*- coding:utf-8 -*-
import redis
def handler (event, context):
r = redis.StrictRedis(host="host_ip",password="passwd",port=6379)
print(str(r.get("hostname")))
return "^_^"
</pre>
<div class="note" id="functiongraph_03_0300__note11881448151811"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="functiongraph_03_0300__ul820717074210"><li id="functiongraph_03_0300__li1438862013581">If the function fails to access to the Redis instance on a public network, perform the following operations:<ul id="functiongraph_03_0300__ul189861724145816"><li id="functiongraph_03_0300__li129861924165810">Modify the <strong id="functiongraph_03_0300__b1944145615018">redis.conf</strong> file to allow access from any IP addresses.</li><li id="functiongraph_03_0300__li423029195815">Set a password for accessing the Redis instance in the <strong id="functiongraph_03_0300__b102551681811">redis.conf</strong> file.</li><li id="functiongraph_03_0300__li48761632195811">Disable the firewall.</li></ul>
</li><li id="functiongraph_03_0300__li299483712583">If the function needs to access DCS APIs, create an agency and grant required permissions.</li></ul>
</div></div>
</li></ol>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="functiongraph_03_0355.html">External Resource Access FAQs</a></div>
</div>
</div>