@Autowired @Resource (name= "Redistemplate") PrivateRedistemplate<string, string>RT; Public voidflushdb () {Rt.execute (NewRediscallback<object>() { PublicString Doinredis (redisconnection connection)throwsDataAccessException {connection.flushdb (); return"OK"; } }); } Public voidset () {flushdb (); Valueoperations<string, string> vo =Rt.opsforvalue (); Vo.set ("Wzg", "Nihao"); Vo.set ("Wzg", "Nihao", 3); Vo.set ("Wzg2", "Nihao", 2, timeunit.minutes); Vo.set ("MC", "Nihao"); Vo.setifabsent ("Wzg", "DSG"); Map<string, string> map =NewHashmap<string, string>(); Map.put ("CFF", "XSG"); Map.put ("CL", "XXSG"); Vo.multiset (map); Vo.append ("CFF", "SM"); Vo.increment ("Age", 2); Vo.increment ("Age", 1); Vo.increment ("Age",-1); Rt.delete ("MC"); Rt.convertandsend ("Redisss", "Niyashabi"); Rt.setenabletransactionsupport (true); } Public voidget () {valueoperations<string, string> vo =Rt.opsforvalue (); Out (Vo.get ("Wzg")); Out (Vo.get ("Wzg",)); Out (Vo.getandset ("Wzg", "Hello")); Out (Vo.get ("Wzg")); Out (Vo.multiget (Arrays.aslist ("CFF", "CL")));//Out (Vo.get ("Age"));Out (Vo.size ("Wzg")); Out (Vo.get ("MC")); Out (Rt.keys ("*")); Out (Rt.randomkey ()); Out (Rt.getclientlist ()); Out (Rt.haskey ("Wzg")); Out (Rt.type ("Wzg")); //try {//Thread.Sleep (+);//} catch (Interruptedexception e) {// }//Out (Rt.getexpire ("wzg2"));}
Spring redistemplate Operation-string operation (2)