jedis簡單使用,jedis

來源:互聯網
上載者:User

jedis簡單使用,jedis

目前只用了單機版的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);}

2.實現簡單的增刪改查,其中key為表名+索引,value為對象的json串

private static String SERVER_KEY="server";
public class ServerDaoImpl  extends RedisUtil implements IServerDao{private static String SERVER_KEY="server";@Overridepublic void saveOrUpdateServer(Server server) {String key = SERVER_KEY + ":" + server.getIp() ;String value = JsonUtils.object2json(server);jedis.set(key, value);}@Overridepublic void deleteServer(String ip) {String key =SERVER_KEY+":" +ip;jedis.del(key);}@Overridepublic Server getServer(String ip) {String key =SERVER_KEY+":" +ip;Server server = (Server)JSONObject.toBean(JSONObject.fromObject(jedis.get(key)),Server.class);return server;}@Overridepublic List<Server> getAllServer() {List<Server> servers = new ArrayList<Server>();String key =SERVER_KEY+"*";Set<String> 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; }}


著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.