TestRedisController.java 1.49 KB
package com.yoho.search.restapi.tools;

import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yoho.search.cache.impls.SearchRedis;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.BitSet;
import java.util.HashMap;
import java.util.Map;

@Controller
public class TestRedisController {

    @Autowired
    private SearchRedis searchRedis;

    @RequestMapping(value = "/testRedis/bitset")
    @ResponseBody
    public Map<String, Object> testBitset() {
        long begin = System.currentTimeMillis();
        for (int i = 0; i < 10000; i++) {
            BitSet bitSet = new BitSet(100000);
            for (int j = 0; j < 10000; j++) {
                bitSet.set(j);
            }
            bitSet.set(100000);
            RedisKeyBuilder redisKeyBuilder = new RedisKeyBuilder();
            redisKeyBuilder.appendFixed("RedisBitSet:").appendVar(System.currentTimeMillis());
            redisKeyBuilder.appendFixed(":").appendVar((int) (Math.random() * 1000));
            searchRedis.setBitSet(redisKeyBuilder, bitSet, 100);
        }
        Map result = new HashMap<>();
        result.put("code", 200);
        result.put("messgae", "success");
        result.put("cost", System.currentTimeMillis() - begin);
        return result;
    }
}