func (rl *List) Trim(start, stop int64) error {
	conn := rl.pool.Get(rl.dbindex)
	_, err := conn.Do("LTRIM", rl.id, start, stop)
	return err
}
Trim an existing list so that it will contain only the specified range of
elements specified.
package simpleredis
import (
	"errors"
	"strconv"
	"strings"
	"time"
	"github.com/gomodule/redigo/redis"
)
const (
	Version = 2.6
	defaultRedisServer = ":6379"
)
type redisDatastructure struct {
	pool    *ConnectionPool
	id      string
	dbindex int
}
type (
	ConnectionPool redis.Pool
	List     redisDatastructure
	Set      redisDatastructure
	HashMap  redisDatastructure
	KeyValue redisDatastructure
)
var (
	connectTimeout = 7 * time.Second
	readTimeout    = 7 * time.Second
	writeTimeout   = 7 * time.Second
	idleTimeout    = 240 * time.Second
	maxIdleConnections = 3
)
func newRedisConnection() (redis.Conn, error) {
	return newRedisConnectionTo(defaultRedisServer)
}
func newRedisConnectionTo(hostColonPort string) (redis.Conn, error) {
	if _, theRest, ok := twoFields(hostColonPort, "@"); ok {
		hostColonPort = theRest
	}
	hostColonPort = strings.TrimSpace(hostColonPort)
	c, err := redis.Dial("tcp", hostColonPort, redis.DialConnectTimeout(connectTimeout), redis.DialReadTimeout(readTimeout), redis.DialWriteTimeout(writeTimeout))
	if err != nil {
		if c != nil {
			c.Close()
		}
		return nil, err
	}
	return c, nil
}
func getString(bi []interface{}, i int) string {
	return string(bi[i].([]uint8))
}
func TestConnection() (err error) {
	return TestConnectionHost(defaultRedisServer)
}
func TestConnectionHost(hostColonPort string) (err error) {
	conn, err := newRedisConnectionTo(hostColonPort)
	defer func() {
		if conn != nil {
			conn.Close()
		}
		if r := recover(); r != nil {
			err = errors.New("Could not connect to redis server: " + hostColonPort)
		}
	}()
	return err
}
func NewConnectionPool() *ConnectionPool {
	redisPool := &redis.Pool{
		MaxIdle:     maxIdleConnections,
		IdleTimeout: idleTimeout,
		Dial:        newRedisConnection,
	}
	pool := ConnectionPool(*redisPool)
	return &pool
}
func twoFields(s, delim string) (string, string, bool) {
	if strings.Count(s, delim) != 1 {
		return s, "", false
	}
	fields := strings.Split(s, delim)
	return fields[0], fields[1], true
}
func NewConnectionPoolHost(hostColonPort string) *ConnectionPool {
	redisPool := &redis.Pool{
		MaxIdle:     maxIdleConnections,
		IdleTimeout: idleTimeout,
		Dial: func() (redis.Conn, error) {
			conn, err := newRedisConnectionTo(hostColonPort)
			if err != nil {
				return nil, err
			}
			if password, _, ok := twoFields(hostColonPort, "@"); ok {
				if password != "" {
					if _, err := conn.Do("AUTH", password); err != nil {
						conn.Close()
						return nil, err
					}
				}
			}
			return conn, err
		},
	}
	pool := ConnectionPool(*redisPool)
	return &pool
}
func SetMaxIdleConnections(maximum int) {
	maxIdleConnections = maximum
}
func (pool *ConnectionPool) Get(dbindex int) redis.Conn {
	redisPool := redis.Pool(*pool)
	conn := redisPool.Get()
	if dbindex != 0 {
		conn.Do("SELECT", strconv.Itoa(dbindex))
	}
	return conn
}
func (pool *ConnectionPool) Ping() error {
	redisPool := redis.Pool(*pool)
	conn := redisPool.Get()
	_, err := conn.Do("PING")
	return err
}
func (pool *ConnectionPool) Close() {
	redisPool := redis.Pool(*pool)
	redisPool.Close()
}
func NewList(pool *ConnectionPool, id string) *List {
	return &List{pool, id, 0}
}
func (rl *List) SelectDatabase(dbindex int) {
	rl.dbindex = dbindex
}
func (rl *List) Get(index int64) (string, error) {
	conn := rl.pool.Get(rl.dbindex)
	result, err := conn.Do("LINDEX", rl.id)
	if err != nil {
		panic(err)
	}
	return redis.String(result, err)
}
func (rl *List) Size() (int64, error) {
	conn := rl.pool.Get(rl.dbindex)
	size, err := conn.Do("LLEN", rl.id)
	if err != nil {
		panic(err)
	}
	return redis.Int64(size, err)
}
func (rl *List) PopFirst() (string, error) {
	conn := rl.pool.Get(rl.dbindex)
	result, err := conn.Do("LPOP", rl.id)
	if err != nil {
		panic(err)
	}
	return redis.String(result, err)
}
func (rl *List) PopLast() (string, error) {
	conn := rl.pool.Get(rl.dbindex)
	result, err := conn.Do("LPOP", rl.id)
	if err != nil {
		panic(err)
	}
	return redis.String(result, err)
}
func (rl *List) AddStart(value string) error {
	conn := rl.pool.Get(rl.dbindex)
	_, err := conn.Do("RPUSH", rl.id, value)
	return err
}
func (rl *List) AddEnd(value string) error {
	conn := rl.pool.Get(rl.dbindex)
	_, err := conn.Do("LPUSH", rl.id, value)
	return err
}
func (rl *List) Add(value string) error {
	return rl.AddStart(value)
}
func (rl *List) All() ([]string, error) {
	conn := rl.pool.Get(rl.dbindex)
	result, err := redis.Values(conn.Do("LRANGE", rl.id, "0", "-1"))
	strs := make([]string, len(result))
	for i := 0; i < len(result); i++ {
		strs[i] = getString(result, i)
	}
	return strs, err
}
func (rl *List) GetAll() ([]string, error) {
	return rl.All()
}
func (rl *List) Last() (string, error) {
	conn := rl.pool.Get(rl.dbindex)
	result, err := redis.Values(conn.Do("LRANGE", rl.id, "-1", "-1"))
	if len(result) == 1 {
		return getString(result, 0), err
	}
	return "", err
}
func (rl *List) GetLast() (string, error) {
	return rl.Last()
}
func (rl *List) LastN(n int) ([]string, error) {
	conn := rl.pool.Get(rl.dbindex)
	result, err := redis.Values(conn.Do("LRANGE", rl.id, "-"+strconv.Itoa(n), "-1"))
	strs := make([]string, len(result))
	for i := 0; i < len(result); i++ {
		strs[i] = getString(result, i)
	}
	return strs, err
}
func (rl *List) GetLastN(n int) ([]string, error) {
	return rl.LastN(n)
}
func (rl *List) RemoveElement(value string) error {
	conn := rl.pool.Get(rl.dbindex)
	_, err := conn.Do("LREM", rl.id, value)
	return err
}
func (rl *List) Set(index int64, value string) error {
	conn := rl.pool.Get(rl.dbindex)
	_, err := conn.Do("LSET", rl.id, index, value)
	return err
}