Increment directive: INCR (Default starting from 0)
Decrement instruction: DECR (default starting from 0, decrement will appear negative, this is not the same as Memcache, MC to 0)
As follows:
Two implementations of Shardedjedispool and Jediscluster are attached:
Shardedjedispool:
@Override PublicLong decr (String key) {Shardedjedis Jedis=NULL; Long result= 0l; Try{Jedis=Shardedjedispool.getresource (); Result=JEDIS.DECR (key); } Catch(Exception e) {log.error ("Redis decr error and key =" +key, E); } returnresult; } @Override PublicLong incr (String key) {Shardedjedis Jedis=NULL; Long result= 0l; Try{Jedis=Shardedjedispool.getresource (); Result=JEDIS.INCR (key); } Catch(Exception e) {log.error ("Redis incr error and key =" +key, E); } returnresult; }
Jediscluster:
@Override Publiclong DECR (String key) {Long result= 0l; Try{result=JEDISCLUSTER.DECR (key); } Catch(Exception e) {log.error ("Jediscluster decr error and key =" +key, E); } returnresult; } @Override Publiclong incr (String key) {Long result= 0l; Try{result=JEDISCLUSTER.INCR (key); } Catch(Exception e) {log.error ("Jediscluster incr error and key =" +key, E); } returnresult; }
Applicable scenarios:
High concurrency generates order numbers, second-class business logic, etc...
Redis is suitable for high concurrency increment and decrement functions