We first place the redis.properties under our own project, which reads as follows:
#redis地址server =192.168.0.8#redis Port port=6379auth=adminmax_active=600max_idle=300# maximum wait time max_wait=1000# timeout timeout= 3000test_on_borrow=true
Then we write a test class, test the Redis, we want to test the object write, read, then we first write a simple user class.
1 Packagecom.redis.test;2 3 Importjava.io.Serializable;4 5 /**6 * @author[email protected]7 * @version1.08 *9 */Ten Public classUserImplementsSerializable { One PrivateString name; A Private intAge ; - - PublicUser (String name,intAge ) { the Super(); - This. Name =name; - This. Age =Age ; - } + - PublicString GetName () { + returnname; A } at - Public intGetage () { - returnAge ; - } - - Public voidsetName (String name) { in This. Name =name; - } to + Public voidSetage (intAge ) { - This. Age =Age ; the } * $}
We write our Redis test class, and I've already written the SDK, which contains code that serializes the deserialized object.
1 Packagecom.redis.test;2 3 ImportCom.redissdk.redis.RedisUtil;4 5 /**6 * @author[email protected]7 * @version1.08 *9 */Ten Public classTestredis { One Public Static voidMain (string[] args) { A -Redisutil.setstring ("Redis key", "Redis HelloWorld", redisutil.exrp_day); -System.out.println (redisutil.getstring ("Redis key")); the -User User =NewUser ("Zhang San", 23); - System.out.println (Redisutil -. SetObject ("User", user, redisutil.exrp_day)); + System.out.println (Redisutil -. SetObject ("User2", user, redisutil.exrp_day)); +User User1 = Redisutil.getobject ("User", user.class); ASystem.out.println ("Name:" + user1.getname () + "Age:" +user1.getage ()); at -System.out.println (Redisutil.getkeys ("*")); - //Redisutil.getjedis () Other unpackaged methods need to invoke the original object method Operation - } -}
We run to see the results:
Ok,redis Java environment In this configuration is complete, the SDK only implemented string and object of the increase, delete, check. Set map and so on also need to call [Redisutil.getjedis ()], get Jedis object method directly access.
SOURCE download
Redis High Performance Client-REDISSDK