<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                [TOC] # 測試是否能ping通 ~~~ //創建一個jedis客戶端對象(redis的客戶端連接) Jedis jedis = new Jedis("127.0.0.1",6379); //設置auth密碼 jedis.auth("root"); //測試服務器是否連通 String ping = jedis.ping(); System.out.println(ping); ~~~ # 命令行 ![](https://box.kancloud.cn/e05330b96f10ef19923070a970fd9c17_479x457.png) # string操作 ~~~ public Jedis init() { //創建一個jedis客戶端對象(redis的客戶端連接) Jedis jedis = new Jedis("127.0.0.1",6379); //設置auth密碼 jedis.auth("root"); return jedis; } @Test public void testString() { Jedis jedis = this.init(); jedis.set("user02:name", "jdxia"); jedis.set("user03:name","xjd"); String u02 = jedis.get("user02:name"); String u03 = jedis.get("user03:name"); System.out.println(u02); System.out.println(u03); } ~~~ # 存個對象 ## 對象序列化 ~~~ @Test public void testObjectCache() throws IOException, ClassNotFoundException { Jedis jedis = this.init(); ProductInfo productInfo = new ProductInfo(); productInfo.setName("jdxia"); productInfo.setCatelog("大數據"); productInfo.setPrice(20.0); //將對象序列化成字節數組,這個productInfo對象需要implements Serializable //字節數組流 ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); //對象序列化流 ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream); //用對象的序列化流將productInfo對象序列化,然后把序列化之后的二進制數據寫到byteArrayOutputStream流中 objectOutputStream.writeObject(productInfo); //將byteArrayOutputStream流轉為byte數組 byte[] bytes = byteArrayOutputStream.toByteArray(); //將對象序列化之后的byte數組存到redis的string中 jedis.set("product:01".getBytes(),bytes); //根據key從redis中取出對象的byte數據 byte[] pBytesResp = jedis.get("product:01".getBytes()); //將byte數據反序列出對象 ByteArrayInputStream bi = new ByteArrayInputStream(pBytesResp); ObjectInputStream oi = new ObjectInputStream(bi); //從對象讀取流中讀取出p對象 ProductInfo productInfo1= (ProductInfo) oi.readObject(); System.out.println(productInfo1); } ~~~ ## 對象轉Gson ~~~ //對象轉Gson @Test public void testObjectToJsonCache() { Jedis jedis = this.init(); ProductInfo productInfo = new ProductInfo(); productInfo.setName("jdxia"); productInfo.setCatelog("大數據---人工智能"); productInfo.setPrice(30.0); //利用gson將對象轉成json串 Gson gson = new Gson(); String pJson = gson.toJson(productInfo); //將json串存入redis jedis.set("product:02",pJson); //從redis中取出對象的json串 String pJsonResp = jedis.get("product:02"); //將返回的json解析成對象 ProductInfo pResponse = gson.fromJson(pJson, ProductInfo.class); System.out.println(pResponse); } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看