dibrinsofor / redis-docs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

home title actions features footer
true
Golang Redis client
text link type
Introduction
/guide/
primary
text link type
Getting started
/guide/go-redis.html
secondary
title details
All flavors
Out-of-the-box works with Redis Server, Redis Cluster, Redis Sentinel, and even Ring of Redis Servers.
title details
Type-safe
go-redis provides types for most Redis commands so you can work with well-structured replies.
title details
Feature-rich
We support pipelines, transactions, publish/subscribe, Lua scripts, mocks, distributed locks, and more.
Copyright © 2022 Go-Redis Authors
package main

import (
	"context"
	"github.com/go-redis/redis/v8"
)

func main() {
	ctx := context.Background()

	rdb := redis.NewClient(&redis.Options{
		Addr:	  "localhost:6379",
		Password: "", // no password set
		DB:		  0,  // use default DB
	})

	err := rdb.Set(ctx, "key", "value", 0).Err()
	if err != nil {
		panic(err)
	}

	val, err := rdb.Get(ctx, "key").Result()
	if err != nil {
		panic(err)
	}
	fmt.Println("key", val)

	val2, err := rdb.Get(ctx, "key2").Result()
	if err == redis.Nil {
		fmt.Println("key2 does not exist")
	} else if err != nil {
		panic(err)
	} else {
		fmt.Println("key2", val2)
	}
	// Output: key value
	// key2 does not exist
}

About


Languages

Language:JavaScript 100.0%