首页 > 代码库 > Spring RedisTemplate操作-String操作(2)
Spring RedisTemplate操作-String操作(2)
@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操作(2)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。