package cn.reghao.tnb.content.app.vod.service;

import cn.reghao.tnb.content.app.ContentApplication;
import cn.reghao.tnb.content.app.util.redis.ds.RedisHash;
import cn.reghao.tnb.content.app.util.redis.ds.RedisList;
import cn.reghao.tnb.content.app.util.redis.ds.RedisString;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.*;

/**
 * @author reghao
 * @date 2023-04-24 03:32:04
 */
@Slf4j
@ActiveProfiles("dev")
@SpringBootTest(classes = ContentApplication.class)
public class RcmdTest {
    @Autowired
    RecommendService recommendService;

    @Test
    public void test() {
        long loginUser = 10001;
        //recommendService.putRecommendVideos(loginUser);
    }

    @Autowired
    RedisString redisString;
    @Autowired
    RedisList redisList;
    @Test
    public void redisTest() {
        String keyPrefix = "content:rcmd";
        long userId = 11011;
        while (userId < 12000L) {
            String key = String.format("%s:%s", keyPrefix, userId);
            redisString.set(key, "hahahah");

            userId++;
        }

        String key = String.format("%s:%s", keyPrefix, userId);
        String value = redisString.get(key);
        if (value != null) {
            log.info("value -> {}", value);
        }
    }

    @Autowired
    RedisHash<String> redisHash;
    @Test
    public void cartTest() {
        long userId = 11011;
        String key = String.format("cart:%s", userId);

        long itemId = 1110110L;
        while (itemId < 1110130) {
            redisHash.hset(key, String.valueOf(itemId), 1+"");
            itemId++;
        }

        String itemIdStr = String.valueOf(itemId);
        redisHash.hset(key, itemIdStr, 1+"");
        redisHash.hincrby(key, itemIdStr, 1);
        Long total = redisHash.hlen(key);
        Map<String, String> items = redisHash.hgetall(key);
        System.out.println();
        //redisHash.hdel(key1, itemId);
    }
}
