| | |
| | | package com.ks; |
| | | |
| | | import com.ks.goldcorn.GoldCornApplication; |
| | | import com.ks.goldcorn.exception.GoldTradeException; |
| | | import com.ks.goldcorn.util.JedisUtil; |
| | | import com.ks.lib.common.util.RedisUtil; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.springframework.boot.test.context.SpringBootTest; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.test.context.ContextConfiguration; |
| | | import redis.clients.jedis.Jedis; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.concurrent.TimeUnit; |
| | |
| | | @Resource |
| | | private RedisTemplate redisTemplate; |
| | | |
| | | @Resource |
| | | private JedisUtil jedisUtil; |
| | | |
| | | |
| | | @Test |
| | | public void getTime() throws InterruptedException { |
| | |
| | | redisTemplate.opsForValue().set(timeKey, "1", 2, TimeUnit.SECONDS); |
| | | long time1 = (redisTemplate.getExpire(timeKey)); |
| | | Thread.sleep(2000); |
| | | time1 = (redisTemplate.getExpire(timeKey)); |
| | | time1 = (redisTemplate.getExpire(timeKey)); |
| | | Thread.sleep(2000); |
| | | time1 = (redisTemplate.getExpire(timeKey)); |
| | | time1 = (redisTemplate.getExpire(timeKey)); |
| | | } |
| | | |
| | | |
| | | @Test |
| | | public void jedis() { |
| | | |
| | | try { |
| | | jedisUtil.excute(new JedisUtil.JedisExcuter() { |
| | | @Override |
| | | public void execute(Jedis jedis) throws Exception { |
| | | throw new GoldTradeException(1, "金币交易错误"); |
| | | } |
| | | }); |
| | | } catch (GoldTradeException e) { |
| | | System.out.println("交易错误:"+e.getMessage()); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | System.out.println("其他错误:" + e.getMessage()); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |