Access the Redis Instance from a Go client
<p>After you created an ECS instance and a whitelist entry, install a GO client on the ECS instance and access the Redis instance from the GO client.</p>
<p><strong><span style="font-size:18px">Prerequisites</span></strong></p>
<ol>
<li>You have successfully created a Redis instance. For more information, see <a href="http://pinganyun.com/ssr/help/database/Redis/Getting_Started.Create_Redis" target="_blank">Create a Redis Instance</a>. Make sure the instance is in running status.</li>
<li>You have successfully created an ECS instance. For more information, see <a href="http://pinganyun.com/ssr/help/database/Redis/Getting_Started.Create_ECS" target="_blank">Create an ECS Instance</a>. Make sure the instance is in running status.</li>
<li>You have successfully created a whitelist entry. For more information, see <a href="http://pinganyun.com/ssr/help/database/Redis/Getting_Started.Create_Whitelist" target="_blank">Create a Whitelist Entry</a>.</li>
</ol>
<p><strong><span style="font-size:18px">Procedures</span></strong></p>
<p>1. Log in to the ECS instance.</p>
<p> a. Log in to the <a href="https://pinganyun.com/console/ecs/overview" target="_blank">ECS Console</a>.</p>
<p> b. In the left navigation pane, click <strong>Instance</strong> to enter the <strong>Instance Management</strong> page.</p>
<p> c. In the <strong>Operations</strong> column for the target instance, click <strong>ECS Console</strong>.</p>
<p> d. Enter the username and password.</p>
<p>2. After configuring the running environment of GO, download and install the GO client.</p>
<p>Download the client from <a href="http://github.com/chasex/redis-go-cluster" target="_blank">download address</a> if the Redis instance is a cluster instance.</p>
<p>3. Connect to the Redis instance.</p>
<p>Execute the following codes to connect to the Redis cluster instance:</p>
<pre>
<code>package main
import "github.com/chasex/redis-go-cluster"
import "fmt"
import "time"
func main() {
cluster, err := redis.NewCluster(
&redis.Options{
StartNodes: []string{"Domain-name:Port"}, //Specify the domain name and port number of the Redis cluster instance
PassWord: "Password", //Specify the password of the Redis instance
ConnTimeout: 3000 * time.Millisecond,
ReadTimeout: 3000 * time.Millisecond,
WriteTimeout: 3000 * time.Millisecond,
KeepAlive: 32,
AliveTime: 60000 * time.Second,
})
cluster.Do("SET","foo","pingan yun")
reply , err := (cluster.Do("GET","foo"))
if err != nil {
fmt.Printf("Get error :%s\n",err.Error())
}
fmt.Printf("%s\n", reply)
}</code></pre>
<p><img src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20201507141831-119d46cb927d.png" style="height:20px; margin:0px; width:80px" />:</p>
<ul>
<li>Domain-Name: Access domain name of the Redis instance. For more information, see <a href="http://pinganyun.com/ssr/help/database/Redis/User_Guide.Instance_Management.View_Instance" target="_blank">View Basic Information about an Instance</a>.</li>
<li>Port: Port number of the Redis instance. For more information, see <a href="http://pinganyun.com/ssr/help/database/Redis/User_Guide.Instance_Management.View_Instance" target="_blank">View Basic Information about an Instance</a>.</li>
<li>Password: Password of the Redis instance when you created the Redis instance. For more information, see <a href="http://pinganyun.com/ssr/help/database/Redis/User_Guide.Instance_Management.View_Instance" target="_blank">View Basic Information about an Instance</a>.</li>
</ul>
<p><strong><span style="font-size:18px">Result</span></strong></p>
<p>The system returns pingan yun, indicating that the Jedis client has been connected to the Redis instance.</p>
Did the above content solve your problem?
Yes
No
Submitted successfully! Thank you for your feedback, we will try our best to do better and better!