redisd

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2020 License: MIT Imports: 9 Imported by: 0

README

MGEs.Redisd

MGEs框架下,基于go-redis的简单生命周期封装。

依赖

  • MGEs.Base^0.3.0

  • go-redis^v6.15.5

  • @Attention:主程序必须调用workflow.Lifecycle_Start,否则服务不会运行!

安装

go get gitlab.com/MGEs/Redisd

例子

package main

import (
	"github.com/go-redis/redis"

	"gitlab.com/MGEs/Base/workflow"
	redisd "gitlab.com/MGEs/Redisd"
)

var redisClient *redis.Client

func init() {
	if cfg, err := redisd.NewConfig(redisd.ConfigEntry{
		Comment:   "SSO",
		Mode:      redisd.ConfigMode_Flag | redisd.ConfigMode_File,
		FlagNames: []string{"-redisd"},
		FileEntry: []string{"api", "redisd"},
	}); err != nil {
		workflow.Throw(err, workflow.TlPanic)
	} else if iErr := cfg.Setup(func(client *redis.Client) []error {
		redisClient = client
		return nil
	}); iErr != nil {
		workflow.Throw(iErr, workflow.TlPanic)
	}
}

func main() {
	if err := workflow.Lifecycle_Start(); err != nil {
        panic(err)
    }
}

Licensing

The MIT License (MIT)

Copyright (c) 2018 - 2020 Kitagawa Kenta.

Documentation

Index

Constants

View Source
const (
	EVT_S__Redisd_HelpMsg = "MGEs.Redisd"
	Flag_HelpEntry        = "MGEs.Redisd"
)
View Source
const (
	EVT_S__Redisd_Subscriber = "MGEs.Redisd.BootUp"
	EVT_OD_Redisd_Shutdown   = workflow.EventPriority_Latest - 10
)
View Source
const (
	ConfigMode_Internal = 1 << (8 - 1 - iota)
	ConfigMode_Flag
	ConfigMode_File
)

Variables

View Source
var (
	EM_Redisd_FailedToRegisterParameters = workflow.NewMask(
		"Redisd:FailedToRegisterParameters",
		"注册参数失败",
	)
	EM_Redisd_FailedToRegisterEvent = workflow.NewMask(
		"Redisd:FailedToRegisterEvent",
		"Redisd:注册事件失败",
	)
	EM_Redisd_FailedToCreateInstance = workflow.NewMask(
		"Redisd:FailedToCreateInstance",
		"Redisd:实例化数据库配置失败",
	)
	EM_Redisd_FailedToConfigInstance = workflow.NewMask(
		"Redisd:FailedToConfigInstance",
		"Redisd:配置数据库实例失败",
	)
	EM_Redisd_InstanceCreated = workflow.NewMask(
		"Redisd:InstanceCreated",
		"[Redisd] 已创建链接 {{name}}",
	)
	EM_Redisd_InstanceClosed = workflow.NewMask(
		"Redisd:InstanceClosed",
		"[Redisd] 已关闭链接 {{name}}",
	)
)

Functions

func DefaultFlagDoc added in v0.2.0

func DefaultFlagDoc() *flags.Document

Types

type Config

type Config struct {
	Tls bool
	mnet.ListenerConfig
	mnet.TlsConfig
	Database int
	Password string
	Comment  string
	// contains filtered or unexported fields
}

func NewConfig

func NewConfig(entry ConfigEntry) (*Config, error)

func (*Config) Setup

func (c *Config) Setup(setup func(*redis.Client) []error) error

type ConfigEntry

type ConfigEntry struct {
	Mode         ConfigMode
	FlagNames    []string
	FlagGroup    *flags.Group
	FlagDocument *flags.Document
	FileEntry    []string
	Comment      string
}

type ConfigMode

type ConfigMode uint8

Jump to

Keyboard shortcuts

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