tencent cloud

Feedback

Go Connection Sample

Last updated: 2022-07-05 10:56:24

Preparations before running:

Download the Go-redis client.

Sample code:

package main
import(
   "fmt"
   "redis"
   "log"
)
func main() {
   const host=192.xx.xx.195
  const port=6379
  const instanceId="84ffd722-b506-4934-9025-64xxx997b"
  const pass="123d7sq"
  // Connect to the Redis server 192.xx.xx.195:6379 and authorize the instanceId password
  spec := redis.DefaultSpec().Host(host).Port(port).Password(instanceId+":"+pass);
  client, err := redis.NewSynchClientWithSpec(spec)
   if err != nil { // Whether the connection is incorrect
      log.Println("error on connect redis server")
      return
   }
   newvalue :=[]byte("QcloudV5!");
   err=client.Set("name",newvalue);
   if err != nil { // Incorrect value set
      log.Println(err)
      return
   }
   value, err := client.Get("name") // Value
   if err != nil { 
      log.Println(err)
      return
   }
   fmt.Println("name value is:",fmt.Sprintf("%s", value)) // Output
} 

Execution result:

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

7x24 Phone Support