redis

package
v0.1.9 Latest Latest
Warning

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

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

README

Mysql

package main

import (
    "context"

    "github.com/joshqu1985/fireman/configor"
    "github.com/joshqu1985/fireman/store/redis"
)

type Config struct {
    Redis    redis.Config
}

var (
    Conf Config
)

func init() {
    if err := configor.Load("./configs/conf.toml", &Conf); err != nil {
        panic(err)
    }
}

type Record struct {
    Uid        string `json:"uid"`
    DeviceId   string `json:"device_id"`
    ClientType string `json:"client_type"` // app / web
    LoginTime  int64  `json:"login_time"`
}

func main() {
    pool := redis.NewPool(Conf.Redis)

    item := Record{}
    data, err := pool.GetBytes(context.Background(), "key")
    if err != nil {
        return item, err
    }

    fmt.Prinln(item, json.Unmarshal(data, &item))

    // redis版分布式锁
    ticket, _ := pool.TryLock(context.Background(), "lock-key", 500)
    defer pool.UnLock(context.Background(), "lock-key", ticket)
}
#conf.toml
[redis]
    host     = "127.0.0.1:6379"
    auth     = ""
    index    = 14
    max_idle = 10

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRecordNotFound = errors.New("redigo: nil returned")
View Source
var UnlockScript = redis.NewScript(1, `
	if redis.call("get", KEYS[1]) == ARGV[1]
	then
		return redis.call("del", KEYS[1])
	else
		return 0
	end
`)

Functions

This section is empty.

Types

type Config

type Config struct {
	Host    string
	Auth    string
	Index   int
	MaxIdle int `toml:"max_idle"`
}

type Pool

type Pool struct {
	Connections *redis.Pool
}

func NewPool

func NewPool(conf Config) *Pool

func (*Pool) DecrBy

func (p *Pool) DecrBy(c context.Context, key string, val int64) (ret int64, err error)

func (*Pool) Delete

func (p *Pool) Delete(c context.Context, key string) (err error)

func (*Pool) Doit

func (p *Pool) Doit(c context.Context, cmd string, handle func(redis.Conn) error) error

func (*Pool) Exist

func (p *Pool) Exist(c context.Context, key string) (ret int, err error)

Exist ...

func (*Pool) Expire

func (p *Pool) Expire(c context.Context, key string, ttl int) (ret int, err error)

func (*Pool) Get

func (p *Pool) Get(c context.Context, key string) (res interface{}, err error)

func (*Pool) GetBytes

func (p *Pool) GetBytes(c context.Context, key string) ([]byte, error)

func (*Pool) GetInt

func (p *Pool) GetInt(c context.Context, key string) (int, error)

GetInt ...

func (*Pool) GetInt64

func (p *Pool) GetInt64(c context.Context, key string) (int64, error)

func (*Pool) GetString

func (p *Pool) GetString(c context.Context, key string) (string, error)

func (*Pool) HDel

func (p *Pool) HDel(c context.Context, hkey, key string) (err error)

func (*Pool) HExists

func (p *Pool) HExists(c context.Context, hkey, key string) (ret int, err error)

func (*Pool) HGet

func (p *Pool) HGet(c context.Context, hkey string, key string) (res interface{}, err error)

func (*Pool) HGetAll

func (p *Pool) HGetAll(c context.Context, hkey string) (res interface{}, err error)

HGetAll 效率原因, 不建议使用

func (*Pool) HGetByteSlices

func (p *Pool) HGetByteSlices(c context.Context, hkey, key string) ([][]byte, error)

func (*Pool) HGetBytes

func (p *Pool) HGetBytes(c context.Context, hkey, key string) ([]byte, error)

func (*Pool) HGetInt64

func (p *Pool) HGetInt64(c context.Context, hkey string, key string) (int64, error)

HGetInt64 ...

func (*Pool) HGetString

func (p *Pool) HGetString(c context.Context, hkey string, key string) (string, error)

func (*Pool) HGetStrings

func (p *Pool) HGetStrings(c context.Context, hkey, key string) ([]string, error)

func (*Pool) HIncrBy

func (p *Pool) HIncrBy(c context.Context, hkey string, key string, val int64) (ret int64, err error)

func (*Pool) HMGet

func (p *Pool) HMGet(c context.Context, hkey string, keys []string) (res interface{}, err error)

func (*Pool) HMGetBytes

func (p *Pool) HMGetBytes(c context.Context, hkey string, keys []string) ([][]byte, error)

func (*Pool) HMGetStrings

func (p *Pool) HMGetStrings(c context.Context, hkey string, keys []string) ([]string, error)

func (*Pool) HMSet

func (p *Pool) HMSet(c context.Context, hkey string, vals []interface{}) (err error)

HMSet vals: [key1, val1, key2, val2, ...]

func (*Pool) HSet

func (p *Pool) HSet(c context.Context, hkey string, key string, val interface{}) (err error)

func (*Pool) IncrBy

func (p *Pool) IncrBy(c context.Context, key string, val int64) (ret int64, err error)

func (*Pool) KeyTTL

func (p *Pool) KeyTTL(c context.Context, key string) (ret int, err error)

func (*Pool) LPop

func (p *Pool) LPop(c context.Context, lkey string) (val interface{}, err error)

func (*Pool) LPopString

func (p *Pool) LPopString(c context.Context, lkey string) (val string, err error)

LPopString ...

func (*Pool) MGet

func (p *Pool) MGet(c context.Context, keys []string) (res interface{}, err error)

func (*Pool) MGetBytes

func (p *Pool) MGetBytes(c context.Context, keys []string) ([][]byte, error)

func (*Pool) MSet

func (p *Pool) MSet(c context.Context, args []interface{}) (err error)

MSet args: [key1, val1, key2, val2, ...]

func (*Pool) RPush

func (p *Pool) RPush(c context.Context, lkey string, val interface{}) (err error)

func (*Pool) SAdd

func (p *Pool) SAdd(c context.Context, skey, member string) (err error)

SAdd ...

func (*Pool) SIsMember

func (p *Pool) SIsMember(c context.Context, skey, member string) (ret int, err error)

func (*Pool) SRem

func (p *Pool) SRem(c context.Context, skey, member string) (err error)

func (*Pool) Set

func (p *Pool) Set(c context.Context, key string, val interface{}, ttl int64) (err error)

func (*Pool) TryLock

func (p *Pool) TryLock(c context.Context, s string, ttl int64) (string, error)

ttl ms

func (*Pool) UnLock

func (p *Pool) UnLock(c context.Context, s, ticket string) error

func (*Pool) ZAdd

func (p *Pool) ZAdd(c context.Context, zkey string, score int64, member string) (err error)

ZAdd ...

func (*Pool) ZCard

func (p *Pool) ZCard(c context.Context, zkey string) (val int64, err error)

func (*Pool) ZMAdd

func (p *Pool) ZMAdd(c context.Context, zkey string, vals []interface{}) (err error)

ZMAdd vals: [score1, member1, score2, member2, ...]

func (*Pool) ZRangeByScore

func (p *Pool) ZRangeByScore(c context.Context, zkey string, beg, end int64, limit int) (items []string, err error)

func (*Pool) ZRem

func (p *Pool) ZRem(c context.Context, zkey, member string) (err error)

func (*Pool) ZRemByScore

func (p *Pool) ZRemByScore(c context.Context, zkey string, min, max int64) (err error)

func (*Pool) ZRemRangeByScore

func (p *Pool) ZRemRangeByScore(c context.Context, zkey string, beg, end int64) error

func (*Pool) ZRevRangeByScore

func (p *Pool) ZRevRangeByScore(c context.Context, zkey string, beg, end int64, limit int) (items []string, err error)

func (*Pool) ZScore

func (p *Pool) ZScore(c context.Context, zkey string, member string) (score int64, err error)

Jump to

Keyboard shortcuts

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