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

「仅发布」redigo 模块启动器 ( starter for redigo )

License

Notifications You must be signed in to change notification settings

go-spring/starter-redigo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

starter-redigo

English

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

Installation

Prerequisites

  • Go >= 1.12

Using go get

go get github.com/go-spring/starter-redigo@v1.1.0-rc2 

Quick Start

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

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-redigo"
)

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

「仅发布」redigo 模块启动器 ( starter for redigo )

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages