redis

package
v0.0.0-...-93b1e75 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package redis provides convenient API to redis storage. It uses redigo library undercover.

Typical simplified usage:

client := redis.MustNewClient(redis.WithAddress("127.0.0.1:6379"))
conn := client.Conn()
defer conn.Close()
value, err := conn.Get("key").String()
if err != nil {
    ...
}

Index

Constants

View Source
const (
	// DefAddress is the default redis server address.
	DefAddress = "127.0.0.1:6379"
	// DefMaxIdle is the default maximum number of idle redis connections in the pool.
	DefMaxIdle = 3
	// DefIdleTimeout is the default timeout in seconds after which idle connections will be dropped away.
	DefIdleTimeout = 600
)

Variables

View Source
var ErrNoValues = errors.New("no values")

ErrNoValues error is returned by Scan and ScanStruct reply methods when there are no values returned by redis server, i.e. reply was empty.

Functions

This section is empty.

Types

type Client

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

Client structure provides redis client functionality. Don't create manually, use the functions down below instead.

func MustNewClient

func MustNewClient(opts ...Option) *Client

MustNewClient function creates new redis client with provided options and panics on any error.

func NewClient

func NewClient(opts ...Option) (*Client, error)

NewClient function creates new redis client with provided options.

func (*Client) Address

func (client *Client) Address() string

Address method retrieves redis server address.

func (*Client) Close

func (client *Client) Close() error

Close method releases all resources used by client. Don't use client object after that.

func (*Client) Conn

func (client *Client) Conn() *Conn

Conn method retrieves idle connection from the pool (if there are none, it will be created).

func (*Client) IdleTimeout

func (client *Client) IdleTimeout() time.Duration

IdleTimeout method retrieves timeout in seconds after which idle connections will be dropped away.

func (*Client) MaxIdle

func (client *Client) MaxIdle() int

MaxIdle method retrieves maximum number of idle redis connections in the pool.

func (*Client) TransConn

func (client *Client) TransConn() *TransConn

TransConn method retrieves idle connection from the pool (if there are none, it will be created). This connection will be specially wrapped to automatically work in transaction mode.

type Config

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

Config structure with client's configuration. Shouldn't be created manually.

type ConfigService

type ConfigService interface {
	GetByKey(string, interface{}) error
	IsNoSuchKeyError(error) bool
}

ConfigService interface used to obtain configuration from somewhere into some specific structure.

type Conn

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

Conn structure represents connection to redis server retrieved from the pool.

func (*Conn) Append

func (conn *Conn) Append(key string, value interface{}) Reply

Append method sends APPEND command to the redis server and waits for the reply.

func (*Conn) BLPop

func (conn *Conn) BLPop(args ...interface{}) Reply

BLPop method sends BLPOP command to the redis server and waits for the reply.

func (*Conn) BRPop

func (conn *Conn) BRPop(args ...interface{}) Reply

BRPop method sends BRPOP command to the redis server and waits for the reply.

func (*Conn) BRPopLPush

func (conn *Conn) BRPopLPush(source string, destination string, timeout int64) Reply

BRPopLPush method sends BRPOPLPUSH command to the redis server and waits for the reply.

func (*Conn) BitCount

func (conn *Conn) BitCount(args ...interface{}) Reply

BitCount method sends BITCOUNT command to the redis server and waits for the reply.

func (*Conn) BitOp

func (conn *Conn) BitOp(args ...interface{}) Reply

BitOp method sends BITOP command to the redis server and waits for the reply.

func (*Conn) Close

func (conn *Conn) Close() error

Close method returns connection to the pool. Don't use connection object after that.

func (*Conn) Decr

func (conn *Conn) Decr(key string) Reply

Decr method sends DECR command to the redis server and waits for the reply.

func (*Conn) DecrBy

func (conn *Conn) DecrBy(key string, decrement int64) Reply

DecrBy method sends DECRBY command to the redis server and waits for the reply.

func (*Conn) Del

func (conn *Conn) Del(args ...interface{}) Reply

Del method sends DEL command to the redis server and waits for the reply.

func (*Conn) Do

func (conn *Conn) Do(commandName string, args ...interface{}) Reply

Do method sends specified command with arguments to the redis server and waits for the reply.

func (*Conn) Dump

func (conn *Conn) Dump(key string) Reply

Dump method sends DUMP command to the redis server and waits for the reply.

func (*Conn) Eval

func (conn *Conn) Eval(args ...interface{}) Reply

Eval method sends EVAL command to the redis server and waits for the reply.

func (*Conn) EvalSha

func (conn *Conn) EvalSha(args ...interface{}) Reply

EvalSha method sends EVALSHA command to the redis server and waits for the reply.

func (*Conn) Exists

func (conn *Conn) Exists(key string) Reply

Exists method sends EXISTS command to the redis server and waits for the reply.

func (*Conn) Expire

func (conn *Conn) Expire(key string, seconds int64) Reply

Expire method sends EXPIRE command to the redis server and waits for the reply.

func (*Conn) ExpireAt

func (conn *Conn) ExpireAt(key string, timestamp int64) Reply

ExpireAt method sends EXPIREAT command to the redis server and waits for the reply.

func (*Conn) Get

func (conn *Conn) Get(key string) Reply

Get method sends GET command to the redis server and waits for the reply.

func (*Conn) GetBit

func (conn *Conn) GetBit(key string, offset int64) Reply

GetBit method sends GETBIT command to the redis server and waits for the reply.

func (*Conn) GetRange

func (conn *Conn) GetRange(key string, start int64, end int64) Reply

GetRange method sends GETRANGE command to the redis server and waits for the reply.

func (*Conn) GetSet

func (conn *Conn) GetSet(key string, value interface{}) Reply

GetSet method sends GETSET command to the redis server and waits for the reply.

func (*Conn) HDel

func (conn *Conn) HDel(args ...interface{}) Reply

HDel method sends HDEL command to the redis server and waits for the reply.

func (*Conn) HExists

func (conn *Conn) HExists(key string, field string) Reply

HExists method sends HEXISTS command to the redis server and waits for the reply.

func (*Conn) HGet

func (conn *Conn) HGet(key string, field string) Reply

HGet method sends HGET command to the redis server and waits for the reply.

func (*Conn) HGetAll

func (conn *Conn) HGetAll(key string) Reply

HGetAll method sends HGETALL command to the redis server and waits for the reply.

func (*Conn) HIncrBy

func (conn *Conn) HIncrBy(key string, field string, increment int64) Reply

HIncrBy method sends HINCRBY command to the redis server and waits for the reply.

func (*Conn) HIncrByFloat

func (conn *Conn) HIncrByFloat(key string, field string, increment float64) Reply

HIncrByFloat method sends HINCRBYFLOAT command to the redis server and waits for the reply.

func (*Conn) HKeys

func (conn *Conn) HKeys(key string) Reply

HKeys method sends HKEYS command to the redis server and waits for the reply.

func (*Conn) HLen

func (conn *Conn) HLen(key string) Reply

HLen method sends HLEN command to the redis server and waits for the reply.

func (*Conn) HMGet

func (conn *Conn) HMGet(args ...interface{}) Reply

HMGet method sends HMGET command to the redis server and waits for the reply.

func (*Conn) HMSet

func (conn *Conn) HMSet(key string, values map[string]interface{}) Reply

HMSet method unfolds provided map, sends HMSET command to the redis server and waits for the reply.

func (*Conn) HMSetFlat

func (conn *Conn) HMSetFlat(args ...interface{}) Reply

HMSetFlat method sends HMSET command to the redis server and waits for the reply.

func (*Conn) HSet

func (conn *Conn) HSet(key string, field string, value interface{}) Reply

HSet method sends HSET command to the redis server and waits for the reply.

func (*Conn) HSetNx

func (conn *Conn) HSetNx(key string, field string, value interface{}) Reply

HSetNx method sends HSETNX command to the redis server and waits for the reply.

func (*Conn) HVals

func (conn *Conn) HVals(key string) Reply

HVals method sends HVALS command to the redis server and waits for the reply.

func (*Conn) Incr

func (conn *Conn) Incr(key string) Reply

Incr method sends INCR command to the redis server and waits for the reply.

func (*Conn) IncrBy

func (conn *Conn) IncrBy(key string, increment int64) Reply

IncrBy method sends INCRBY command to the redis server and waits for the reply.

func (*Conn) IncrByFloat

func (conn *Conn) IncrByFloat(key string, increment float64) Reply

IncrByFloat method sends INCRBYFLOAT command to the redis server and waits for the reply.

func (*Conn) Keys

func (conn *Conn) Keys(pattern string) Reply

Keys method sends KEYS command to the redis server and waits for the reply.

func (*Conn) LIndex

func (conn *Conn) LIndex(key string, index int64) Reply

LIndex method sends LINDEX command to the redis server and waits for the reply.

func (*Conn) LInsertAfter

func (conn *Conn) LInsertAfter(key string, pivot interface{}, value interface{}) Reply

LInsertAfter method sends LINSERT command with AFTER modifier to the redis server and waits for the reply.

func (*Conn) LInsertBefore

func (conn *Conn) LInsertBefore(key string, pivot interface{}, value interface{}) Reply

LInsertBefore method sends LINSERT command with BEFORE modifier to the redis server and waits for the reply.

func (*Conn) LLen

func (conn *Conn) LLen(key string) Reply

LLen method sends LLEN command to the redis server and waits for the reply.

func (*Conn) LPop

func (conn *Conn) LPop(key string) Reply

LPop method sends LPOP command to the redis server and waits for the reply.

func (*Conn) LPush

func (conn *Conn) LPush(args ...interface{}) Reply

LPush method sends LPUSH command to the redis server and waits for the reply.

func (*Conn) LPushX

func (conn *Conn) LPushX(args ...interface{}) Reply

LPushX method sends LPUSHX command to the redis server and waits for the reply.

func (*Conn) LRange

func (conn *Conn) LRange(key string, start int64, stop int64) Reply

LRange method sends LRANGE command to the redis server and waits for the reply.

func (*Conn) LRem

func (conn *Conn) LRem(key string, count int64, value interface{}) Reply

LRem method sends LREM command to the redis server and waits for the reply.

func (*Conn) LSet

func (conn *Conn) LSet(key string, index int64, value interface{}) Reply

LSet method sends LSET command to the redis server and waits for the reply.

func (*Conn) LTrim

func (conn *Conn) LTrim(key string, start int64, stop int64) Reply

LTrim method sends LTRIM command to the redis server and waits for the reply.

func (*Conn) MGet

func (conn *Conn) MGet(args ...interface{}) Reply

MGet method sends MGET command to the redis server and waits for the reply.

func (*Conn) MSet

func (conn *Conn) MSet(values map[string]interface{}) Reply

MSet method unfolds provided map, sends MSET command to the redis server and waits for the reply.

func (*Conn) MSetFlat

func (conn *Conn) MSetFlat(args ...interface{}) Reply

MSetFlat method sends MSET command to the redis server and waits for the reply.

func (*Conn) MSetNx

func (conn *Conn) MSetNx(values map[string]interface{}) Reply

MSetNx method unfolds provided map, sends MSETNX command to the redis server and waits for the reply.

func (*Conn) MSetNxFlat

func (conn *Conn) MSetNxFlat(args ...interface{}) Reply

MSetNxFlat method sends MSETNX command to the redis server and waits for the reply.

func (*Conn) Move

func (conn *Conn) Move(key string, db int64) Reply

Move method sends MOVE command to the redis server and waits for the reply.

func (*Conn) MultiCall

func (conn *Conn) MultiCall(f MultiCallFunc) Reply

MultiCall method wraps calling of provided function for bulk processing. It will return unified reply of all commands that were sent in this function.

func (*Conn) Object

func (conn *Conn) Object(args ...interface{}) Reply

Object method sends OBJECT command to the redis server and waits for the reply.

func (*Conn) PExpire

func (conn *Conn) PExpire(key string, milliseconds int64) Reply

PExpire method sends PEXPIRE command to the redis server and waits for the reply.

func (*Conn) PExpireAt

func (conn *Conn) PExpireAt(key string, mtimestamp int64) Reply

PExpireAt method sends PEXPIREAT command to the redis server and waits for the reply.

func (*Conn) PSetEx

func (conn *Conn) PSetEx(key string, milliseconds int64, value interface{}) Reply

PSetEx method sends PSETEX command to the redis server and waits for the reply.

func (*Conn) PTTL

func (conn *Conn) PTTL(key string) Reply

PTTL method sends PTTL command to the redis server and waits for the reply.

func (*Conn) Persist

func (conn *Conn) Persist(key string) Reply

Persist method sends PERSIST command to the redis server and waits for the reply.

func (*Conn) RPop

func (conn *Conn) RPop(key string) Reply

RPop method sends RPOP command to the redis server and waits for the reply.

func (*Conn) RPopLPush

func (conn *Conn) RPopLPush(source string, destination string) Reply

RPopLPush method sends RPOPLPUSH command to the redis server and waits for the reply.

func (*Conn) RPush

func (conn *Conn) RPush(args ...interface{}) Reply

RPush method sends RPUSH command to the redis server and waits for the reply.

func (*Conn) RPushX

func (conn *Conn) RPushX(args ...interface{}) Reply

RPushX method sends RPUSHX command to the redis server and waits for the reply.

func (*Conn) RandomKey

func (conn *Conn) RandomKey() Reply

RandomKey method sends RANDOMKEY command to the redis server and waits for the reply.

func (*Conn) Rename

func (conn *Conn) Rename(key string, newkey string) Reply

Rename method sends RENAME command to the redis server and waits for the reply.

func (*Conn) RenameNx

func (conn *Conn) RenameNx(key string, newkey string) Reply

RenameNx method sends RENAMENX command to the redis server and waits for the reply.

func (*Conn) Restore

func (conn *Conn) Restore(key string, ttl int64, value interface{}) Reply

Restore method sends RESTORE command to the redis server and waits for the reply.

func (*Conn) SAdd

func (conn *Conn) SAdd(args ...interface{}) Reply

SAdd method sends SADD command to the redis server and waits for the reply.

func (*Conn) SCard

func (conn *Conn) SCard(key string) Reply

SCard method sends SCARD command to the redis server and waits for the reply.

func (*Conn) SDiff

func (conn *Conn) SDiff(args ...interface{}) Reply

SDiff method sends SDIFF command to the redis server and waits for the reply.

func (*Conn) SDiffStore

func (conn *Conn) SDiffStore(args ...interface{}) Reply

SDiffStore method sends SDIFFSTORE command to the redis server and waits for the reply.

func (*Conn) SInter

func (conn *Conn) SInter(args ...interface{}) Reply

SInter method sends SINTER command to the redis server and waits for the reply.

func (*Conn) SInterStore

func (conn *Conn) SInterStore(args ...interface{}) Reply

SInterStore method sends SINTERSTORE command to the redis server and waits for the reply.

func (*Conn) SIsMember

func (conn *Conn) SIsMember(key string, member interface{}) Reply

SIsMember method sends SISMEMBER command to the redis server and waits for the reply.

func (*Conn) SMembers

func (conn *Conn) SMembers(key string) Reply

SMembers method sends SMEMBERS command to the redis server and waits for the reply.

func (*Conn) SMove

func (conn *Conn) SMove(source string, destination string, member interface{}) Reply

SMove method sends SMOVE command to the redis server and waits for the reply.

func (*Conn) SPop

func (conn *Conn) SPop(key string) Reply

SPop method sends SPOP command to the redis server and waits for the reply.

func (*Conn) SRandMember

func (conn *Conn) SRandMember(key string) Reply

SRandMember method sends SRANDMEMBER command to the redis server and waits for the reply.

func (*Conn) SRandMemberCount

func (conn *Conn) SRandMemberCount(key string, count int64) Reply

SRandMemberCount method sends SRANDMEMBER command with count param to the redis server and waits for the reply.

func (*Conn) SRem

func (conn *Conn) SRem(args ...interface{}) Reply

SRem method sends SREM command to the redis server and waits for the reply.

func (*Conn) SUnion

func (conn *Conn) SUnion(args ...interface{}) Reply

SUnion method sends SUNION command to the redis server and waits for the reply.

func (*Conn) SUnionStore

func (conn *Conn) SUnionStore(args ...interface{}) Reply

SUnionStore method sends SUNIONSTORE command to the redis server and waits for the reply.

func (*Conn) ScriptExists

func (conn *Conn) ScriptExists(args ...interface{}) Reply

ScriptExists method sends SCRIPT EXISTS command to the redis server and waits for the reply.

func (*Conn) ScriptFlush

func (conn *Conn) ScriptFlush() Reply

ScriptFlush method sends SCRIPT FLUSH command to the redis server and waits for the reply.

func (*Conn) ScriptKill

func (conn *Conn) ScriptKill() Reply

ScriptKill method sends SCRIPT KILL command to the redis server and waits for the reply.

func (*Conn) ScriptLoad

func (conn *Conn) ScriptLoad(script string) Reply

ScriptLoad method sends SCRIPT LOAD command to the redis server and waits for the reply.

func (*Conn) Set

func (conn *Conn) Set(key string, value interface{}) Reply

Set method sends SET command to the redis server and waits for the reply.

func (*Conn) SetAdvanced

func (conn *Conn) SetAdvanced(args ...interface{}) Reply

SetAdvanced method sends SET command with any provided advanced args to the redis server and waits for the reply.

func (*Conn) SetBit

func (conn *Conn) SetBit(key string, offset int64, value interface{}) Reply

SetBit method sends SETBIT command to the redis server and waits for the reply.

func (*Conn) SetEx

func (conn *Conn) SetEx(key string, seconds int64, value interface{}) Reply

SetEx method sends SETEX command to the redis server and waits for the reply.

func (*Conn) SetNx

func (conn *Conn) SetNx(key string, value interface{}) Reply

SetNx method sends SETNX command to the redis server and waits for the reply.

func (*Conn) SetRange

func (conn *Conn) SetRange(key string, offset int64, value interface{}) Reply

SetRange method sends SETRANGE command to the redis server and waits for the reply.

func (*Conn) Sort

func (conn *Conn) Sort(args ...interface{}) Reply

Sort method sends SORT command to the redis server and waits for the reply.

func (*Conn) StrLen

func (conn *Conn) StrLen(key string) Reply

StrLen method sends STRLEN command to the redis server and waits for the reply.

func (*Conn) TTL

func (conn *Conn) TTL(key string) Reply

TTL method sends TTL command to the redis server and waits for the reply.

func (*Conn) Transaction

func (conn *Conn) Transaction(f MultiCallFunc) Reply

Transaction method wraps calling of provided function for transaction processing, i.e. it will send MULTI command before and EXEC command after. Then it will return unified reply of all commands that were sent.

func (*Conn) Type

func (conn *Conn) Type(key string) Reply

Type method sends TYPE command to the redis server and waits for the reply.

func (*Conn) ZAdd

func (conn *Conn) ZAdd(args ...interface{}) Reply

ZAdd method sends ZADD command to the redis server and waits for the reply.

func (*Conn) ZCard

func (conn *Conn) ZCard(key string) Reply

ZCard method sends ZCARD command to the redis server and waits for the reply.

func (*Conn) ZCount

func (conn *Conn) ZCount(key string, min interface{}, max interface{}) Reply

ZCount method sends ZCOUNT command to the redis server and waits for the reply.

func (*Conn) ZIncrBy

func (conn *Conn) ZIncrBy(key string, increment int64, member interface{}) Reply

ZIncrBy method sends ZINCRBY command to the redis server and waits for the reply.

func (*Conn) ZIncrByFloat

func (conn *Conn) ZIncrByFloat(key string, increment float64, member interface{}) Reply

ZIncrByFloat method sends ZINCRBY command with float increment to the redis server and waits for the reply.

func (*Conn) ZInterStore

func (conn *Conn) ZInterStore(args ...interface{}) Reply

ZInterStore method sends ZINTERSTORE command to the redis server and waits for the reply.

func (*Conn) ZRange

func (conn *Conn) ZRange(key string, start int64, stop int64) Reply

ZRange method sends ZRANGE command to the redis server and waits for the reply.

func (*Conn) ZRangeByScore

func (conn *Conn) ZRangeByScore(key string, min interface{}, max interface{}) Reply

ZRangeByScore method sends ZRANGEBYSCORE command to the redis server and waits for the reply.

func (*Conn) ZRangeByScoreWithLimit

func (conn *Conn) ZRangeByScoreWithLimit(
	key string, min interface{}, max interface{}, offset int64, count int64,
) Reply

ZRangeByScoreWithLimit method sends ZRANGEBYSCORE command with LIMIT modifier to the redis server and waits for the reply.

func (*Conn) ZRangeByScoreWithScores

func (conn *Conn) ZRangeByScoreWithScores(key string, min interface{}, max interface{}) Reply

ZRangeByScoreWithScores method sends ZRANGEBYSCORE command with WITHSCORES modifier to the redis server and waits for the reply.

func (*Conn) ZRangeByScoreWithScoresWithLimit

func (conn *Conn) ZRangeByScoreWithScoresWithLimit(key string, min interface{}, max interface{}, offset int64,
	count int64,
) Reply

ZRangeByScoreWithScoresWithLimit method sends ZRANGEBYSCORE command with WITHSCORES and LIMIT modifiers to the redis server and waits for the reply.

func (*Conn) ZRangeWithScores

func (conn *Conn) ZRangeWithScores(key string, start int64, stop int64) Reply

ZRangeWithScores method sends ZRANGE command with WITHSCORES modifier to the redis server and waits for the reply.

func (*Conn) ZRank

func (conn *Conn) ZRank(key string, member interface{}) Reply

ZRank method sends ZRANK command to the redis server and waits for the reply.

func (*Conn) ZRem

func (conn *Conn) ZRem(args ...interface{}) Reply

ZRem method sends ZREM command to the redis server and waits for the reply.

func (*Conn) ZRemRangeByRank

func (conn *Conn) ZRemRangeByRank(key string, start int64, stop int64) Reply

ZRemRangeByRank method sends ZREMRANGEBYRANK command to the redis server and waits for the reply.

func (*Conn) ZRemRangeByScore

func (conn *Conn) ZRemRangeByScore(key string, min interface{}, max interface{}) Reply

ZRemRangeByScore method sends ZREMRANGEBYSCORE command to the redis server and waits for the reply.

func (*Conn) ZRevRange

func (conn *Conn) ZRevRange(key string, start int64, stop int64) Reply

ZRevRange method sends ZREVRANGE command to the redis server and waits for the reply.

func (*Conn) ZRevRangeByScore

func (conn *Conn) ZRevRangeByScore(key string, max interface{}, min interface{}) Reply

ZRevRangeByScore method sends ZREVRANGEBYSCORE command to the redis server and waits for the reply.

func (*Conn) ZRevRangeByScoreWithLimit

func (conn *Conn) ZRevRangeByScoreWithLimit(
	key string, max interface{}, min interface{}, offset int64, count int64,
) Reply

ZRevRangeByScoreWithLimit method sends ZREVRANGEBYSCORE command with LIMIT modifier to the redis server and waits for the reply.

func (*Conn) ZRevRangeByScoreWithScores

func (conn *Conn) ZRevRangeByScoreWithScores(key string, max interface{}, min interface{}) Reply

ZRevRangeByScoreWithScores method sends ZREVRANGEBYSCORE command with WITHSCORES modifier to the redis server and waits for the reply.

func (*Conn) ZRevRangeByScoreWithScoresWithLimit

func (conn *Conn) ZRevRangeByScoreWithScoresWithLimit(
	key string, max interface{}, min interface{}, offset int64, count int64,
) Reply

ZRevRangeByScoreWithScoresWithLimit method sends ZREVRANGEBYSCORE command with WITHSCORES and LIMIT modifiers to the redis server and waits for the reply.

func (*Conn) ZRevRangeWithScores

func (conn *Conn) ZRevRangeWithScores(key string, start int64, stop int64) Reply

ZRevRangeWithScores method sends ZREVRANGE command with WITHSCORES modifier to the redis server and waits for the reply.

func (*Conn) ZRevRank

func (conn *Conn) ZRevRank(key string, member interface{}) Reply

ZRevRank method sends ZREVRANK command to the redis server and waits for the reply.

func (*Conn) ZScore

func (conn *Conn) ZScore(key string, member interface{}) Reply

ZScore method sends ZSCORE command to the redis server and waits for the reply.

func (*Conn) ZUnionStore

func (conn *Conn) ZUnionStore(args ...interface{}) Reply

ZUnionStore method sends ZUNIONSTORE command to the redis server and waits for the reply.

type MultiCall

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

MultiCall structure is a bulk or transaction processing context. Do not create it manually. Use it inside MultiCallFunc to send commands that are part of that bulk or transaction processing.

func (MultiCall) Append

func (multiCall MultiCall) Append(key string, value interface{}) error

Append method sends APPEND command to the redis server.

func (MultiCall) BitOp

func (multiCall MultiCall) BitOp(args ...interface{}) error

BitOp method sends BITOP command to the redis server.

func (MultiCall) Decr

func (multiCall MultiCall) Decr(key string) error

Decr method sends DECR command to the redis server.

func (MultiCall) DecrBy

func (multiCall MultiCall) DecrBy(key string, decrement int64) error

DecrBy method sends DECRBY command to the redis server.

func (MultiCall) Del

func (multiCall MultiCall) Del(args ...interface{}) error

Del method sends DEL command to the redis server.

func (MultiCall) Eval

func (multiCall MultiCall) Eval(args ...interface{}) error

Eval method sends EVAL command to the redis server.

func (MultiCall) EvalSha

func (multiCall MultiCall) EvalSha(args ...interface{}) error

EvalSha method sends EVALSHA command to the redis server.

func (MultiCall) Expire

func (multiCall MultiCall) Expire(key string, seconds int64) error

Expire method sends EXPIRE command to the redis server.

func (MultiCall) ExpireAt

func (multiCall MultiCall) ExpireAt(key string, timestamp int64) error

ExpireAt method sends EXPIREAT command to the redis server.

func (MultiCall) HDel

func (multiCall MultiCall) HDel(args ...interface{}) error

HDel method sends HDEL command to the redis server.

func (MultiCall) HIncrBy

func (multiCall MultiCall) HIncrBy(key string, field string, increment int64) error

HIncrBy method sends HINCRBY command to the redis server.

func (MultiCall) HIncrByFloat

func (multiCall MultiCall) HIncrByFloat(key string, field string, increment float64) error

HIncrByFloat method sends HINCRBYFLOAT command to the redis server.

func (MultiCall) HMSet

func (multiCall MultiCall) HMSet(key string, values map[string]interface{}) error

HMSet method unfolds provided map and sends HMSET command to the redis server.

func (MultiCall) HMSetFlat

func (multiCall MultiCall) HMSetFlat(args ...interface{}) error

HMSetFlat method sends HMSET command to the redis server.

func (MultiCall) HSet

func (multiCall MultiCall) HSet(key string, field string, value interface{}) error

HSet method sends HSET command to the redis server.

func (MultiCall) HSetNx

func (multiCall MultiCall) HSetNx(key string, field string, value interface{}) error

HSetNx method sends HSETNX command to the redis server.

func (MultiCall) Incr

func (multiCall MultiCall) Incr(key string) error

Incr method sends INCR command to the redis server.

func (MultiCall) IncrBy

func (multiCall MultiCall) IncrBy(key string, increment int64) error

IncrBy method sends INCRBY command to the redis server.

func (MultiCall) IncrByFloat

func (multiCall MultiCall) IncrByFloat(key string, increment float64) error

IncrByFloat method sends INCRBYFLOAT command to the redis server.

func (MultiCall) LInsertAfter

func (multiCall MultiCall) LInsertAfter(key string, pivot interface{}, value interface{}) error

LInsertAfter method sends LINSERT command with AFTER modifier to the redis server.

func (MultiCall) LInsertBefore

func (multiCall MultiCall) LInsertBefore(key string, pivot interface{}, value interface{}) error

LInsertBefore method sends LINSERT command with BEFORE modifier to the redis server.

func (MultiCall) LPush

func (multiCall MultiCall) LPush(args ...interface{}) error

LPush method sends LPUSH command to the redis server.

func (MultiCall) LPushX

func (multiCall MultiCall) LPushX(key string, value interface{}) error

LPushX method sends LPUSHX command to the redis server.

func (MultiCall) LRem

func (multiCall MultiCall) LRem(key string, count int64, value interface{}) error

LRem method sends LREM command to the redis server.

func (MultiCall) LSet

func (multiCall MultiCall) LSet(key string, index int64, value interface{}) error

LSet method sends LSET command to the redis server.

func (MultiCall) LTrim

func (multiCall MultiCall) LTrim(key string, start int64, stop int64) error

LTrim method sends LTRIM command to the redis server.

func (MultiCall) MSet

func (multiCall MultiCall) MSet(values map[string]interface{}) error

MSet method unfolds provided map and sends MSET command to the redis server.

func (MultiCall) MSetFlat

func (multiCall MultiCall) MSetFlat(args ...interface{}) error

MSetFlat method sends MSET command to the redis server.

func (MultiCall) MSetNx

func (multiCall MultiCall) MSetNx(values map[string]interface{}) error

MSetNx method unfolds provided map and sends MSETNX command to the redis server.

func (MultiCall) MSetNxFlat

func (multiCall MultiCall) MSetNxFlat(args ...interface{}) error

MSetNxFlat method sends MSETNX command to the redis server.

func (MultiCall) Move

func (multiCall MultiCall) Move(key string, db int64) error

Move method sends MOVE command to the redis server.

func (MultiCall) PExpire

func (multiCall MultiCall) PExpire(key string, milliseconds int64) error

PExpire method sends PEXPIRE command to the redis server.

func (MultiCall) PExpireAt

func (multiCall MultiCall) PExpireAt(key string, mtimestamp int64) error

PExpireAt method sends PEXPIREAT command to the redis server.

func (MultiCall) PSetEx

func (multiCall MultiCall) PSetEx(key string, milliseconds int64, value interface{}) error

PSetEx method sends PSETEX command to the redis server.

func (MultiCall) Persist

func (multiCall MultiCall) Persist(key string) error

Persist method sends PERSIST command to the redis server.

func (MultiCall) RPopLPush

func (multiCall MultiCall) RPopLPush(source string, destination string) error

RPopLPush method sends RPOPLPUSH command to the redis server.

func (MultiCall) RPush

func (multiCall MultiCall) RPush(args ...interface{}) error

RPush method sends RPUSH command to the redis server.

func (MultiCall) RPushX

func (multiCall MultiCall) RPushX(key string, value interface{}) error

RPushX method sends RPUSHX command to the redis server.

func (MultiCall) Rename

func (multiCall MultiCall) Rename(key string, newkey string) error

Rename method sends RENAME command to the redis server.

func (MultiCall) RenameNx

func (multiCall MultiCall) RenameNx(key string, newkey string) error

RenameNx method sends RENAMENX command to the redis server.

func (MultiCall) Restore

func (multiCall MultiCall) Restore(key string, ttl int64, value interface{}) error

Restore method sends RESTORE command to the redis server.

func (MultiCall) SAdd

func (multiCall MultiCall) SAdd(args ...interface{}) error

SAdd method sends SADD command to the redis server.

func (MultiCall) SDiffStore

func (multiCall MultiCall) SDiffStore(args ...interface{}) error

SDiffStore method sends SDIFFSTORE command to the redis server.

func (MultiCall) SInterStore

func (multiCall MultiCall) SInterStore(args ...interface{}) error

SInterStore method sends SINTERSTORE command to the redis server.

func (MultiCall) SMove

func (multiCall MultiCall) SMove(source string, destination string, member interface{}) error

SMove method sends SMOVE command to the redis server.

func (MultiCall) SRem

func (multiCall MultiCall) SRem(args ...interface{}) error

SRem method sends SREM command to the redis server.

func (MultiCall) SUnionStore

func (multiCall MultiCall) SUnionStore(args ...interface{}) error

SUnionStore method sends SUNIONSTORE command to the redis server.

func (MultiCall) ScriptFlush

func (multiCall MultiCall) ScriptFlush() error

ScriptFlush method sends SCRIPT FLUSH command to the redis server.

func (MultiCall) ScriptKill

func (multiCall MultiCall) ScriptKill() error

ScriptKill method sends SCRIPT KILL command to the redis server.

func (MultiCall) Send

func (multiCall MultiCall) Send(commandName string, args ...interface{}) error

Send method sends provided command and arguments to redis server as part of bulk or transaction processing. Generally you will not call this method directly, but use helper command methods instead.

func (MultiCall) Set

func (multiCall MultiCall) Set(key string, value interface{}) error

Set method sends SET command to the redis server.

func (MultiCall) SetAdvanced

func (multiCall MultiCall) SetAdvanced(args ...interface{}) error

SetAdvanced method sends SET command with any provided advanced args to the redis server.

func (MultiCall) SetBit

func (multiCall MultiCall) SetBit(key string, offset int64, value interface{}) error

SetBit method sends SETBIT command to the redis server.

func (MultiCall) SetEx

func (multiCall MultiCall) SetEx(key string, seconds int64, value interface{}) error

SetEx method sends SETEX command to the redis server.

func (MultiCall) SetNx

func (multiCall MultiCall) SetNx(key string, value interface{}) error

SetNx method sends SETNX command to the redis server.

func (MultiCall) SetRange

func (multiCall MultiCall) SetRange(key string, offset int64, value interface{}) error

SetRange method sends SETRANGE command to the redis server.

func (MultiCall) ZAdd

func (multiCall MultiCall) ZAdd(args ...interface{}) error

ZAdd method sends ZADD command to the redis server.

func (MultiCall) ZIncrBy

func (multiCall MultiCall) ZIncrBy(key string, increment int64, member interface{}) error

ZIncrBy method sends ZINCRBY command to the redis server.

func (MultiCall) ZIncrByFloat

func (multiCall MultiCall) ZIncrByFloat(key string, increment float64, member interface{}) error

ZIncrByFloat method sends ZINCRBY command with float increment to the redis server.

func (MultiCall) ZInterStore

func (multiCall MultiCall) ZInterStore(args ...interface{}) error

ZInterStore method sends ZINTERSTORE command to the redis server.

func (MultiCall) ZRem

func (multiCall MultiCall) ZRem(args ...interface{}) error

ZRem method sends ZREM command to the redis server.

func (MultiCall) ZRemRangeByRank

func (multiCall MultiCall) ZRemRangeByRank(key string, start int64, stop int64) error

ZRemRangeByRank method sends ZREMRANGEBYRANK command to the redis server.

func (MultiCall) ZRemRangeByScore

func (multiCall MultiCall) ZRemRangeByScore(key string, min interface{}, max interface{}) error

ZRemRangeByScore method sends ZREMRANGEBYSCORE command to the redis server.

func (MultiCall) ZUnionStore

func (multiCall MultiCall) ZUnionStore(args ...interface{}) error

ZUnionStore method sends ZUNIONSTORE command to the redis server.

type MultiCallFunc

type MultiCallFunc func(MultiCall) error

MultiCallFunc is a function that will be wrapped in bulk and transaction processing. Inside it should call all necessary commands to redis server using provided MultiCall context.

type Option

type Option func(*Config) error

Option function that is fed to NewClient and MustNewClient. Obtain them using 'With' functions down below.

func WithAddress

func WithAddress(address string) Option

WithAddress option applies provided redis server address. Default: "127.0.0.1:6379".

func WithConfig

func WithConfig(service ConfigService, key string) Option

WithConfig option retrieves configuration from provided configuration service.

Example JSON configuration with all possible fields (if some are not present, defaults will be used):

{
    "address": "127.0.0.1:6379",
    "maxIdle": 5,
    "idleTimeout": 300
}

func WithDealFunc

func WithDealFunc(dialFunc func() (redis.Conn, error)) Option

WithDealFunc option applies provided custom dial function instead of the default one. Used primarily in tests to mock redis connection.

func WithIdleTimeout

func WithIdleTimeout(idleTimeout int) Option

WithIdleTimeout option applies provided timeout in seconds after which idle connections will be dropped away. Default: 600.

func WithMaxIdle

func WithMaxIdle(maxIdle int) Option

WithMaxIdle option applies provided maximum number of idle redis connections in the pool. Default: 3.

type Reply

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

Reply structure represents some reply returned from redis server.

func (Reply) Bool

func (reply Reply) Bool() (bool, error)

Bool method tries to represent returned data as boolean.

func (Reply) Bytes

func (reply Reply) Bytes() ([]byte, error)

Bytes method tries to represent returned data as slice of bytes.

func (Reply) Error

func (reply Reply) Error() error

Error method retrieves an error arisen on reply receiving.

func (Reply) Float64

func (reply Reply) Float64() (float64, error)

Float64 method tries to represent returned data as a number with a float point.

func (Reply) Int

func (reply Reply) Int() (int, error)

Int method tries to represent returned data as int.

func (Reply) Int64

func (reply Reply) Int64() (int64, error)

Int64 method tries to represent returned data as int64.

func (Reply) IsError

func (reply Reply) IsError() bool

IsError method checks if reply contains an error.

func (Reply) IsNil

func (reply Reply) IsNil() bool

IsNil method checks if returned data is nil.

func (Reply) List

func (reply Reply) List() ([]string, error)

List method tries to represent returned data as a list of strings.

func (Reply) Map

func (reply Reply) Map() (map[string]string, error)

Map method tries to represent returned data as a map of strings.

func (Reply) Scan

func (reply Reply) Scan(args ...interface{}) error

Scan method tries to put returned data into provided arguments (that must be pointers) in order.

func (Reply) ScanStruct

func (reply Reply) ScanStruct(dest interface{}) error

ScanStruct method tries to put returned data into a structure that is pointed to by the dest argument. For this method to work properly, the returned data must be a map of some sort (such as the HGETALL command returns).

You can use 'redis' tag and RedisScan methods to control scanning behavior. Nil values in reply data are silently ignored.

func (Reply) String

func (reply Reply) String() (string, error)

String method tries to represent returned data as string.

type TransConn

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

TransConn structure represents connection to redis server retrieved from the pool. It is specially wrapped to send all the commands as part of some transaction.

func (*TransConn) Append

func (conn *TransConn) Append(key string, value interface{}) error

Append method sends APPEND command to the redis server.

func (*TransConn) BitOp

func (conn *TransConn) BitOp(args ...interface{}) error

BitOp method sends BITOP command to the redis server.

func (*TransConn) Close

func (conn *TransConn) Close() error

Close method returns connection to the pool. Don't use connection object after that.

func (*TransConn) Decr

func (conn *TransConn) Decr(key string) error

Decr method sends DECR command to the redis server.

func (*TransConn) DecrBy

func (conn *TransConn) DecrBy(key string, decrement int64) error

DecrBy method sends DECRBY command to the redis server.

func (*TransConn) Del

func (conn *TransConn) Del(args ...interface{}) error

Del method sends DEL command to the redis server.

func (*TransConn) Discard

func (conn *TransConn) Discard() Reply

Discard method sends DISCARD command to redis server and waits for the reply.

func (*TransConn) Eval

func (conn *TransConn) Eval(args ...interface{}) error

Eval method sends EVAL command to the redis server.

func (*TransConn) EvalSha

func (conn *TransConn) EvalSha(args ...interface{}) error

EvalSha method sends EVALSHA command to the redis server.

func (*TransConn) Exec

func (conn *TransConn) Exec() Reply

Exec method sends EXEC command to redis server and waits for the reply.

func (*TransConn) Expire

func (conn *TransConn) Expire(key string, seconds int64) error

Expire method sends EXPIRE command to the redis server.

func (*TransConn) ExpireAt

func (conn *TransConn) ExpireAt(key string, timestamp int64) error

ExpireAt method sends EXPIREAT command to the redis server.

func (*TransConn) HDel

func (conn *TransConn) HDel(args ...interface{}) error

HDel method sends HDEL command to the redis server.

func (*TransConn) HIncrBy

func (conn *TransConn) HIncrBy(key string, field string, increment int64) error

HIncrBy method sends HINCRBY command to the redis server.

func (*TransConn) HIncrByFloat

func (conn *TransConn) HIncrByFloat(key string, field string, increment float64) error

HIncrByFloat method sends HINCRBYFLOAT command to the redis server.

func (*TransConn) HMSet

func (conn *TransConn) HMSet(key string, values map[string]interface{}) error

HMSet method unfolds provided map and sends HMSET command to the redis server.

func (*TransConn) HMSetFlat

func (conn *TransConn) HMSetFlat(args ...interface{}) error

HMSetFlat method sends HMSET command to the redis server.

func (*TransConn) HSet

func (conn *TransConn) HSet(key string, field string, value interface{}) error

HSet method sends HSET command to the redis server.

func (*TransConn) HSetNx

func (conn *TransConn) HSetNx(key string, field string, value interface{}) error

HSetNx method sends HSETNX command to the redis server.

func (*TransConn) Incr

func (conn *TransConn) Incr(key string) error

Incr method sends INCR command to the redis server.

func (*TransConn) IncrBy

func (conn *TransConn) IncrBy(key string, increment int64) error

IncrBy method sends INCRBY command to the redis server.

func (*TransConn) IncrByFloat

func (conn *TransConn) IncrByFloat(key string, increment float64) error

IncrByFloat method sends INCRBYFLOAT command to the redis server.

func (*TransConn) LInsertAfter

func (conn *TransConn) LInsertAfter(key string, pivot interface{}, value interface{}) error

LInsertAfter method sends LINSERT command with AFTER modifier to the redis server.

func (*TransConn) LInsertBefore

func (conn *TransConn) LInsertBefore(key string, pivot interface{}, value interface{}) error

LInsertBefore method sends LINSERT command with BEFORE modifier to the redis server.

func (*TransConn) LPush

func (conn *TransConn) LPush(args ...interface{}) error

LPush method sends LPUSH command to the redis server.

func (*TransConn) LPushX

func (conn *TransConn) LPushX(key string, value interface{}) error

LPushX method sends LPUSHX command to the redis server.

func (*TransConn) LRem

func (conn *TransConn) LRem(key string, count int64, value interface{}) error

LRem method sends LREM command to the redis server.

func (*TransConn) LSet

func (conn *TransConn) LSet(key string, index int64, value interface{}) error

LSet method sends LSET command to the redis server.

func (*TransConn) LTrim

func (conn *TransConn) LTrim(key string, start int64, stop int64) error

LTrim method sends LTRIM command to the redis server.

func (*TransConn) MSet

func (conn *TransConn) MSet(values map[string]interface{}) error

MSet method unfolds provided map and sends MSET command to the redis server.

func (*TransConn) MSetFlat

func (conn *TransConn) MSetFlat(args ...interface{}) error

MSetFlat method sends MSET command to the redis server.

func (*TransConn) MSetNx

func (conn *TransConn) MSetNx(values map[string]interface{}) error

MSetNx method unfolds provided map and sends MSETNX command to the redis server.

func (*TransConn) MSetNxFlat

func (conn *TransConn) MSetNxFlat(args ...interface{}) error

MSetNxFlat method sends MSETNX command to the redis server.

func (*TransConn) Move

func (conn *TransConn) Move(key string, db int64) error

Move method sends MOVE command to the redis server.

func (*TransConn) PExpire

func (conn *TransConn) PExpire(key string, milliseconds int64) error

PExpire method sends PEXPIRE command to the redis server.

func (*TransConn) PExpireAt

func (conn *TransConn) PExpireAt(key string, mtimestamp int64) error

PExpireAt method sends PEXPIREAT command to the redis server.

func (*TransConn) PSetEx

func (conn *TransConn) PSetEx(key string, milliseconds int64, value interface{}) error

PSetEx method sends PSETEX command to the redis server.

func (*TransConn) Persist

func (conn *TransConn) Persist(key string) error

Persist method sends PERSIST command to the redis server.

func (*TransConn) RPopLPush

func (conn *TransConn) RPopLPush(source string, destination string) error

RPopLPush method sends RPOPLPUSH command to the redis server.

func (*TransConn) RPush

func (conn *TransConn) RPush(args ...interface{}) error

RPush method sends RPUSH command to the redis server.

func (*TransConn) RPushX

func (conn *TransConn) RPushX(key string, value interface{}) error

RPushX method sends RPUSHX command to the redis server.

func (*TransConn) Rename

func (conn *TransConn) Rename(key string, newkey string) error

Rename method sends RENAME command to the redis server.

func (*TransConn) RenameNx

func (conn *TransConn) RenameNx(key string, newkey string) error

RenameNx method sends RENAMENX command to the redis server.

func (*TransConn) Restore

func (conn *TransConn) Restore(key string, ttl int64, value interface{}) error

Restore method sends RESTORE command to the redis server.

func (*TransConn) SAdd

func (conn *TransConn) SAdd(args ...interface{}) error

SAdd method sends SADD command to the redis server.

func (*TransConn) SDiffStore

func (conn *TransConn) SDiffStore(args ...interface{}) error

SDiffStore method sends SDIFFSTORE command to the redis server.

func (*TransConn) SInterStore

func (conn *TransConn) SInterStore(args ...interface{}) error

SInterStore method sends SINTERSTORE command to the redis server.

func (*TransConn) SMove

func (conn *TransConn) SMove(source string, destination string, member interface{}) error

SMove method sends SMOVE command to the redis server.

func (*TransConn) SRem

func (conn *TransConn) SRem(args ...interface{}) error

SRem method sends SREM command to the redis server.

func (*TransConn) SUnionStore

func (conn *TransConn) SUnionStore(args ...interface{}) error

SUnionStore method sends SUNIONSTORE command to the redis server.

func (*TransConn) ScriptFlush

func (conn *TransConn) ScriptFlush() error

ScriptFlush method sends SCRIPT FLUSH command to the redis server.

func (*TransConn) ScriptKill

func (conn *TransConn) ScriptKill() error

ScriptKill method sends SCRIPT KILL command to the redis server.

func (*TransConn) Send

func (conn *TransConn) Send(commandName string, args ...interface{}) error

Send method sends specified command with arguments to the redis server without waiting for reply. If connection is not in transaction state yet, it will send MULTI command automatically.

func (*TransConn) Set

func (conn *TransConn) Set(key string, value interface{}) error

Set method sends SET command to the redis server.

func (*TransConn) SetAdvanced

func (conn *TransConn) SetAdvanced(args ...interface{}) error

SetAdvanced method sends SET command with any provided advanced args to the redis server.

func (*TransConn) SetBit

func (conn *TransConn) SetBit(key string, offset int64, value interface{}) error

SetBit method sends SETBIT command to the redis server.

func (*TransConn) SetEx

func (conn *TransConn) SetEx(key string, seconds int64, value interface{}) error

SetEx method sends SETEX command to the redis server.

func (*TransConn) SetNx

func (conn *TransConn) SetNx(key string, value interface{}) error

SetNx method sends SETNX command to the redis server.

func (*TransConn) SetRange

func (conn *TransConn) SetRange(key string, offset int64, value interface{}) error

SetRange method sends SETRANGE command to the redis server.

func (*TransConn) ZAdd

func (conn *TransConn) ZAdd(args ...interface{}) error

ZAdd method sends ZADD command to the redis server.

func (*TransConn) ZIncrBy

func (conn *TransConn) ZIncrBy(key string, increment int64, member interface{}) error

ZIncrBy method sends ZINCRBY command to the redis server.

func (*TransConn) ZIncrByFloat

func (conn *TransConn) ZIncrByFloat(key string, increment float64, member interface{}) error

ZIncrByFloat method sends ZINCRBY command with float increment to the redis server.

func (*TransConn) ZInterStore

func (conn *TransConn) ZInterStore(args ...interface{}) error

ZInterStore method sends ZINTERSTORE command to the redis server.

func (*TransConn) ZRem

func (conn *TransConn) ZRem(args ...interface{}) error

ZRem method sends ZREM command to the redis server.

func (*TransConn) ZRemRangeByRank

func (conn *TransConn) ZRemRangeByRank(key string, start int64, stop int64) error

ZRemRangeByRank method sends ZREMRANGEBYRANK command to the redis server.

func (*TransConn) ZRemRangeByScore

func (conn *TransConn) ZRemRangeByScore(key string, min interface{}, max interface{}) error

ZRemRangeByScore method sends ZREMRANGEBYSCORE command to the redis server.

func (*TransConn) ZUnionStore

func (conn *TransConn) ZUnionStore(args ...interface{}) error

ZUnionStore method sends ZUNIONSTORE command to the redis server.

Directories

Path Synopsis
Package rdidgen provides implementation of id generation using redis server.
Package rdidgen provides implementation of id generation using redis server.

Jump to

Keyboard shortcuts

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