Spring RedisTemplate操作-String操作
Posted aoeiuv
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Spring RedisTemplate操作-String操作相关的知识,希望对你有一定的参考价值。
@Autowired @Resource(name="redisTemplate") private RedisTemplate<String, String> rt; public void flushdb(){ rt.execute(new RedisCallback<Object>() { public String doInRedis(RedisConnection connection) throws DataAccessException { connection.flushDb(); return "ok"; } }); } public void set(){ 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 = new HashMap<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 void get(){ ValueOperations<String, String> vo = rt.opsForValue(); out(vo.get("wzg")); out(vo.get("wzg",1,2)); 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(2000); // } catch (InterruptedException e) { // } // out(rt.getExpire("wzg2")); }
以上是关于Spring RedisTemplate操作-String操作的主要内容,如果未能解决你的问题,请参考以下文章
Spring RedisTemplate操作-String操作