Help us shape the future of Go! Take the 2026 Go Developer Survey

redisutil

package
v1.8.3 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: MIT Imports: 4 Imported by: 8

Documentation

Overview

Package redisutil provides Redis client utilities with go-redis/v9 backend. It maintains API compatibility with the previous redigo-based implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RedisClient

type RedisClient struct {
	Address string
	// contains filtered or unexported fields
}

RedisClient wraps go-redis client with compatible API

func GetDefaultRedisClient added in v1.7.14

func GetDefaultRedisClient(address string) *RedisClient

GetDefaultRedisClient returns the RedisClient of specified address use default maxIdle & maxActive

func GetRedisClient

func GetRedisClient(address string, maxIdle, maxActive int) *RedisClient

GetRedisClient returns the RedisClient of specified address & maxIdle & maxActive

func (*RedisClient) Append

func (rc *RedisClient) Append(key string, val interface{}) (interface{}, error)

Append appends the string to original value specified by key.

func (*RedisClient) BLPop

func (rc *RedisClient) BLPop(key ...interface{}) (map[string]string, error)

BLPop removes and returns the first element of the first non-empty list

func (*RedisClient) BRPop

func (rc *RedisClient) BRPop(key ...interface{}) (map[string]string, error)

BRPop removes and returns the last element of the first non-empty list

func (*RedisClient) BRPopLPush

func (rc *RedisClient) BRPopLPush(source string, destination string) (string, error)

BRPopLPush pops from one list and pushes to another with blocking

func (*RedisClient) DBSize

func (rc *RedisClient) DBSize() (int64, error)

DBSize returns count of keys in the database

func (*RedisClient) DECR

func (rc *RedisClient) DECR(key string) (int, error)

DECR atomically decrement the value by 1 specified by key

func (*RedisClient) Del

func (rc *RedisClient) Del(key string) (int64, error)

Del deletes specified key

func (*RedisClient) Exists

func (rc *RedisClient) Exists(key string) (bool, error)

Exists whether key exists

func (*RedisClient) Expire

func (rc *RedisClient) Expire(key string, timeOutSeconds int64) (int64, error)

Expire specifies the expire duration for key

func (*RedisClient) FlushDB

func (rc *RedisClient) FlushDB()

FlushDB removes all data in the database

func (*RedisClient) Get

func (rc *RedisClient) Get(key string) (string, error)

Get returns the content as string specified by key

func (*RedisClient) GetConn

func (rc *RedisClient) GetConn() interface{}

GetConn returns a connection from the pool Deprecated: This method exists for backwards compatibility but is not recommended. Use the RedisClient methods directly instead.

func (*RedisClient) GetObj

func (rc *RedisClient) GetObj(key string) (interface{}, error)

GetObj returns the content specified by key

func (*RedisClient) HDel

func (rc *RedisClient) HDel(args ...interface{}) (int64, error)

HDel delete content in hashset

func (*RedisClient) HExist

func (rc *RedisClient) HExist(hashID string, field string) (int, error)

HExist returns if the field exists in specified hashID

func (*RedisClient) HGet

func (rc *RedisClient) HGet(hashID string, field string) (string, error)

HGet returns content specified by hashID and field

func (*RedisClient) HGetAll

func (rc *RedisClient) HGetAll(hashID string) (map[string]string, error)

HGetAll returns all content specified by hashID

func (*RedisClient) HIncrBy

func (rc *RedisClient) HIncrBy(hashID string, field string, increment int) (int, error)

HIncrBy increment the value specified by hashID and field

func (*RedisClient) HLen

func (rc *RedisClient) HLen(hashID string) (int64, error)

HLen returns count of fields in hashID

func (*RedisClient) HSet

func (rc *RedisClient) HSet(hashID string, field string, val string) error

HSet set content with hashID and field

func (*RedisClient) HSetNX

func (rc *RedisClient) HSetNX(hashID, field, value string) (interface{}, error)

HSetNX set content with hashID and field, if the field does not exists

func (*RedisClient) HVals

func (rc *RedisClient) HVals(hashID string) (interface{}, error)

HVals return all the values in all fields specified by hashID

func (*RedisClient) INCR

func (rc *RedisClient) INCR(key string) (int, error)

INCR atomically increment the value by 1 specified by key

func (*RedisClient) LIndex

func (rc *RedisClient) LIndex(key string, index int) (string, error)

LIndex returns the element at index

func (*RedisClient) LInsertAfter

func (rc *RedisClient) LInsertAfter(key string, pivot string, value string) (int, error)

LInsertAfter inserts value after pivot

func (*RedisClient) LInsertBefore

func (rc *RedisClient) LInsertBefore(key string, pivot string, value string) (int, error)

LInsertBefore inserts value before pivot

func (*RedisClient) LLen

func (rc *RedisClient) LLen(key string) (int, error)

LLen returns the length of the list

func (*RedisClient) LPop

func (rc *RedisClient) LPop(key string) (string, error)

LPop removes and returns the first element of the list

func (*RedisClient) LPush

func (rc *RedisClient) LPush(key string, value ...interface{}) (int, error)

LPush insert the values into front of the list

func (*RedisClient) LPushX

func (rc *RedisClient) LPushX(key string, value string) (int, error)

LPushX inserts value at the head of the list only if key exists

func (*RedisClient) LRange

func (rc *RedisClient) LRange(key string, start int, stop int) ([]string, error)

LRange returns elements from start to stop

func (*RedisClient) LRem

func (rc *RedisClient) LRem(key string, count int, value string) (int, error)

LRem removes count elements equal to value

func (*RedisClient) LSet

func (rc *RedisClient) LSet(key string, index int, value string) (string, error)

LSet sets the list element at index to value

func (*RedisClient) LTrim

func (rc *RedisClient) LTrim(key string, start int, stop int) (string, error)

LTrim trims the list to the specified range

func (*RedisClient) Ping

func (rc *RedisClient) Ping() (string, error)

Ping tests the client is ready for use

func (*RedisClient) RPop

func (rc *RedisClient) RPop(key string) (string, error)

RPop removes and returns the last element of the list

func (*RedisClient) RPopLPush

func (rc *RedisClient) RPopLPush(source string, destination string) (string, error)

RPopLPush removes the last element from one list and pushes it to another

func (*RedisClient) RPush

func (rc *RedisClient) RPush(key string, value ...interface{}) (int, error)

RPush inserts values at the tail of the list

func (*RedisClient) RPushX

func (rc *RedisClient) RPushX(key string, value ...interface{}) (int, error)

RPushX inserts value at the tail of the list only if key exists

func (*RedisClient) SAdd

func (rc *RedisClient) SAdd(key string, member ...interface{}) (int, error)

SAdd add one or multiple members into the set

func (*RedisClient) SCard

func (rc *RedisClient) SCard(key string) (int, error)

SCard returns cardinality of the set

func (*RedisClient) SDiff

func (rc *RedisClient) SDiff(key ...interface{}) ([]string, error)

SDiff returns the difference between sets

func (*RedisClient) SDiffStore

func (rc *RedisClient) SDiffStore(destination string, key ...interface{}) (int, error)

SDiffStore stores the difference in a new set

func (*RedisClient) SInter

func (rc *RedisClient) SInter(key ...interface{}) ([]string, error)

SInter returns the intersection of sets

func (*RedisClient) SInterStore

func (rc *RedisClient) SInterStore(destination string, key ...interface{}) (int, error)

SInterStore stores the intersection in a new set

func (*RedisClient) SIsMember

func (rc *RedisClient) SIsMember(key string, member string) (bool, error)

SIsMember returns if member is a member of set

func (*RedisClient) SMembers

func (rc *RedisClient) SMembers(key string) ([]string, error)

SMembers returns all members of the set

func (*RedisClient) SMove

func (rc *RedisClient) SMove(source string, destination string, member string) (bool, error)

SMove moves member from one set to another

func (*RedisClient) SPop

func (rc *RedisClient) SPop(key string) (string, error)

SPop removes and returns a random member from the set

func (*RedisClient) SRandMember

func (rc *RedisClient) SRandMember(key string, count int) ([]string, error)

SRandMember returns random count elements from set

func (*RedisClient) SRem

func (rc *RedisClient) SRem(key string, member ...interface{}) (int, error)

SRem removes multiple elements from set

func (*RedisClient) SUnion

func (rc *RedisClient) SUnion(key ...interface{}) ([]string, error)

SUnion returns the union of sets

func (*RedisClient) SUnionStore

func (rc *RedisClient) SUnionStore(destination string, key ...interface{}) (int, error)

SUnionStore stores the union in a new set

func (*RedisClient) Set

func (rc *RedisClient) Set(key string, val interface{}) (interface{}, error)

Set put key/value into redis

func (*RedisClient) SetNX

func (rc *RedisClient) SetNX(key, value string) (interface{}, error)

SetNX sets key/value only if key does not exists

func (*RedisClient) SetWithExpire

func (rc *RedisClient) SetWithExpire(key string, val interface{}, timeOutSeconds int64) (interface{}, error)

SetWithExpire set the key/value with specified duration

Jump to

Keyboard shortcuts

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