Java Redis Tool Class

Source: Internet
Author: User

1  PackageCom.mohecun.jedis;2 3  Public Interfacejedisclient {4 5 string Set (String key, String value);6 string Get (string key);7 Boolean exists (String key);8Long expire (String key,intseconds);9 A Long ttl (String key);Ten Long incr (String key); One Long Hset (String key, String field, String value); A string Hget (String key, string field); - Long Hdel (string key, String ... field); -}

Clusterclient:

1  PackageCom.mohecun.jedis;2 3 Importorg.springframework.beans.factory.annotation.Autowired;4 5 ImportRedis.clients.jedis.JedisCluster;6 7  Public classJedisclientclusterImplementsjedisclient {8     9 @AutowiredTen     PrivateJediscluster Jediscluster; One  A @Override -      Publicstring Set (String key, String value) { -         returnJediscluster.set (key, value); the     } -  - @Override -      Publicstring Get (String key) { +         returnJediscluster.get (key); -     } +  A @Override at      PublicBoolean exists (String key) { -         returnjediscluster.exists (key); -     } -  - @Override -      PublicLong expire (String key,intseconds) { in         returnJediscluster.expire (key, seconds); -     } to  + @Override -      PublicLong TTL (String key) { the         returnJediscluster.ttl (key); *     } $ Panax Notoginseng @Override -      PublicLong incr (String key) { the         returnJEDISCLUSTER.INCR (key); +     } A  the @Override +      PublicLong Hset (String key, String field, String value) { -         returnJediscluster.hset (Key, field, value); $     } $  - @Override -      Publicstring Hget (String key, String field) { the         returnJediscluster.hget (key, field); -     }Wuyi  the @Override -      PublicLong Hdel (string key, String ... field) { Wu         returnJediscluster.hdel (key, field); -     } About  $}

Clientpool:

1  PackageCom.mohecun.jedis;2 3 Importorg.springframework.beans.factory.annotation.Autowired;4 5 ImportRedis.clients.jedis.Jedis;6 ImportRedis.clients.jedis.JedisPool;7 8  Public classJedisclientpoolImplementsjedisclient {9     Ten @Autowired One     PrivateJedispool Jedispool; A  - @Override -      Publicstring Set (String key, String value) { theJedis Jedis =Jedispool.getresource (); -String result =Jedis.set (key, value); - jedis.close (); -         returnresult; +     } -  + @Override A      Publicstring Get (String key) { atJedis Jedis =Jedispool.getresource (); -String result =Jedis.get (key); - jedis.close (); -         returnresult; -     } -  in @Override -      PublicBoolean exists (String key) { toJedis Jedis =Jedispool.getresource (); +Boolean result =jedis.exists (key); - jedis.close (); the         returnresult; *     } $ Panax Notoginseng @Override -      PublicLong expire (String key,intseconds) { theJedis Jedis =Jedispool.getresource (); +Long result =Jedis.expire (key, seconds); A jedis.close (); the         returnresult; +     } -  $ @Override $      PublicLong TTL (String key) { -Jedis Jedis =Jedispool.getresource (); -Long result =Jedis.ttl (key); the jedis.close (); -         returnresult;Wuyi     } the  - @Override Wu      PublicLong incr (String key) { -Jedis Jedis =Jedispool.getresource (); AboutLong result =JEDIS.INCR (key); $ jedis.close (); -         returnresult; -     } -  A @Override +      PublicLong Hset (String key, String field, String value) { theJedis Jedis =Jedispool.getresource (); -Long result =Jedis.hset (Key, field, value); $ jedis.close (); the         returnresult; the     } the  the @Override -      Publicstring Hget (String key, String field) { inJedis Jedis =Jedispool.getresource (); theString result =Jedis.hget (key, field); the jedis.close (); About         returnresult; the     } the  the @Override +      PublicLong Hdel (string key, String ... field) { -Jedis Jedis =Jedispool.getresource (); theLong result =Jedis.hdel (key, field);Bayi jedis.close (); the         returnresult; the     } -  -}

Java Redis Tool Class

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.