rd

package module
v0.0.0-...-ef063fc Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

README

RD

Redis (Cluster) Driver

Build Status GoDoc Go Report Card

Simple Usage

package main

import (
    "github.com/beiping96/rd"
)

func main() {
    cfg := rd.Config{
        IsCluster: true,
        Address: "127.0.0.1:6379",
    }
    cli, err := rd.NewClient(cfg)
    if err != nil {
        // handle err
    }

    defer cli.Close()

    _, err := cli.DoString("GET", "not_exist_key")
    if err == cli.ErrNil() {
        // key not exist
    } else if err != nil {
        // handle err
    }
}

With Instance

Instance Example

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// if is redis-cluster
	IsCluster bool

	// required redis addr
	Address string
	// if has password
	Password string

	// default is 10 seconds
	DialTimeout time.Duration
	// default is 10 seconds
	ReadTimeout time.Duration
	// default is 10 seconds
	WriteTimeout time.Duration

	// default is 20
	OpenConns int
	// default is keep alive
	Lifetime time.Duration

	// Prefix will wrap redis-key at head
	// default is nil
	Prefix func(key string) (keyWithPrefix string)

	// DB select redis database
	// default is nil
	// useless in cluster
	DB int
}

Config desc redis client method

type RD

type RD interface {
	// ErrNil declare NIL-error
	ErrNil() error

	// Do execute redis command
	Do(cmd string, args ...interface{}) (interface{}, error)

	DoBool(cmd string, args ...interface{}) (bool, error)
	DoBytes(cmd string, args ...interface{}) ([]byte, error)
	DoFloat64(cmd string, args ...interface{}) (float64, error)
	DoInt(cmd string, args ...interface{}) (int, error)
	DoInt64(cmd string, args ...interface{}) (int64, error)
	DoInts(cmd string, args ...interface{}) ([]int, error)
	DoString(cmd string, args ...interface{}) (string, error)
	DoStringMap(cmd string, args ...interface{}) (map[string]string, error)
	DoStrings(cmd string, args ...interface{}) ([]string, error)

	Values(cmd string, args ...interface{}) ([]interface{}, error)
	Scan(src []interface{}, dst ...interface{}) ([]interface{}, error)

	Close()
}

RD declare redis client method

func New

func New(cfg Config) (cli RD, err error)

New redis client with config

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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