<commit_before>package ratelimiter

import (
	"bytes"
	"encoding/gob"
	"github.com/bradfitz/gomemcache/memcache"
)

type Memcache struct {
	mc        *memcache.Client
	keyprefix string
}

func NewMemcache(servers string, cacheKeyPrefix string) *Memcache {
	m := new(Memcache)
	m.mc = memcache.New(servers)

	m.keyprefix = cacheKeyPrefix

	return m
}

func (m *Memcache) GetBucketFor(key string) (*LeakyBucket, error) {

	item, err := m.mc.Get(m.keyprefix + key)
	if err != nil {
		return nil, err
	}

	var bucketser LeakyBucketSer
	buf := bytes.NewBuffer(item.Value)
	d := gob.NewDecoder(buf)

	err = d.Decode(&bucketser)
	if err != nil {
		return nil, err
	}

	bucket := bucketser.DeSerialise()<commit_msg>Gomemcache accepts an array of memcached servers<commit_after>package ratelimiter

import (
	"bytes"
	"encoding/gob"
	"github.com/bradfitz/gomemcache/memcache"
)

type Memcache struct {
	mc        *memcache.Client
	keyprefix string
}

func NewMemcache(servers []string, cacheKeyPrefix string) *Memcache {
	m := new(Memcache)
	m.mc = memcache.New(servers...)

	m.keyprefix = cacheKeyPrefix

	return m
}

func (m *Memcache) GetBucketFor(key string) (*LeakyBucket, error) {

	item, err := m.mc.Get(m.keyprefix + key)
	if err != nil {
		return nil, err
	}

	var bucketser LeakyBucketSer
	buf := bytes.NewBuffer(item.Value)
	d := gob.NewDecoder(buf)

	err = d.Decode(&bucketser)
	if err != nil {
		return nil, err
	}

	bucket := bucketser.DeSerialise()
{'fraction_non_alphanumeric': 0.12310866574965612, 'fraction_numerical': 0.0, 'mean_word_length': 4.052083333333333, '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': '3792688', 'n_tokens_mistral': 554, 'n_tokens_neox': 539, 'n_words': 127}