package
1.4.2
Repository: https://github.com/zdao-pro/sky_blue.git
Documentation: pkg.go.dev

# README

cache-redis模块

找到cache-redis

摘自bilibili karos框架,对其简单修改

使用方式

cache-redis 是一个redis客户端,包括了基本DML,性能监控,可以使用peach配置SDK加载配置文件。

example

1. 普通使用

import (
	"context"
	"time"

	"github.com/zdao-pro/sky_blue/pkg/cache/redis"
	"github.com/zdao-pro/sky_blue/pkg/common/pool"
)

func main() {
	config := &redis.Config{
		Config: &pool.Config{
			Active: 10, // 连接池活跃数
			Idle:   5, // 连接池空闲数
		},
		Name:         "test_get",
		Proto:        "tcp",
		Addr:         "localhost:6379",
		DialTimeout:  time.Second, // 连接超时
		ReadTimeout:  time.Second,
		WriteTimeout: time.Second,
	}
	db := 1 // 指定数据库
	r := redis.NewRedis(config) // 内部维护一个redis连接池
	defer r.Close()
	r.Do(context.Background(), db, "SET", "a", "b")
}

1. 配置文件使用方式

import (
	"context"
	"time"

	"github.com/zdao-pro/sky_blue/pkg/cache/redis"
	"github.com/zdao-pro/sky_blue/pkg/common/pool"
	"github.com/zdao-pro/sky_blue/pkg/peach"
	_ "github.com/zdao-pro/sky_blue/pkg/peach/apollo"
)

func main() {
	peach.Init(peach.PeachDriverApollo, "zdao_backend.sky_blue")
	var c redis.NewConfig
	peach.Get("redis_test.yaml").UnmarshalYAML(&c)
	fmt.Println(c)
	r := redis.NewRedisClient(&c)
	db := 2 // 指定数据库
	defer r.Close()
	r.Do(context.Background(), db, "SET", "a", "f")
}

# Packages

No description provided by the author

# Functions

Bool is a helper that converts a command reply to a boolean.
Bytes is a helper that converts a command reply to a slice of bytes.
ByteSlices is a helper that converts an array command reply to a [][]byte.
Dial connects to the Redis server at the given network and address using the specified options.
DialConnectTimeout specifies the timeout for connecting to the Redis server.
DialDatabase specifies the database to select when dialing a connection.
DialNetDial specifies a custom dial function for creating TCP connections.
DialPassword specifies the password to use when connecting to the Redis server.
DialReadTimeout specifies the timeout for reading a single command reply.
DialTimeout acts like Dial but takes timeouts for establishing the connection to the server, writing a command and reading a reply.
DialURL connects to a Redis server at the given URL using the Redis URI scheme.
DialWriteTimeout specifies the timeout for writing a single command.
Float64 is a helper that converts a command reply to 64 bit float.
Int is a helper that converts a command reply to an integer.
Int64 is a helper that converts a command reply to 64 bit integer.
Int64Map is a helper that converts an array of strings (alternating key, value) into a map[string]int64.
Int64s is a helper that converts an array command reply to a []int64.
IntMap is a helper that converts an array of strings (alternating key, value) into a map[string]int.
Ints is a helper that converts an array command reply to a []int.
LookupCommandInfo get command info.
MockWith return a mock conn.
MultiBulk is a helper that converts an array command reply to a []interface{}.
NewConn new a redis conn.
NewLoggingConn returns a logging wrapper around a connection.
NewPool creates a new pool.
NewRedis ..
NewRedisClient ..
NewScript returns a new script object.
Scan copies from src to the values pointed at by dest.
ScanSlice scans src to the slice pointed to by dest.
ScanStruct scans alternating names and values from src to a struct.
String is a helper that converts a command reply to a string.
StringMap is a helper that converts an array of strings (alternating key, value) into a map[string]string.
Strings is a helper that converts an array command reply to a []string.
Uint64 is a helper that converts a command reply to 64 bit integer.
Values is a helper that converts an array command reply to a []interface{}.

# Constants

redis state.
redis state.
redis state.
redis state.

# Variables

ErrNil indicates that a reply value is nil.
ErrNoReply ..

# Structs

CommandInfo command info.
Config client settings.
DialOption specifies an option for dialing a Redis server.
Message represents a message notification.
MockErr for unit test.
NewConfig ..
PMessage represents a pmessage notification.
Pong represents a pubsub pong notification.
Pool .
PubSubConn wraps a Conn with convenience methods for subscribers.
Redis ..
Replies ..
Script encapsulates the source, hash and key count for a Lua script.
Subscription represents a subscribe or unsubscribe notification.

# Interfaces

Conn represents a connection to a Redis server.
Pipeliner ..

# Type aliases

Args is a helper for constructing command arguments from structured values.
Error represents an error returned in a command reply.