From 90df18562cda31753872960bc4c8e901f41b79d5 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Thu, 20 Jan 2022 11:49:13 +0100 Subject: [PATCH] redis.go: implement functions for pipeline. --- redis.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/redis.go b/redis.go index c7d03b2..5187340 100644 --- a/redis.go +++ b/redis.go @@ -10,6 +10,8 @@ import ( var rdb *redis.Client +var redis_pipe redis.Pipeliner + var redisCtx = context.Background() var redisPrefix = "ship." @@ -20,6 +22,8 @@ func RedisConnect(addr string, password string, db int) { Password: password, DB: db, }) + + redis_pipe = rdb.Pipeline() } func RedisKey(components ...string) (string) { @@ -37,3 +41,11 @@ func RedisSet(key string, value interface{}, expiration time.Duration) (*redis.S func RedisPublish(channel string, message interface{}) (*redis.IntCmd) { return rdb.Publish(redisCtx, channel, message) } + +func RedisRegisterPublish(channel string, message interface{}) (*redis.IntCmd) { + return redis_pipe.Publish(redisCtx, channel, message) +} + +func RedisSend() ([]redis.Cmder, error) { + return redis_pipe.Exec(redisCtx) +}