redis

package
v0.0.0-...-da57006 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2019 License: Apache-2.0 Imports: 3 Imported by: 0

README

usthooz

Base On github.com/go-redis/redis v6.6.0

Usage

package redis

import (
	"testing"
	"time"
)

func TestClient(t *testing.T) {
	single := SingleConfig{
		Addr: "127.0.0.1:6379",
	}
	client, err := NewClient(&Config{
		DeployType: "single",
		ForSingle:  single,
	})
	if err != nil {
		t.Errorf("new client err->%v", err)
	}
	m := NewModule("ooz-test")
	s, err := client.Set(m.GetKey("ooz_key"), "ooz_value", time.Second).Result()
	if err != nil {
		t.Fatalf("c.Set().Result() err-> %v", err)
	}
	t.Logf("c.Set().Result() result-> %s", s)

	s, err = client.Get(m.GetKey("ooz_key")).Result()
	if err != nil {
		t.Fatalf("c.Get().Result() error-> %v", err)
	}
	t.Logf("c.Get().Result() result-> %s", s)
}

Documentation

Overview

Based on `github.com/go-redis/redis`v6.6.0

Index

Constants

View Source
const (
	DeploySingle  string = "single"
	DeployCluster string = "cluster"
)

redis deploy type

View Source
const Nil = redis.Nil

Redis nil reply, .e.g. when key does not exist.

Variables

This section is empty.

Functions

func IsRedisNil

func IsRedisNil(err error) bool

IsRedisNil Is the redis nil reply? .e.g. when key does not exist.

Types

type BoolCmd

type BoolCmd = redis.BoolCmd

Client redis client and cluster client merge.

type BoolSliceCmd

type BoolSliceCmd = redis.BoolSliceCmd

Client redis client and cluster client merge.

type Client

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

Client redis client and cluster client merge.

func NewClient

func NewClient(cfg *Config) (*Client, error)

NewClient new redis client and cluster redis.

func (*Client) GetConfig

func (c *Client) GetConfig() *Config

GetConfig returns config.

func (*Client) LockCallback

func (c *Client) LockCallback(lockKey string, callback func(), maxLock ...time.Duration) error

注意:每10毫秒尝试1次上锁,且上锁后默认锁定1分钟

type ClusterConfig

type ClusterConfig struct {
	// A seed list of host:port addresses of cluster nodes.
	Addrs []string `yaml:"addrs"`
	// The maximum number of retries before giving up. Command is retried
	// on network errors and MOVED/ASK redirects.
	// Default is 16.
	MaxRedirects int `yaml:"max_redirects,omitempty"`
	// Enables routing read-only queries to the closest master or slave node.
	RouteByLatency bool `yaml:"route_by_latency,omitempty"`
}

ClusterConfig redis cluster client config.

type ClusterSlotsCmd

type ClusterSlotsCmd = redis.ClusterSlotsCmd

Client redis client and cluster client merge.

type Cmdable

type Cmdable interface {
	redis.Cmdable
	TxPipeline() redis.Pipeliner
	TxPipelined(fn func(redis.Pipeliner) error) ([]redis.Cmder, error)
	Publish(channel, message string) *redis.IntCmd
	Subscribe(channels ...string) *redis.PubSub
}

Client redis client and cluster client merge.

type Cmder

type Cmder = redis.Cmder

Client redis client and cluster client merge.

type Config

type Config struct {
	// redis deploy type, [single, cluster]
	DeployType string `yaml:"deploy_type"`
	// only for single node config, valid when DeployType=single.
	ForSingle SingleConfig `yaml:"for_single"`
	// only for cluster config, valid when DeployType=cluster.
	ForCluster ClusterConfig `yaml:"for_cluster"`
	// An optional password. Must match the password specified in the
	// requirepass server configuration option.
	Password string `yaml:"password,omitempty"`
	// The maximum number of retries before giving up.
	// Default is to not retry failed commands.
	MaxRetries int `yaml:"max_retries,omitempty"`
	// Dial timeout for establishing new connections.
	// Default is 5 seconds.
	DialTimeout int64 `yaml:"dial_timeout,omitempty"`
	// Timeout for socket reads. If reached, commands will fail
	// with a timeout instead of blocking.
	// Default is 3 seconds.
	ReadTimeout int64 `yaml:"read_timeout,omitempty"`
	// Timeout for socket writes. If reached, commands will fail
	// with a timeout instead of blocking.
	// Default is ReadTimeout.
	WriteTimeout int64 `yaml:"write_timeout,omitempty"`
	// PoolSizePerNode applies per cluster node and not for the whole cluster.
	// Maximum number of socket connections.
	// Default is 10 connections per every CPU as reported by runtime.NumCPU.
	PoolSizePerNode int `yaml:"pool_size_per_node"`
	// Amount of time client waits for connection if all connections
	// are busy before returning an error.
	// Default is ReadTimeout + 1 second.
	PoolTimeout int64 `yaml:"pool_timeout,omitempty"`
	// Amount of time after which client closes idle connections.
	// Should be less than server's timeout.
	// Default is 300 seconds.
	IdleTimeout int64 `yaml:"idle_timeout"`
	// Frequency of idle checks.
	// Default is 60 seconds.
	// When minus value is set, then idle check is disabled.
	IdleCheckFrequency int64 `yaml:"idle_check_frequency,omitempty"`
	// Enables read only queries on slave nodes.
	// Only for cluster.
	ReadOnly bool `yaml:"read_only,omitempty"`
}

Config redis and cluster client config

type DurationCmd

type DurationCmd = redis.DurationCmd

Client redis client and cluster client merge.

type FloatCmd

type FloatCmd = redis.FloatCmd

Client redis client and cluster client merge.

type GeoLocation

type GeoLocation = redis.GeoLocation

Client redis client and cluster client merge.

type GeoRadiusQuery

type GeoRadiusQuery = redis.GeoRadiusQuery

Client redis client and cluster client merge.

type IntCmd

type IntCmd = redis.IntCmd

Client redis client and cluster client merge.

type Message

type Message = redis.Message

Client redis client and cluster client merge.

type Module

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

Module

func NewModule

func NewModule(module string) *Module

NewModule create module.

func (*Module) GetKey

func (m *Module) GetKey(shortKey string) string

GetKey

func (*Module) GetModuleString

func (m *Module) GetModuleString() string

GetModuleString

func (*Module) GetPrefix

func (m *Module) GetPrefix() string

GetPrefix

func (*Module) SetModuleString

func (m *Module) SetModuleString(module string) *Module

SetModuleString

type Pipeliner

type Pipeliner = redis.Pipeliner

Client redis client and cluster client merge.

type PubSub

type PubSub = redis.PubSub

Alias-> usth ooz.redis's method copy to go-redis.redis

type RedisCmdable

type RedisCmdable = redis.Cmdable

Client redis client and cluster client merge.

type ScanCmd

type ScanCmd = redis.ScanCmd

Client redis client and cluster client merge.

type SingleConfig

type SingleConfig struct {
	// host:port and address.
	Addr string `yaml:"addr"`
	// Maximum backoff between each retry.
	// Default is 512 seconds; -1 disables backoff.
	MaxRetryBackoff int64 `yaml:"max_retry_backoff,omitempty"`
}

SingleConfig redis single node client config.

type SliceCmd

type SliceCmd = redis.SliceCmd

Client redis client and cluster client merge.

type StatusCmd

type StatusCmd = redis.StatusCmd

Client redis client and cluster client merge.

type StringCmd

type StringCmd = redis.StringCmd

Client redis client and cluster client merge.

type StringIntMapCmd

type StringIntMapCmd = redis.StringIntMapCmd

Client redis client and cluster client merge.

type StringSliceCmd

type StringSliceCmd = redis.StringSliceCmd

Client redis client and cluster client merge.

type StringStringMapCmd

type StringStringMapCmd = redis.StringStringMapCmd

Client redis client and cluster client merge.

type Z

type Z = redis.Z

Client redis client and cluster client merge.

type ZRangeBy

type ZRangeBy = redis.ZRangeBy

Client redis client and cluster client merge.

type ZSliceCmd

type ZSliceCmd = redis.ZSliceCmd

Client redis client and cluster client merge.

Jump to

Keyboard shortcuts

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