java redis 问题
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java redis 问题相关的知识,希望对你有一定的参考价值。
代码如下:
public String getInfo(String infoName)
try
Jedis jedis = jedisPool.getResource();
try
String key = infoName+":" + infoName;
byte[] bytes = jedis.get(key.getBytes());
if (bytes != null)
String info = schema.newMessage();
ProtostuffIOUtil.mergeFrom(bytes, info, schema);
return info;
finally
jedis.close();
catch (java.lang.Exception e)
logger.error(e.getMessage(), e);
return null;
public String putInfo(String infoName,String info)
try
Jedis jedis = jedisPool.getResource();
try
String key = infoName+":" + info;
byte[] bytes = ProtostuffIOUtil.toByteArray(info, schema, LinkedBuffer.allocate(LinkedBuffer.DEFAULT_BUFFER_SIZE));
int timeout = 60 * 60;
String result=jedis.setex(key.getBytes(), timeout, bytes);
return result;
finally
jedis.close();
catch (Exception e)
logger.error(e.getMessage(), e);
return null;
public long getTotalPage()
if (redisDao.getInfo("totalPage") == null)
long allBlogCount = blogDao.getCount();
System.out.println("allBlogCount..............:"+allBlogCount);
redisDao.putInfo("totalPage", (allBlogCount / 8 + 1) + "");
return allBlogCount / 8 + 1;
else
System.out.println("totalPage..............: "+redisDao.getInfo("totalPage"));
return Long.getLong(redisDao.getInfo("totalPage"));
@RequestMapping("/")
public String home(Model model)
List<Blog> blogs = blogServiceImpl.queryAll(0, 0);
model.addAttribute("blogs", blogs);
model.addAttribute("categorys",categoryServiceImpl.queryAll());
model.addAttribute("pageIndex", 1);
System.out.println(redisDao.getInfo("totalPage")+" controller totalPage ");
model.addAttribute("totalPage",blogServiceImpl.getTotalPage()); // redisDao.getInfo("totalPage") 这行出错
return "/home";
提示:
org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [seckill-dispatcher] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
java.lang.NullPointerException
以上是关于java redis 问题的主要内容,如果未能解决你的问题,请参考以下文章
java操作redis集群问题CLUSTERDOWN The cluster is down. Use CLUSTER INFO for more information