<commit_before>package redis

import (
	"errors"
	"github.com/garyburd/redigo/redis"
	"github.com/rafaeljusto/redigomock"
	"time"
)

// RedisStore holds a handle to the Redis pool
type RedisStore struct {
	Pool  *redis.Pool
	Mutex *Mutex
}

var (
	RedisCache   RedisStore
	ErrCacheMiss = errors.New("cache: key not found.")
)

type Redis struct {
	// Redis address and max pool connections
	Protocol       string
	Address        string
	MaxIdle        int
	MaxConnections int
}

// NewRedisCache creates a new pool
func (r *Redis) NewRedisCache() {

	RedisCache.Pool = &redis.Pool{
		MaxIdle:     r.MaxIdle,
		MaxActive:   r.MaxConnections,
		IdleTimeout: 240 * time.Second,
		Dial: func() (c redis.Conn, err error) {
			c, err = redis.Dial(r.Protocol, r.Address)
			if err != nil {
				return
			}
			return
		},
	}

	// create our distributed lock
	RedisCache.Mutex = NewMutex([]Pool{
		RedisCache.Pool,
	})

	return
}

type RedisPoolMock struct {
	Conn *redigomock.Conn
}

func (r *RedisPoolMock) Get() redis.Conn {
	return r.Conn
}

// NewRedisMock returns a fake redis pool for testing
func NewRedisMock() {

	RedisCache.Pool = &RedisPoolMock{
		Conn: redigomock.NewConn(),<commit_msg>add redis mock<commit_after>package redis

import (
	"errors"
	"github.com/garyburd/redigo/redis"
	"github.com/rafaeljusto/redigomock"
	"time"
)

type Pool interface {
	Get() redis.Conn
}

// RedisStore holds a handle to the Redis pool
type RedisStore struct {
	Pool  *Pool
	Mutex *Mutex
}

var (
	RedisCache   RedisStore
	ErrCacheMiss = errors.New("cache: key not found.")
)

type Redis struct {
	// Redis address and max pool connections
	Protocol       string
	Address        string
	MaxIdle        int
	MaxConnections int
}

// NewRedisCache creates a new pool
func (r *Redis) NewRedisCache() {

	RedisCache.Pool = &redis.Pool{
		MaxIdle:     r.MaxIdle,
		MaxActive:   r.MaxConnections,
		IdleTimeout: 240 * time.Second,
		Dial: func() (c redis.Conn, err error) {
			c, err = redis.Dial(r.Protocol, r.Address)
			if err != nil {
				return
			}
			return
		},
	}

	// create our distributed lock
	RedisCache.Mutex = NewMutex([]Pool{
		RedisCache.Pool,
	})

	return
}

type RedisPoolMock struct {
	Conn *redigomock.Conn
}

func (r *RedisPoolMock) Get() redis.Conn {
	return r.Conn
}

func (r *RedisPoolMock) Close() error {
	return nil
}

// NewRedisMock returns a fake redis pool for testing
func NewRedisMock() {

	RedisCache.Pool = &RedisPoolMock{
		Conn: redigomock.NewConn(),
{'fraction_non_alphanumeric': 0.10715729882733523, 'fraction_numerical': 0.002426202992317024, 'mean_word_length': 3.317626527050611, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '295137', 'n_tokens_mistral': 968, 'n_tokens_neox': 923, 'n_words': 241}