mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 16:40:24 +08:00 
			
		
		
		
	[Vendor] Update go-redis to v8.5.0 (#13749)
* Update go-redis to v8.4.0 * github.com/go-redis/redis/v8 v8.4.0 -> v8.5.0 * Apply suggestions from code review Co-authored-by: zeripath <art27@cantab.net> * TODO * Use the Queue termination channel as the default context for pushes Signed-off-by: Andrew Thornton <art27@cantab.net> * missed one Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: zeripath <art27@cantab.net>
This commit is contained in:
		@@ -4,7 +4,12 @@
 | 
			
		||||
 | 
			
		||||
package queue
 | 
			
		||||
 | 
			
		||||
import "github.com/go-redis/redis/v7"
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
 | 
			
		||||
	"code.gitea.io/gitea/modules/graceful"
 | 
			
		||||
	"github.com/go-redis/redis/v8"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// RedisUniqueQueueType is the type for redis queue
 | 
			
		||||
const RedisUniqueQueueType Type = "unique-redis"
 | 
			
		||||
@@ -46,6 +51,8 @@ func NewRedisUniqueQueue(handle HandlerFunc, cfg, exemplar interface{}) (Queue,
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	byteFIFO.ctx = graceful.NewChannelContext(byteFIFOQueue.IsTerminated(), fmt.Errorf("queue has been terminated"))
 | 
			
		||||
 | 
			
		||||
	queue := &RedisUniqueQueue{
 | 
			
		||||
		ByteFIFOUniqueQueue: byteFIFOQueue,
 | 
			
		||||
	}
 | 
			
		||||
@@ -86,7 +93,7 @@ func NewRedisUniqueByteFIFO(config RedisUniqueByteFIFOConfiguration) (*RedisUniq
 | 
			
		||||
 | 
			
		||||
// PushFunc pushes data to the end of the fifo and calls the callback if it is added
 | 
			
		||||
func (fifo *RedisUniqueByteFIFO) PushFunc(data []byte, fn func() error) error {
 | 
			
		||||
	added, err := fifo.client.SAdd(fifo.setName, data).Result()
 | 
			
		||||
	added, err := fifo.client.SAdd(fifo.ctx, fifo.setName, data).Result()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
@@ -98,12 +105,12 @@ func (fifo *RedisUniqueByteFIFO) PushFunc(data []byte, fn func() error) error {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return fifo.client.RPush(fifo.queueName, data).Err()
 | 
			
		||||
	return fifo.client.RPush(fifo.ctx, fifo.queueName, data).Err()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Pop pops data from the start of the fifo
 | 
			
		||||
func (fifo *RedisUniqueByteFIFO) Pop() ([]byte, error) {
 | 
			
		||||
	data, err := fifo.client.LPop(fifo.queueName).Bytes()
 | 
			
		||||
	data, err := fifo.client.LPop(fifo.ctx, fifo.queueName).Bytes()
 | 
			
		||||
	if err != nil && err != redis.Nil {
 | 
			
		||||
		return data, err
 | 
			
		||||
	}
 | 
			
		||||
@@ -112,13 +119,13 @@ func (fifo *RedisUniqueByteFIFO) Pop() ([]byte, error) {
 | 
			
		||||
		return data, nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	err = fifo.client.SRem(fifo.setName, data).Err()
 | 
			
		||||
	err = fifo.client.SRem(fifo.ctx, fifo.setName, data).Err()
 | 
			
		||||
	return data, err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Has returns whether the fifo contains this data
 | 
			
		||||
func (fifo *RedisUniqueByteFIFO) Has(data []byte) (bool, error) {
 | 
			
		||||
	return fifo.client.SIsMember(fifo.setName, data).Result()
 | 
			
		||||
	return fifo.client.SIsMember(fifo.ctx, fifo.setName, data).Result()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func init() {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user