Пример #1
0
func TestDeadClient(t *testing.T) {
	server, client := redistest.NewServerClient(t)
	server.Close()
	cache := bytecache.New(client)
	const key = "key"
	_, err := cache.Get(key)
	if err == nil {
		t.Fatal("was expecting error")
	}
}
Пример #2
0
func TestGetMissing(t *testing.T) {
	server, client := redistest.NewServerClient(t)
	defer server.Close()
	cache := bytecache.New(client)
	const key = "key"
	actual, err := cache.Get(key)
	if err != nil {
		t.Fatal(err)
	}
	if actual != nil {
		t.Fatalf("found %s instead of nil", actual)
	}
}
Пример #3
0
func TestSetGet(t *testing.T) {
	server, client := redistest.NewServerClient(t)
	defer server.Close()
	cache := bytecache.New(client)
	const key = "key"
	expected := []byte("data")
	if err := cache.Store(key, expected, time.Second); err != nil {
		t.Fatal(err)
	}
	actual, err := cache.Get(key)
	if err != nil {
		t.Fatal(err)
	}
	if !bytes.Equal(actual, expected) {
		t.Fatalf("found %s instead of %s", actual, expected)
	}
}
Пример #4
0
func TestExpires(t *testing.T) {
	server, client := redistest.NewServerClient(t)
	defer server.Close()
	cache := bytecache.New(client)
	const key = "key"
	expected := []byte("data")
	if err := cache.Store(key, expected, time.Millisecond); err != nil {
		t.Fatal(err)
	}
	time.Sleep(3 * time.Millisecond)
	actual, err := cache.Get(key)
	if err != nil {
		t.Fatal(err)
	}
	if actual != nil {
		t.Fatalf("found %s instead of nil", actual)
	}
}
Пример #5
0
// Package service provides configured service instances.
package service

import (
	"github.com/daaku/go.redis"
	"github.com/daaku/go.redis/bytecache"
	"github.com/daaku/go.redis/bytestore"
	"github.com/daaku/go.static"
	"github.com/daaku/go.stats/stathatbackend"
)

var (
	Static    = static.HandlerFlag("rell.static")
	Stats     = stathatbackend.EZKeyFlag("rell.stats")
	Redis     = redis.ClientFlag("rell.redis")
	ByteCache = bytecache.New(Redis)
	ByteStore = bytestore.New(Redis)
)

func init() {
	Redis.Stats = Stats
}