redis

package module
v0.0.0-...-9eca039 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 License: MIT Imports: 13 Imported by: 0

README

registry redis for Kitex

Redis as service discovery for Kitex.

How to use?

Server
import (
    // ...
    registry "github.com/ydmxcz/kitex-registry-redis"
    "github.com/cloudwego/kitex/pkg/rpcinfo"
	
    // ...
)

func main() {
    // ... 
    r, err := registry.NewRedisRegistry("127.0.0.1:6379")
    if err != nil {
        panic(err)
    }
    svr := echo.NewServer(
        new(EchoImpl), 
        server.WithServerBasicInfo(&rpcinfo.EndpointBasicInfo{ServiceName: "echo"}),
        server.WithRegistry(r), 
	)
    if err := svr.Run(); err != nil {
        log.Println("server stopped with error:", err)
    } else {
        log.Println("server stopped")
    }
    // ...
}
Client
import (
    // ...
    resolver "github.com/ydmxcz/kitex-registry-redis"
    // ...
)

func main() {
    // ... 
    r, err := resolver.NewRedisResolver()
	if err != nil {
	    panic(err)	
    }
    client, err := echo.NewClient("echo", client.WithResolver(r))
    if err != nil {
        log.Fatal(err)
    }
    // ...
}

Documentation

Index

Constants

View Source
const (
	Redis = "redis"
)

Variables

This section is empty.

Functions

func NewRedisRegistry

func NewRedisRegistry(addr string, opts ...Option) registry.Registry

NewRedisRegistry creates a redis registry

func NewRedisResolver

func NewRedisResolver(addr string, opts ...Option) discovery.Resolver

NewRedisResolver creates a redis resolver

Types

type Option

type Option func(opts *redis.Options)

func WithDB

func WithDB(db int) Option

func WithDialer

func WithDialer(dialer func(ctx context.Context, network, addr string) (net.Conn, error)) Option

func WithPassword

func WithPassword(password string) Option

func WithReadTimeout

func WithReadTimeout(t time.Duration) Option

func WithTLSConfig

func WithTLSConfig(t *tls.Config) Option

func WithWriteTimeout

func WithWriteTimeout(t time.Duration) Option

Jump to

Keyboard shortcuts

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