Skip to content
This repository has been archived by the owner on Oct 1, 2023. It is now read-only.
/ starter-go-redis Public archive

「仅发布」 go-redis 启动器 ( starter for go-redis )

License

Notifications You must be signed in to change notification settings

go-spring/starter-go-redis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

starter-go-redis

English

[仅发布] 该项目仅为最终发布,不要向该项目直接提交代码,开发请关注 go-spring 项目。

Installation

Prerequisites

  • Go >= 1.12

Using go get

go get github.com/go-spring/[email protected] 

Quick Start

import "github.com/go-spring/starter-go-redis"

main.go

package main

import (
	"errors"
	"fmt"

	"github.com/go-spring/spring-base/util"
	"github.com/go-spring/spring-core/gs"
	"github.com/go-spring/spring-core/redis"
	
	_ "github.com/go-spring/starter-go-redis"
)

type runner struct {
	Client redis.Client `autowire:""`
}

func (r *runner) Run(ctx gs.Context) {

	_, err := r.Client.Get(ctx.Context(), "nonexisting")
	if err != redis.ErrNil {
		panic(errors.New("should be redis.ErrNil"))
	}

	_, err = r.Client.Set(ctx.Context(), "mykey", "Hello")
	util.Panic(err).When(err != nil)

	v, err := r.Client.Get(ctx.Context(), "mykey")
	util.Panic(err).When(err != nil)
	if v != "Hello" {
		panic(errors.New("should be \"Hello\""))
	}

	fmt.Printf("GET mykey=%q\n", v)
	go gs.ShutDown()
}

func main() {
	gs.Object(&runner{}).Export((*gs.AppRunner)(nil))
	fmt.Printf("program exited %v\n", gs.Web(false).Run())
}

Configuration

About

「仅发布」 go-redis 启动器 ( starter for go-redis )

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages