Пример #1
0
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
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
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
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)
	}
}