/** * 判断两个node对象中host和port是否相等 * * @author ningyu * @date 2013-1-26 下午3:46:50 * @param anObject * @return * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals(Object anObject) { if (this == anObject) { return true; } if (anObject instanceof Node) { Node node = (Node) anObject; if (this.getHost().equals(node.getHost()) && (this.getPort() == node.getPort())) { return true; } } return false; }
/** * 执行redis ping操作 * * @author ningyu * @date 2013-1-26 下午3:51:07 * @param node * @return * @see */ public static boolean pingNode(Node node) { Jedis j = null; try { j = new Jedis(node.getHost(), node.getPort()); String re = j.ping(); return re.equals("PONG"); } catch (Exception e) { return false; } finally { if (j != null) { j.disconnect(); } } }
/** * 返回json字符串 * * @author ningyu * @date 2013-1-26 下午3:47:45 * @param node * @return * @see */ private static String passJson(Node node) { StringBuilder sb = new StringBuilder(); if (node != null) { sb.append("{"); sb.append("host:" + node.getHost()).append(", "); sb.append("port:" + node.getPort()).append(", "); sb.append("password:"******", "); sb.append("weight:" + node.getWeight()).append(", "); sb.append("name:" + node.getName()).append(", "); sb.append("timeout:" + node.getTimeout()); sb.append("}"); node = node.getNext(); if (node != null) { sb.append(","); sb.append(passJson(node)); } } return sb.toString(); }