发表于: 2017-11-09 18:38:55

1 749


今日完成:

成功使用redis。

明日计划:

整理完善代码,在服务器跑通后提交任务。

遇到的困难:

在对整个东西没有一点概念时复制教程代码都没用,然后看了一个没有用spring集成的例子之后解决的问题后再看解决集成的就简单很多,因为集成时问题难定位,以下是我的操作redis的代码

public class RedisDao {
private static String ADDR = "localhost";
   private static int PORT = 6379;
   //访问密码,若你的redis服务器没有设置密码,就不需要用密码去连接
   //private static String AUTH = "123456";
   private static int MAX_TOTAL = 512;
   private static int MAX_IDLE = 50;
   private static int MAX_WAIT = 10000;
   private static int TIMEOUT = 10000;
   private static boolean TEST_ON_BORROW = true;

   private static JedisPool jedisPool = null;
   
   static {
try {
JedisPoolConfig config = new JedisPoolConfig();
           config.setMaxTotal(MAX_TOTAL);
           config.setMaxIdle(MAX_IDLE);
           config.setMaxWaitMillis(MAX_WAIT);
           config.setTestOnBorrow(TEST_ON_BORROW);
           jedisPool = new JedisPool(config, ADDR, PORT, TIMEOUT);
       } catch (Exception e) {
e.printStackTrace();
       }
}

public synchronized static Jedis getJedis() {
try {
if (jedisPool != null) {
Jedis jedis = jedisPool.getResource();
               return jedis;
           } else {
return null;
           }
} catch (Exception e) {
e.printStackTrace();
           return null;
       }
}

以下是控制器调用的代码,不需要实例化,直接调用方法操作redis。

try {
if(RedisDao.getJedis().get("id"+id)!=null){
System.out.println("redis返回");
       return RedisDao.getJedis().get("id"+id);
   }
}catch (Exception e){}
RedisDao.getJedis().set("id"+id,servicesDao.takePerById(id).toString());
System.out.println("redis无数据,已插入");
return RedisDao.getJedis().get("id"+id);

集成的话在网上一搜就有模板,然后修改自己的参数就好了。

最大的问题就是不知道为什么做了一天都都是报错,而做了个类的然后去问问师兄后,回来五分钟就完成了集成,那个教程早上就看过,但是没做成功,磨了一天重新看就做好了,玄学。

进度:

任务六

任务开始时间:2017.11.05

预计demo时间:2017.11.10

是否有延期风险:

能提交,过不过就不知道了。

禅道:http://task.ptteng.com/zentao/my-task.htm



返回列表 返回列表
评论

    分享到