package com.elab.redis.spring;

import com.elab.redis.CacheTemplate;
import com.elab.redis.RedisSpringBoot;
import org.junit.Test;
import org.redisson.api.RLock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * springData
 *
 * @author ： liukx
 * @time ： 2020/7/15 - 11:12
 */
public class SpringDataTest extends RedisSpringBoot {

    @Autowired
    private CacheTemplate cacheTemplate;

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Test
    public void set() throws IOException {

        cacheTemplate.set().add("aaa","a","b","c");


        RLock xxx = cacheTemplate.getRedissonClient().getLock("xxx");
        cacheTemplate.string().set("abc", "cccc");
        Object abc = cacheTemplate.string().get("abc");
        System.out.println("--->" + abc);

        redisTemplate.opsForValue().set("kkx", "abc");

        Map<String, String> map = new HashMap<>();
        map.put("lkx", "xxx");
        map.put("xxx", "sss");
        redisTemplate.opsForValue().set("obj", map);
        Map<String, String> xiong = (Map<String, String>) redisTemplate.opsForValue().get("obj");
        System.out.println(xiong);
        System.in.read();

    }
}
