package com.tzld.piaoquan.recommend.server.framework.utils;


import com.google.common.base.Function;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.Tuple;

import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Service
public class RedisSmartClient {

    private final static ExecutorService executorService = Executors.newCachedThreadPool();
    @Qualifier("redisTemplate")
    @Autowired
    protected RedisTemplate<String, String> redisTemplate;


    public RedisSmartClient() {
    }
    public void set(final String key, final String value) {
        redisTemplate.opsForValue().set(key, value);
    }

    public String get(final String key) {
        return redisTemplate.opsForValue().get(key);
    }

    // hget
    public String hget(final String key, final String field) {
        return redisTemplate.opsForHash().get(key, field).toString();
    }


    // getRandomValueFromSet
    public List<String> getRandomList(final String key, long num) {
        return redisTemplate.opsForSet().randomMembers(key, num);
    }


    // hgetall
    public Map<Object, Object> hgetall(String key) {
        return redisTemplate.opsForHash().entries(key);
    }

    // TODO 异步写入redis 作为用户的分发历史
    public <T> T write(String key, String value) {
        T t = null;
        return t;
    }



}
