<commit_before>// Copyright 2014 Wandoujia Inc. All Rights Reserved.
// Licensed under the MIT (MIT-LICENSE.txt) license.

package redispool

import (
	"bufio"
	"net"
)

//not thread-safe
type Conn struct {
	addr string
	net.Conn
	closed bool
	r      *bufio.Reader
}

func (c *Conn) Close() {
	c.Conn.Close()
	c.closed = true
}

func (c *Conn) IsClosed() bool {
	return c.closed
}

type PooledConn struct {
	*Conn
	pool *ConnectionPool
}

func (pc *PooledConn) Recycle() {
	if pc.IsClosed() {
		pc.pool.Put(nil)
	} else {
		pc.pool.Put(pc)
	}
}

//requre read to use bufio
func (pc *PooledConn) Read(p []byte) (int, error) {
	panic("not allowed")
	return pc.r.Read(p)
}

func (pc *PooledConn) Write(p []byte) (int, error) {
	return pc.Conn.Write(p)
}

func (pc *PooledConn) BufioReader() *bufio.Reader {
	return pc.r
}

func NewConnection(addr string) (*Conn, error) {
	conn, err := net.Dial("tcp", addr)
	if err != nil {
		return nil, err
	}

	return &Conn{
		addr: addr,
		Conn: conn,
		r:    bufio.NewReaderSize(conn, 204800),
	}, nil
}

func ConnectionCreator(addr string) CreateConnectionFunc {
	return func(pool *ConnectionPool) (PoolConnection, error) {
		c, err := NewConnection(addr)
		if err != nil {
			return nil, err
		}
		return &PooledConn{c, pool}, nil
	}
}
<commit_msg>clean up<commit_after>// Copyright 2014 Wandoujia Inc. All Rights Reserved.
// Licensed under the MIT (MIT-LICENSE.txt) license.

package redispool

import (
	"bufio"
	"net"
)

//not thread-safe
type Conn struct {
	addr string
	net.Conn
	closed bool
	r      *bufio.Reader
}

func (c *Conn) Close() {
	c.Conn.Close()
	c.closed = true
}

func (c *Conn) IsClosed() bool {
	return c.closed
}

type PooledConn struct {
	*Conn
	pool *ConnectionPool
}

func (pc *PooledConn) Recycle() {
	if pc.IsClosed() {
		pc.pool.Put(nil)
	} else {
		pc.pool.Put(pc)
	}
}

//requre read to use bufio
func (pc *PooledConn) Read(p []byte) (int, error) {
	panic("not allowed")
}

func (pc *PooledConn) Write(p []byte) (int, error) {
	return pc.Conn.Write(p)
}

func (pc *PooledConn) BufioReader() *bufio.Reader {
	return pc.r
}

func NewConnection(addr string) (*Conn, error) {
	conn, err := net.Dial("tcp", addr)
	if err != nil {
		return nil, err
	}

	return &Conn{
		addr: addr,
		Conn: conn,
		r:    bufio.NewReaderSize(conn, 204800),
	}, nil
}

func ConnectionCreator(addr string) CreateConnectionFunc {
	return func(pool *ConnectionPool) (PoolConnection, error) {
		c, err := NewConnection(addr)
		if err != nil {
			return nil, err
		}
		return &PooledConn{c, pool}, nil
	}
}

{'fraction_non_alphanumeric': 0.14454045561665357, 'fraction_numerical': 0.007855459544383346, 'mean_word_length': 3.5727109515260325, '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': '4863589', 'n_tokens_mistral': 1035, 'n_tokens_neox': 984, 'n_words': 277}