微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

redis.clients.jedis.exceptions.JedisConnectionException:无法连接到主机localhost:6379

如何解决redis.clients.jedis.exceptions.JedisConnectionException:无法连接到主机localhost:6379

我已经插入连接代码,并使用websocket将redis的数据输入到Web服务器代码中,并且出现诸如标题之类的错误,我正在做一个聊天应用程序,现在该如何解决?,谢谢

@ServerEndpoint(value =“ / chatRoomServer”) 公共类ChatRoomServerEndpoint {

static Set<Session> users = Collections.synchronizedSet(new HashSet<>());

@Onopen
public void handleOpen(Session session) {
    users.add(session);
}

@OnMessage
public void handleMessage(String message,Session userSession) throws IOException {
    System.out.println("tien");
    String username = (String) userSession.getUserProperties().get("username");
     Jedis jedis = new Jedis("localhost"); 
      System.out.println("Connection to server sucessfully"); 
    
      System.out.println("Server is running: "+jedis.ping()); 
      List<String> list = jedis.lrange("tutorial-list",5); 
      for(int i = 0; i<list.size(); i++) { 
          System.out.println("List of stored keys:: "+list.get(i)); 
          
      }
    
    if (username == null) {
        userSession.getUserProperties().put("username",message);
        userSession.getBasicRemote().sendText("System: you are connectd as " + message);
    } else {
        for (Session session : users) {
            session.getBasicRemote().sendText(username + ": " + message);
        }
    }
    
}

@OnClose
public void handleClose(Session session) {
    users.remove(session);
}

@OnError
public void handleError(Throwable t) {
    t.printstacktrace();
}

}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。