目前只用了單機版的jedis,集群搭建成功,但接口測試有問題
1.和jedis服務連接
public class RedisUtil { private static String JEDIS_SERVER="10.0.0.18"; private static int JEDIS_PORT=6379; protected Jedis jedis = new Jedis(JEDIS_SERVER, JEDIS_PORT); }
private static String SERVER_KEY="server";
public class ServerDaoImpl extends RedisUtil implements IServerDao{ private static String SERVER_KEY="server"; @Override public void saveOrUpdateServer(Server server) { String key = SERVER_KEY + ":" + server.getIp() ; String value = JsonUtils.object2json(server); jedis.set(key, value); } @Override public void deleteServer(String ip) { String key =SERVER_KEY+":" +ip; jedis.del(key); } @Override public Server getServer(String ip) { String key =SERVER_KEY+":" +ip; Server server = (Server)JSONObject.toBean(JSONObject.fromObject(jedis.get(key)),Server.class); return server; } @Override public ListgetAllServer() { List servers = new ArrayList (); String key =SERVER_KEY+"*"; Set set =jedis.keys(key); for(String s:set){ System.out.println(jedis.get(s)); Server server = (Server)JSONObject.toBean(JSONObject.fromObject(jedis.get(s)),Server.class); servers.add(server); } return servers; } }