redis

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2022 License: MIT Imports: 7 Imported by: 1

Documentation

Overview

Package redis use gofame-gredis implement common-usage redis functions.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Redis Client wrappers

Example (Publish)
package main

import (
	"sync"

	"github.com/lovelacelee/clsgo/v1/redis"
)

var workGroup sync.WaitGroup

const messageCount = 1000

func main() {
	c := redis.New("default")
	defer c.Close()
	for i := 0; i < messageCount; i++ {
		c.Do("PUBLISH", "channel", "test")
	}
	workGroup.Done()
}
Output:

func New

func New(name string) *Client

Name valid in default/cache, initialized with config.yaml, See order for more https://www.redis.net.cn/order/

Example
package main

import (
	"github.com/lovelacelee/clsgo/v1/redis"
)

func main() {
	c := redis.New("default")
	defer c.Close()
}
Output:

func (*Client) Close

func (client *Client) Close()

func (*Client) Do

func (client *Client) Do(command string, args ...any) (*g.Var, error)
Example
package main

import (
	"fmt"

	"github.com/lovelacelee/clsgo/pkg/version"
	"github.com/lovelacelee/clsgo/v1/redis"
)

func main() {
	c := redis.New("default")
	defer c.Close()

	c.Do("SET", "clsgo", version.Version)
	rv, _ := c.Do("GET", "clsgo")
	fmt.Println(rv.String())
}
Output:

func (*Client) Receive

func (client *Client) Receive() (*g.Var, error)

func (*Client) Subscribe

func (client *Client) Subscribe(channel string) chan *g.Var

Redis subscribe, return a go chan for receive message notification

Example
package main

import (
	"fmt"
	"sync"

	"github.com/lovelacelee/clsgo/v1/redis"
)

var workGroup sync.WaitGroup

const messageCount = 1000

func main() {
	c := redis.New("default")
	defer c.Close()
	notify := c.Subscribe("channel")
	var payload string
	for i := 0; i < messageCount; i++ {
		resp := <-notify
		channelRes := struct {
			Channel      string
			Pattern      string
			Payload      string
			PayloadSlice string
		}{}
		resp.Struct(&channelRes)
		payload = channelRes.Payload
	}
	fmt.Printf("Receive %v %v times\n", payload, messageCount)
	workGroup.Done()
	// Output
	// v0.0.9
	// Receive test 1000 times
}
Output:

Jump to

Keyboard shortcuts

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