Java代碼redis基礎操作

來源:互聯網
上載者:User

標籤:common   turn   pack   redis   source   pac   print   pre   style   

maven依賴包:

 1         <dependency> 2             <groupId>redis.clients</groupId> 3             <artifactId>jedis</artifactId> 4             <version>2.9.0</version> 5         </dependency> 6         <dependency> 7             <groupId>org.apache.commons</groupId> 8             <artifactId>commons-pool2</artifactId> 9             <version>2.6.0</version>10         </dependency>

 

源碼:

 1 package StudyPro.base; 2  3 import org.junit.Test; 4 import redis.clients.jedis.Jedis; 5 import redis.clients.jedis.JedisPool; 6 import redis.clients.jedis.JedisPoolConfig; 7  8 public class TestSample { 9 //    Jedis jedis = new Jedis("10.15.1.19",16379);10 11     // 簡單串連12     @Test13     public void test() {14         Jedis jedis = new Jedis("10.15.1.19", 16379);15         jedis.auth("wC3Xo8E5mlmgMb");16         jedis.set("a", "bb");17         System.out.println(jedis.get("a"));18         jedis.close();19     }20 21     // 使用串連池22     @Test23     public void testPool() {24         JedisPoolConfig poolConfig = new JedisPoolConfig();25         poolConfig.setMaxIdle(20);26         poolConfig.setMinIdle(10);27         poolConfig.setMaxTotal(30);28         poolConfig.setMaxWaitMillis(3000);29         poolConfig.setTestOnBorrow(true);30         poolConfig.setTestOnReturn(true);31         JedisPool jedisPool = new JedisPool("10.15.1.19", 16379);32         Jedis jedis = jedisPool.getResource();33         jedis.auth("wC3Xo8E5mlmgMb");34         System.out.println(jedis.get("a"));35         jedis.close();36         jedisPool.close();37     }38 39 }

 

Java代碼redis基礎操作

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.