redis

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ClusterType means redis cluster.
	ClusterType = "cluster"
	// NodeType means redis node.
	NodeType = "node"
	// Nil is an alias of redis.Nil.
	Nil = red.Nil
)

Variables

View Source
var (
	// ErrEmptyHost is an error that indicates no redis host is set.
	ErrEmptyHost = errors.New("empty redis host")
	// ErrEmptyType is an error that indicates no redis type is set.
	ErrEmptyType = errors.New("empty redis type")
	// ErrEmptyKey is an error that indicates no redis key is set.
	ErrEmptyKey = errors.New("empty redis key")
)
View Source
var ErrNilNode = errors.New("nil redis node")

ErrNilNode is an error that indicates a nil redis node.

Functions

This section is empty.

Types

type ClosableNode

type ClosableNode interface {
	RedisNode
	Close()
}

ClosableNode interface represents a closable redis node.

func CreateBlockingNode

func CreateBlockingNode(r *Redis) (ClosableNode, error)

CreateBlockingNode returns a ClosableNode.

type FloatCmd

type FloatCmd = red.FloatCmd

FloatCmd is an alias of redis.FloatCmd.

type GeoLocation

type GeoLocation = red.GeoLocation

GeoLocation is used with GeoAdd to add geospatial location.

type GeoPos

type GeoPos = red.GeoPos

GeoPos is used to represent a geo position.

type GeoRadiusQuery

type GeoRadiusQuery = red.GeoRadiusQuery

GeoRadiusQuery is used with GeoRadius to query geospatial index.

type IntCmd

type IntCmd = red.IntCmd

IntCmd is an alias of redis.IntCmd.

type Map

type Map map[string]string

Map is an alias of map[string]string.

type Option

type Option func(r *Redis)

Option defines the method to customize a Redis.

func Cluster

func Cluster() Option

Cluster customizes the given Redis as a cluster.

func WithPass

func WithPass(pass string) Option

WithPass customizes the given Redis with given password.

func WithTLS

func WithTLS() Option

WithTLS customizes the given Redis with TLS enabled.

type Pair

type Pair struct {
	Key   string
	Score int64
}

A Pair is a key/pair set used in redis zset.

type Pipeliner

type Pipeliner = red.Pipeliner

Pipeliner is an alias of redis.Pipeliner.

type Redis

type Redis struct {
	Addr string
	Type string
	Pass string
	// contains filtered or unexported fields
}

Redis defines a redis node/cluster. It is thread-safe.

func New

func New(addr string, opts ...Option) *Redis

New returns a Redis with given options.

func NewRedis

func NewRedis(redisAddr, redisType string, redisPass ...string) *Redis

NewRedis returns a Redis.

func (*Redis) BitCount

func (s *Redis) BitCount(key string, start, end int64) (val int64, err error)

BitCount is redis bitcount command implementation.

func (*Redis) BitOpAnd

func (s *Redis) BitOpAnd(destKey string, keys ...string) (val int64, err error)

BitOpAnd is redis bit operation (and) command implementation.

func (*Redis) BitOpNot

func (s *Redis) BitOpNot(destKey, key string) (val int64, err error)

BitOpNot is redis bit operation (not) command implementation.

func (*Redis) BitOpOr

func (s *Redis) BitOpOr(destKey string, keys ...string) (val int64, err error)

BitOpOr is redis bit operation (or) command implementation.

func (*Redis) BitOpXor

func (s *Redis) BitOpXor(destKey string, keys ...string) (val int64, err error)

BitOpXor is redis bit operation (xor) command implementation.

func (*Redis) BitPos

func (s *Redis) BitPos(key string, bit int64, start, end int64) (val int64, err error)

BitPos is redis bitpos command implementation.

func (*Redis) Blpop

func (s *Redis) Blpop(redisNode RedisNode, key string) (string, error)

Blpop uses passed in redis connection to execute blocking queries. Doesn't benefit from pooling redis connections of blocking queries

func (*Redis) BlpopEx

func (s *Redis) BlpopEx(redisNode RedisNode, key string) (string, bool, error)

BlpopEx uses passed in redis connection to execute blpop command. The difference against Blpop is that this method returns a bool to indicate success.

func (*Redis) Del

func (s *Redis) Del(keys ...string) (val int, err error)

Del deletes keys.

func (*Redis) Eval

func (s *Redis) Eval(script string, keys []string, args ...interface{}) (val interface{}, err error)

Eval is the implementation of redis eval command.

func (*Redis) EvalSha

func (s *Redis) EvalSha(sha string, keys []string, args ...interface{}) (val interface{}, err error)

EvalSha is the implementation of redis evalsha command.

func (*Redis) Exists

func (s *Redis) Exists(key string) (val bool, err error)

Exists is the implementation of redis exists command.

func (*Redis) Expire

func (s *Redis) Expire(key string, seconds int) error

Expire is the implementation of redis expire command.

func (*Redis) Expireat

func (s *Redis) Expireat(key string, expireTime int64) error

Expireat is the implementation of redis expireat command.

func (*Redis) GeoAdd

func (s *Redis) GeoAdd(key string, geoLocation ...*GeoLocation) (val int64, err error)

GeoAdd is the implementation of redis geoadd command.

func (*Redis) GeoDist

func (s *Redis) GeoDist(key string, member1, member2, unit string) (val float64, err error)

GeoDist is the implementation of redis geodist command.

func (*Redis) GeoHash

func (s *Redis) GeoHash(key string, members ...string) (val []string, err error)

GeoHash is the implementation of redis geohash command.

func (*Redis) GeoPos

func (s *Redis) GeoPos(key string, members ...string) (val []*GeoPos, err error)

GeoPos is the implementation of redis geopos command.

func (*Redis) GeoRadius

func (s *Redis) GeoRadius(key string, longitude, latitude float64, query *GeoRadiusQuery) (val []GeoLocation, err error)

GeoRadius is the implementation of redis georadius command.

func (*Redis) GeoRadiusByMember

func (s *Redis) GeoRadiusByMember(key, member string, query *GeoRadiusQuery) (val []GeoLocation, err error)

GeoRadiusByMember is the implementation of redis georadiusbymember command.

func (*Redis) Get

func (s *Redis) Get(key string) (val string, err error)

Get is the implementation of redis get command.

func (*Redis) GetBit

func (s *Redis) GetBit(key string, offset int64) (val int, err error)

GetBit is the implementation of redis getbit command.

func (*Redis) Hdel

func (s *Redis) Hdel(key string, fields ...string) (val bool, err error)

Hdel is the implementation of redis hdel command.

func (*Redis) Hexists

func (s *Redis) Hexists(key, field string) (val bool, err error)

Hexists is the implementation of redis hexists command.

func (*Redis) Hget

func (s *Redis) Hget(key, field string) (val string, err error)

Hget is the implementation of redis hget command.

func (*Redis) Hgetall

func (s *Redis) Hgetall(key string) (val map[string]string, err error)

Hgetall is the implementation of redis hgetall command.

func (*Redis) Hincrby

func (s *Redis) Hincrby(key, field string, increment int) (val int, err error)

Hincrby is the implementation of redis hincrby command.

func (*Redis) Hkeys

func (s *Redis) Hkeys(key string) (val []string, err error)

Hkeys is the implementation of redis hkeys command.

func (*Redis) Hlen

func (s *Redis) Hlen(key string) (val int, err error)

Hlen is the implementation of redis hlen command.

func (*Redis) Hmget

func (s *Redis) Hmget(key string, fields ...string) (val []string, err error)

Hmget is the implementation of redis hmget command.

func (*Redis) Hmset

func (s *Redis) Hmset(key string, fieldsAndValues map[string]string) error

Hmset is the implementation of redis hmset command.

func (*Redis) Hscan

func (s *Redis) Hscan(key string, cursor uint64, match string, count int64) (keys []string, cur uint64, err error)

Hscan is the implementation of redis hscan command.

func (*Redis) Hset

func (s *Redis) Hset(key, field, value string) error

Hset is the implementation of redis hset command.

func (*Redis) Hsetnx

func (s *Redis) Hsetnx(key, field, value string) (val bool, err error)

Hsetnx is the implementation of redis hsetnx command.

func (*Redis) Hvals

func (s *Redis) Hvals(key string) (val []string, err error)

Hvals is the implementation of redis hvals command.

func (*Redis) Incr

func (s *Redis) Incr(key string) (val int64, err error)

Incr is the implementation of redis incr command.

func (*Redis) Incrby

func (s *Redis) Incrby(key string, increment int64) (val int64, err error)

Incrby is the implementation of redis incrby command.

func (*Redis) Keys

func (s *Redis) Keys(pattern string) (val []string, err error)

Keys is the implementation of redis keys command.

func (*Redis) Llen

func (s *Redis) Llen(key string) (val int, err error)

Llen is the implementation of redis llen command.

func (*Redis) Lpop

func (s *Redis) Lpop(key string) (val string, err error)

Lpop is the implementation of redis lpop command.

func (*Redis) Lpush

func (s *Redis) Lpush(key string, values ...interface{}) (val int, err error)

Lpush is the implementation of redis lpush command.

func (*Redis) Lrange

func (s *Redis) Lrange(key string, start int, stop int) (val []string, err error)

Lrange is the implementation of redis lrange command.

func (*Redis) Lrem

func (s *Redis) Lrem(key string, count int, value string) (val int, err error)

Lrem is the implementation of redis lrem command.

func (*Redis) Mget

func (s *Redis) Mget(keys ...string) (val []string, err error)

Mget is the implementation of redis mget command.

func (*Redis) Persist

func (s *Redis) Persist(key string) (val bool, err error)

Persist is the implementation of redis persist command.

func (*Redis) Pfadd

func (s *Redis) Pfadd(key string, values ...interface{}) (val bool, err error)

Pfadd is the implementation of redis pfadd command.

func (*Redis) Pfcount

func (s *Redis) Pfcount(key string) (val int64, err error)

Pfcount is the implementation of redis pfcount command.

func (*Redis) Pfmerge

func (s *Redis) Pfmerge(dest string, keys ...string) error

Pfmerge is the implementation of redis pfmerge command.

func (*Redis) Ping

func (s *Redis) Ping() (val bool)

Ping is the implementation of redis ping command.

func (*Redis) Pipelined

func (s *Redis) Pipelined(fn func(Pipeliner) error) (err error)

Pipelined lets fn to execute pipelined commands.

func (*Redis) Rpop

func (s *Redis) Rpop(key string) (val string, err error)

Rpop is the implementation of redis rpop command.

func (*Redis) Rpush

func (s *Redis) Rpush(key string, values ...interface{}) (val int, err error)

Rpush is the implementation of redis rpush command.

func (*Redis) Sadd

func (s *Redis) Sadd(key string, values ...interface{}) (val int, err error)

Sadd is the implementation of redis sadd command.

func (*Redis) Scan

func (s *Redis) Scan(cursor uint64, match string, count int64) (keys []string, cur uint64, err error)

Scan is the implementation of redis scan command.

func (*Redis) Scard

func (s *Redis) Scard(key string) (val int64, err error)

Scard is the implementation of redis scard command.

func (*Redis) ScriptLoad

func (s *Redis) ScriptLoad(script string) (string, error)

ScriptLoad is the implementation of redis script load command.

func (*Redis) Sdiff

func (s *Redis) Sdiff(keys ...string) (val []string, err error)

Sdiff is the implementation of redis sdiff command.

func (*Redis) Sdiffstore

func (s *Redis) Sdiffstore(destination string, keys ...string) (val int, err error)

Sdiffstore is the implementation of redis sdiffstore command.

func (*Redis) Set

func (s *Redis) Set(key string, value string) error

Set is the implementation of redis set command.

func (*Redis) SetBit

func (s *Redis) SetBit(key string, offset int64, value int) error

SetBit is the implementation of redis setbit command.

func (*Redis) Setex

func (s *Redis) Setex(key, value string, seconds int) error

Setex is the implementation of redis setex command.

func (*Redis) Setnx

func (s *Redis) Setnx(key, value string) (val bool, err error)

Setnx is the implementation of redis setnx command.

func (*Redis) SetnxEx

func (s *Redis) SetnxEx(key, value string, seconds int) (val bool, err error)

SetnxEx is the implementation of redis setnx command with expire.

func (*Redis) Sismember

func (s *Redis) Sismember(key string, value interface{}) (val bool, err error)

Sismember is the implementation of redis sismember command.

func (*Redis) Smembers

func (s *Redis) Smembers(key string) (val []string, err error)

Smembers is the implementation of redis smembers command.

func (*Redis) Spop

func (s *Redis) Spop(key string) (val string, err error)

Spop is the implementation of redis spop command.

func (*Redis) Srandmember

func (s *Redis) Srandmember(key string, count int) (val []string, err error)

Srandmember is the implementation of redis srandmember command.

func (*Redis) Srem

func (s *Redis) Srem(key string, values ...interface{}) (val int, err error)

Srem is the implementation of redis srem command.

func (*Redis) Sscan

func (s *Redis) Sscan(key string, cursor uint64, match string, count int64) (keys []string, cur uint64, err error)

Sscan is the implementation of redis sscan command.

func (*Redis) String

func (s *Redis) String() string

String returns the string representation of s.

func (*Redis) Sunion

func (s *Redis) Sunion(keys ...string) (val []string, err error)

Sunion is the implementation of redis sunion command.

func (*Redis) Sunionstore

func (s *Redis) Sunionstore(destination string, keys ...string) (val int, err error)

Sunionstore is the implementation of redis sunionstore command.

func (*Redis) Ttl

func (s *Redis) Ttl(key string) (val int, err error)

Ttl is the implementation of redis ttl command.

func (*Redis) ZRevRangeWithScores

func (s *Redis) ZRevRangeWithScores(key string, start, stop int64) (val []Pair, err error)

ZRevRangeWithScores is the implementation of redis zrevrange command with scores.

func (*Redis) Zadd

func (s *Redis) Zadd(key string, score int64, value string) (val bool, err error)

Zadd is the implementation of redis zadd command.

func (*Redis) Zadds

func (s *Redis) Zadds(key string, ps ...Pair) (val int64, err error)

Zadds is the implementation of redis zadds command.

func (*Redis) Zcard

func (s *Redis) Zcard(key string) (val int, err error)

Zcard is the implementation of redis zcard command.

func (*Redis) Zcount

func (s *Redis) Zcount(key string, start, stop int64) (val int, err error)

Zcount is the implementation of redis zcount command.

func (*Redis) Zincrby

func (s *Redis) Zincrby(key string, increment int64, field string) (val int64, err error)

Zincrby is the implementation of redis zincrby command.

func (*Redis) Zrange

func (s *Redis) Zrange(key string, start, stop int64) (val []string, err error)

Zrange is the implementation of redis zrange command.

func (*Redis) ZrangeWithScores

func (s *Redis) ZrangeWithScores(key string, start, stop int64) (val []Pair, err error)

ZrangeWithScores is the implementation of redis zrange command with scores.

func (*Redis) ZrangebyscoreWithScores

func (s *Redis) ZrangebyscoreWithScores(key string, start, stop int64) (val []Pair, err error)

ZrangebyscoreWithScores is the implementation of redis zrangebyscore command with scores.

func (*Redis) ZrangebyscoreWithScoresAndLimit

func (s *Redis) ZrangebyscoreWithScoresAndLimit(key string, start, stop int64, page, size int) (
	val []Pair, err error)

ZrangebyscoreWithScoresAndLimit is the implementation of redis zrangebyscore command with scores and limit.

func (*Redis) Zrank

func (s *Redis) Zrank(key, field string) (val int64, err error)

Zrank is the implementation of redis zrank command.

func (*Redis) Zrem

func (s *Redis) Zrem(key string, values ...interface{}) (val int, err error)

Zrem is the implementation of redis zrem command.

func (*Redis) Zremrangebyrank

func (s *Redis) Zremrangebyrank(key string, start, stop int64) (val int, err error)

Zremrangebyrank is the implementation of redis zremrangebyrank command.

func (*Redis) Zremrangebyscore

func (s *Redis) Zremrangebyscore(key string, start, stop int64) (val int, err error)

Zremrangebyscore is the implementation of redis zremrangebyscore command.

func (*Redis) Zrevrange

func (s *Redis) Zrevrange(key string, start, stop int64) (val []string, err error)

Zrevrange is the implementation of redis zrevrange command.

func (*Redis) ZrevrangebyscoreWithScores

func (s *Redis) ZrevrangebyscoreWithScores(key string, start, stop int64) (val []Pair, err error)

ZrevrangebyscoreWithScores is the implementation of redis zrevrangebyscore command with scores.

func (*Redis) ZrevrangebyscoreWithScoresAndLimit

func (s *Redis) ZrevrangebyscoreWithScoresAndLimit(key string, start, stop int64, page, size int) (
	val []Pair, err error)

ZrevrangebyscoreWithScoresAndLimit is the implementation of redis zrevrangebyscore command with scores and limit.

func (*Redis) Zrevrank

func (s *Redis) Zrevrank(key string, field string) (val int64, err error)

Zrevrank is the implementation of redis zrevrank command.

func (*Redis) Zscore

func (s *Redis) Zscore(key string, value string) (val int64, err error)

Zscore is the implementation of redis zscore command.

func (*Redis) Zunionstore

func (s *Redis) Zunionstore(dest string, store ZStore, keys ...string) (val int64, err error)

Zunionstore is the implementation of redis zunionstore command.

type RedisConf

type RedisConf struct {
	Host string
	Type string `json:",default=node,options=node|cluster"`
	Pass string `json:",optional"`
	Tls  bool   `json:",default=false,options=true|false"`
}

A RedisConf is a redis config.

func (RedisConf) NewRedis

func (rc RedisConf) NewRedis() *Redis

NewRedis returns a Redis.

func (RedisConf) Validate

func (rc RedisConf) Validate() error

Validate validates the RedisConf.

type RedisKeyConf

type RedisKeyConf struct {
	RedisConf
	Key string `json:",optional"`
}

A RedisKeyConf is a redis config with key.

func (RedisKeyConf) Validate

func (rkc RedisKeyConf) Validate() error

Validate validates the RedisKeyConf.

type RedisLock

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

A RedisLock is a redis lock.

func NewRedisLock

func NewRedisLock(store *Redis, key string) *RedisLock

NewRedisLock returns a RedisLock.

func (*RedisLock) Acquire

func (rl *RedisLock) Acquire() (bool, error)

Acquire acquires the lock.

func (*RedisLock) Release

func (rl *RedisLock) Release() (bool, error)

Release releases the lock.

func (*RedisLock) SetExpire

func (rl *RedisLock) SetExpire(seconds int)

SetExpire sets the expire.

type RedisNode

type RedisNode interface {
	red.Cmdable
}

RedisNode interface represents a redis node.

type ScriptCache

type ScriptCache struct {
	atomic.Value
}

A ScriptCache is a cache that stores a script with its sha key.

func GetScriptCache

func GetScriptCache() *ScriptCache

GetScriptCache returns a ScriptCache.

func (*ScriptCache) GetSha

func (sc *ScriptCache) GetSha(script string) (string, bool)

GetSha returns the sha string of given script.

func (*ScriptCache) SetSha

func (sc *ScriptCache) SetSha(script, sha string)

SetSha sets script with sha into the ScriptCache.

type Z

type Z = red.Z

Z represents sorted set member.

type ZStore

type ZStore = red.ZStore

ZStore is an alias of redis.ZStore.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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