redis高性能客戶端 - redissdk

咱們首先在咱們本身的工程下放置redis.properties,內容以下:java

#redis地址
server=192.168.0.8
#redis端口
port=6379
auth=admin
max_active=600
max_idle=300
#最大等待時間
max_wait=1000
#超時
timeout=3000
test_on_borrow=true

 而後咱們寫一個測試類,測試下redis,咱們要測試對象寫入,讀取,那麼咱們先寫一個簡單的User類。redis

 1 package com.redis.test;
 2 
 3 import java.io.Serializable;
 4 
 5 /**
 6  * @author luwenbin006@163.com
 7  * @version 1.0
 8  *
 9  */
10 public class User implements Serializable {
11     private String name;
12     private int age;
13 
14     public User(String name, int age) {
15         super();
16         this.name = name;
17         this.age = age;
18     }
19 
20     public String getName() {
21         return name;
22     }
23 
24     public int getAge() {
25         return age;
26     }
27 
28     public void setName(String name) {
29         this.name = name;
30     }
31 
32     public void setAge(int age) {
33         this.age = age;
34     }
35 
36 }

咱們寫咱們的redis測試類,我已經寫好了sdk,裏面包含序列化反序列化對象等代碼。測試

 1 package com.redis.test;
 2 
 3 import com.redissdk.redis.RedisUtil;
 4 
 5 /**
 6  * @author luwenbin006@163.com
 7  * @version 1.0
 8  *
 9  */
10 public class TestRedis {
11     public static void main(String[] args) {
12 
13         RedisUtil.setString("redis key", "redis helloworld", RedisUtil.EXRP_DAY);
14         System.out.println(RedisUtil.getString("redis key"));
15 
16         User user = new User("張三", 23);
17         System.out.println(RedisUtil
18                 .setObject("user", user, RedisUtil.EXRP_DAY));
19         System.out.println(RedisUtil
20                 .setObject("user2", user, RedisUtil.EXRP_DAY));
21         User user1 = RedisUtil.getObject("user", User.class);
22         System.out.println("姓名:" + user1.getName() + "  年齡:" + user1.getAge());
23 
24         System.out.println(RedisUtil.getKeys("*"));
25         // RedisUtil.getJedis() 其餘未封裝方法須要調用原對象方法操做
26     }
27 }

咱們運行看看結果:this

 

ok,redis java環境就這樣配置完畢了,sdk中只實現了string和對象的增,刪,查。set map等還須要這樣調用[RedisUtil.getJedis()],拿到Jedis對象方法直接存取。spa

源碼下載code

相關文章
相關標籤/搜索