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