예제 #1
0
파일: example_test.go 프로젝트: arvinkx/too
func ExampleEngine() {
	te, err := too.New("redis://localhost", "movies")
	if err != nil {
		log.Fatal(err)
	}

	te.Likes.Add("Sonic", "The Shawshank Redemption")
	te.Likes.Add("Sonic", "The Godfather")
	te.Likes.Add("Sonic", "The Dark Knight")
	te.Likes.Add("Sonic", "Pulp Fiction")

	te.Likes.Add("Mario", "The Godfather")
	te.Likes.Add("Mario", "The Dark Knight")
	te.Likes.Add("Mario", "The Shawshank Redemption")
	te.Likes.Add("Mario", "The Prestige")
	te.Likes.Add("Mario", "The Matrix")

	te.Likes.Add("Peach", "The Godfather")
	te.Likes.Add("Peach", "Inception")
	te.Likes.Add("Peach", "Fight Club")
	te.Likes.Add("Peach", "WALL·E")
	te.Likes.Add("Peach", "Princess Mononoke")

	te.Likes.Add("Luigi", "The Prestige")
	te.Likes.Add("Luigi", "The Dark Knight")

	items, _ := te.Suggestions.For("Luigi", 2)
	for _, item := range items {
		fmt.Println(item)
	}

	// Output:
	// The Shawshank Redemption
	// The Matrix
}
예제 #2
0
파일: example_test.go 프로젝트: hjr265/too
func BenchmarkNoBatch(b *testing.B) {
	te, err := too.New("redis://localhost", "movies")
	if err != nil {
		log.Fatal(err)
	}

	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		te.Likes.Add("Sonic", "The Shawshank Redemption")
		te.Likes.Add("Sonic", "The Godfather")
		te.Likes.Add("Sonic", "The Dark Knight")
		te.Likes.Add("Sonic", "Pulp Fiction")

		te.Likes.Add("Mario", "The Godfather")
		te.Likes.Add("Mario", "The Dark Knight")
		te.Likes.Add("Mario", "The Shawshank Redemption")
		te.Likes.Add("Mario", "The Prestige")
		te.Likes.Add("Mario", "The Matrix")

		te.Likes.Add("Peach", "The Godfather")
		te.Likes.Add("Peach", "Inception")
		te.Likes.Add("Peach", "Fight Club")
		te.Likes.Add("Peach", "WALL·E")
		te.Likes.Add("Peach", "Princess Mononoke")
	}
}
예제 #3
0
파일: example_test.go 프로젝트: hjr265/too
func ExampleBatch() {
	te, err := too.New("redis://localhost", "movies")
	if err != nil {
		log.Fatal(err)
	}

	err = te.Likes.Batch([]too.BatchRaterOp{
		{
			User: "******",
			Items: []too.Item{
				"The Shawshank Redemption",
				"The Godfather",
				"The Dark Knight",
				"Pulp Fiction",
			},
		},
		{
			User: "******",
			Items: []too.Item{
				"The Godfather",
				"The Dark Knight",
				"The Shawshank Redemption",
				"The Prestige",
				"The Matrix",
			},
		},
		{
			User: "******",
			Items: []too.Item{
				"The Godfather",
				"Inception",
				"Fight Club",
				"WALL·E",
				"Princess Mononoke",
			},
		}, {
			User: "******",
			Items: []too.Item{
				"The Prestige",
				"The Dark Knight",
			},
		},
	}, true)

	if err != nil {
		log.Fatal(err)
	}

	items, _ := te.Suggestions.For("Luigi", 2)
	for _, item := range items {
		fmt.Println(item)
	}

	// Output:
	// The Shawshank Redemption
	// The Matrix
}
예제 #4
0
func NewClient() Client {

	redisAddr, _ := net.ResolveTCPAddr("tcp", ":6379")
	conn, err := too.New(redisAddr, "tvshows")

	if err != nil {
		log.Fatal(err)
	}

	client := Client{make(chan Like), make(chan too.User), make(chan bool), conn}
	go client.run()
	return client
}
예제 #5
0
파일: example_test.go 프로젝트: hjr265/too
func BenchmarkUsingBatchWithAutoUpdate(b *testing.B) {
	te, err := too.New("redis://localhost", "movies")
	if err != nil {
		log.Fatal(err)
	}

	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		te.Likes.Batch([]too.BatchRaterOp{
			{
				User: "******",
				Items: []too.Item{
					"The Shawshank Redemption",
					"The Godfather",
					"The Dark Knight",
					"Pulp Fiction",
				},
			},
			{
				User: "******",
				Items: []too.Item{
					"The Godfather",
					"The Dark Knight",
					"The Shawshank Redemption",
					"The Prestige",
					"The Matrix",
				},
			},
			{
				User: "******",
				Items: []too.Item{
					"The Godfather",
					"Inception",
					"Fight Club",
					"WALL·E",
					"Princess Mononoke",
				},
			},
		}, true)
	}
}