Golang Redis client
Open-source APMGolang ORMGolang ClickHouseBlogGo Redis Newsletter open in new window Reference open in new window GitHub open in new window Newsletter open in new window Reference open in new window GitHub open in new windowGo RedisGolang Redis client for Redis Server and Redis Cluster Introduction Getting started All flavorsOut-of-the-box works with Redis Server, Redis Cluster, Redis Sentinel, and even Ring of Redis Servers.Type-safego-redis provides types for most Redis commands so you can work with well-structured replies.Feature-richWe support pipelines, transactions, publish/subscribe, Lua scripts, mocks, distributed locks, and more.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
Copyright 漏 2022 Go-Redis Authors