<commit_before>package redis

import (
	"time"

	"github.com/garyburd/redigo/redis"
	"h12.me/gspec/db/docker"
)

const containerName = "gspec-db-redis-ac3bfb841b3c47378dfdecca51b23042"

type Redis struct {
	pool *redis.Pool
	c    *docker.Container
}

func New() (*Redis, error) {
	container, err := docker.Find(containerName)
	if err != nil {
		container, err = docker.New("--name="+containerName, "--detach=true", "--publish=8379:6379", "redis")
		if err != nil {
			return nil, err
		}
	}
	return &Redis{
		pool: &redis.Pool{
			MaxIdle:     3,
			IdleTimeout: 240 * time.Second,
			Dial: func() (redis.Conn, error) {
				c, err := redis.Dial("tcp", container.Addr.String())
				if err != nil {
					return nil, err
				}
				return c, err
			},
			TestOnBorrow: func(c redis.Conn, t time.Time) error {
				_, err := c.Do("PING")
				return err
			},
		},
		c: container,<commit_msg>use default port.<commit_after>package redis

import (
	"time"

	"github.com/garyburd/redigo/redis"
	"h12.me/gspec/db/docker"
)

const containerName = "gspec-db-redis-ac3bfb841b3c47378dfdecca51b23042"

type Redis struct {
	pool *redis.Pool
	c    *docker.Container
}

func New() (*Redis, error) {
	container, err := docker.Find(containerName)
	if err != nil {
		container, err = docker.New("--name="+containerName, "--detach=true", "--publish=6379:6379", "redis")
		if err != nil {
			return nil, err
		}
	}
	return &Redis{
		pool: &redis.Pool{
			MaxIdle:     3,
			IdleTimeout: 240 * time.Second,
			Dial: func() (redis.Conn, error) {
				c, err := redis.Dial("tcp", container.Addr.String())
				if err != nil {
					return nil, err
				}
				return c, err
			},
			TestOnBorrow: func(c redis.Conn, t time.Time) error {
				_, err := c.Do("PING")
				return err
			},
		},
		c: container,
{'fraction_non_alphanumeric': 0.16065388951521983, 'fraction_numerical': 0.03494926719278467, 'mean_word_length': 3.1087962962962963, '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': '1021113', 'n_tokens_mistral': 827, 'n_tokens_neox': 696, 'n_words': 153}