redis

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RedisNil = redis.Nil

RedisNil is redis nil

Functions

func AddDelayQueue

func AddDelayQueue(queueKey string, i interface{}, delay time.Duration) error

AddDelayQueue

func AddPriorityQueue

func AddPriorityQueue(queueKey string, i interface{}, priority int64) error

AddPriorityQueue

func AddQueue

func AddQueue(queueKey string, i interface{}) error

AddQueue

func AddQueueByScore

func AddQueueByScore(queueKey string, i interface{}, score float64) error

AddQueueByScore

func AnyDo

func AnyDo(name string, expiration time.Duration) int

AnyDo

func DayDo

func DayDo(name string) int

DayDo 每天可执行次数

func DecrBy

func DecrBy(key string, value int64) *redis.IntCmd

DecrBy

func Del

func Del(keys ...string) *redis.IntCmd

Del

func Expire

func Expire(key string, expiration time.Duration) *redis.BoolCmd

Expire

func Get

func Get(key string) *redis.StringCmd

Get

func GetAnyDoKey

func GetAnyDoKey(name string, expiration time.Duration) string

GetAnyDoKey

func GetCacheKey

func GetCacheKey(key string) string

GetCacheKey is get cache key

func GetPrefix

func GetPrefix() string

GetPrefix is get prefix

func GetRedis

func GetRedis() *redis.Ring

创建一个 redis 连接

func Has

func Has(key string) bool

Has

func HourDo

func HourDo(name string) int

HourDo 每小时可执行次数

func IncrBy

func IncrBy(key string, value int64) *redis.IntCmd

IncrBy

func IncrByFloat

func IncrByFloat(key string, value float64) *redis.FloatCmd

IncrByFloat

func JsonGet

func JsonGet(key string, paths ...string) *redis.JSONCmd

JsonSet

func JsonSet

func JsonSet(key string, value any, expiration time.Duration) *redis.StatusCmd

JsonSet

func MonthDo

func MonthDo(name string) int

MonthDo 每月可执行次数

func Prefix

func Prefix(key string)

Prefix is set prefix

func RunQueue

func RunQueue(queueKey string, batchNum int, qType string, callback func([]byte) (interface{}, error), callbacks ...func([]interface{}) error)

RunQueue processes tasks from a Redis sorted set queue.

Example usage:

1. Process tasks one by one:

redis.RunQueue("task_queue", 10, "inf", func(data []byte) (interface{}, error) {
	log.Infof("Processing task: %s", string(data))
	// Process the task here
	return nil, nil
})

2. Process tasks in batches:

redis.RunQueue("task_queue", 10, "inf", func(data []byte) (interface{}, error) {
	// Process individual task
	return processTask(data), nil
}, func(results []interface{}) error {
	// Batch process the results
	return batchProcessResults(results)
})

3. Process time-based tasks:

redis.RunQueue("delayed_task_queue", 10, "time", func(data []byte) (interface{}, error) {
	log.Infof("Processing delayed task: %s", string(data))
	// Process the delayed task here
	return nil, nil
})

Parameters:

  • queueKey: The key of the Redis sorted set queue
  • batchNum: The maximum number of tasks to process in each iteration
  • qType: Use "inf" for regular queue, "time" for time-based queue
  • callback: Function to process each task
  • callbacks: Optional function(s) for batch processing results

func Set

func Set(key string, value any, expiration time.Duration) *redis.StatusCmd

Set

func TTL

func TTL(key string) *redis.DurationCmd

TTL

Types

This section is empty.

Jump to

Keyboard shortcuts

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