Redis Client for Golang

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Redis is a very popular memory cache, known for its rich data structure and high performance. This article describes the Golang client Go-redis that uses Redis in Golang.

At present, the better client has Go-redis and Redigo.

Introduction to use

Installation

go get -u github.com/go-redis/redis

Example

...import "github.com/go-redis/redis"...client := redis.NewClient(&redis.Options{    Addr:     "localhost:6379",    Password: "", // no password set    DB:       0,  // use default DB})pong, err := client.Ping().Result()fmt.Println(pong, err)// Output: PONG <nil>err := client.Set("key", "value", 0).Err()if err != nil {    panic(err)}val, err := client.Get("key").Result()if err != nil {    panic(err)}fmt.Println("key", val)val2, err := client.Get("key2").Result()if err == redis.Nil {    fmt.Println("key2 does not exists")} else if err != nil {    panic(err)} else {    fmt.Println("key2", val2)}// Output: key value// key2 does not exists

Description

Create Client

client = redis.NewClient(&redis.Options{})

Executing commands and Results

A variety of REDIS commands can be consulted Http://godoc.org/github.com/go-redis/redis

  Client. Get ("key")//Return is a command. Result ()//returns VAL, Errcommand. ERR ()//returns ERR  
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.