Documentation ¶
Index ¶
- Variables
- func AddDelayQueue(queueKey string, i interface{}, delay time.Duration) error
- func AddPriorityQueue(queueKey string, i interface{}, priority int64) error
- func AddQueue(queueKey string, i interface{}) error
- func AddQueueByScore(queueKey string, i interface{}, score float64) error
- func AnyDo(name string, expiration time.Duration) int
- func DayDo(name string) int
- func DecrBy(key string, value int64) *redis.IntCmd
- func Del(keys ...string) *redis.IntCmd
- func Expire(key string, expiration time.Duration) *redis.BoolCmd
- func Get(key string) *redis.StringCmd
- func GetAnyDoKey(name string, expiration time.Duration) string
- func GetCacheKey(key string) string
- func GetPrefix() string
- func GetRedis() *redis.Ring
- func Has(key string) bool
- func HourDo(name string) int
- func IncrBy(key string, value int64) *redis.IntCmd
- func IncrByFloat(key string, value float64) *redis.FloatCmd
- func JsonGet(key string, paths ...string) *redis.JSONCmd
- func JsonSet(key string, value any, expiration time.Duration) *redis.StatusCmd
- func MonthDo(name string) int
- func Prefix(key string)
- func RunQueue(queueKey string, batchNum int, qType string, ...)
- func Set(key string, value any, expiration time.Duration) *redis.StatusCmd
- func TTL(key string) *redis.DurationCmd
Constants ¶
This section is empty.
Variables ¶
View Source
var RedisNil = redis.Nil
RedisNil is redis nil
Functions ¶
func AddDelayQueue ¶ added in v0.1.7
AddDelayQueue
func AddPriorityQueue ¶ added in v0.1.10
AddPriorityQueue
func AddQueueByScore ¶ added in v0.1.11
AddQueueByScore
func GetAnyDoKey ¶ added in v0.1.40
GetAnyDoKey
func RunQueue ¶ added in v0.1.6
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
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.