redis

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2022 License: MIT Imports: 5 Imported by: 0

README

redis

Go codecov Go Report Card Release

Golang redis package based on go-redis and miniredis.

Installation

go get github.com/go-ecosystem/redis

Usage

See more at go-redis.

package example_test

import (
	"context"
	"fmt"

	"github.com/go-ecosystem/redis"
	goredis "github.com/go-redis/redis/v8"
)

var ctx = context.Background()

func ExampleGetClient() {
	redis.SetUp("127.0.0.1", "6379", "")
	defer redis.Close()

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

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

	val2, err := redis.GetClient().Get(ctx, "key2").Result()
	if err == goredis.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
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close() error

Close closes the client, releasing any open resources

func GetClient

func GetClient() *redis.Client

GetClient get redis client

func MockRedis

func MockRedis()

MockRedis mock redis for unittests

func SetUp

func SetUp(host, port, pwd string)

SetUp set up redis connection

func SetUpWithOps

func SetUpWithOps(ops *redis.Options)

SetUpWithOps set up redis connection with Options

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL