springboot整合redis-sentinel哨兵模式集群(三)

Service层

@Service
public class StuService {
	@Autowired
	RedisOperateUtil redisOpetateUtil;

	Student stuEntity = new Student();
	stuEntity.name = "luxifa";
	stuEntity.age = 25;

	Map<String, Object> stuMap = new HashMap<>();
    stuMap.put("name","degula");
    stuMap.put("age",27);

	Student stuList1 = new Student();
	stuList1.name = "zhangsan";
	stuEntity.age = 17;
	
	Student stuList2 = new Student();
	stuList2.name = "lisi";
	stuList2.age = 20;
	
	Student stuList3 = new Student();
	stuList3.name = "wangwu";
	stuList3.age = 29;
	
// String
	// 插入键值对
	redisOpetateUtil.set("stuEntity",stu1);
	// 取值
	Object stuObject = redisOpetateUtil.get("stuEntity");
    // 判断键是否存在
    boolean exist = redisOpetateUtil.hasKey("stuEntity");
    // 删除键值
    redisOpetateUtil.del("stuEntity");

// map
    // 插入键值对
	redisOpetateUtil.set("stuMap",stuMap);
	// 取值
	Map<Object, Object> stuMapResult = redisOpetateUtil.get("stuMap");
    // 判断键是否存在
    boolean existMap = redisOpetateUtil.hasKey("stuMap");
    // 删除键值
    redisOpetateUtil.del("stuMap");
   
// list
    // 插入键值对
	redisOpetateUtil.lSet("stuList",stuList1);
	redisOpetateUtil.lSet("stuList",stuList2);
	redisOpetateUtil.lSet("stuList",stuList3);
	// 取值
	List<Object> stuList= redisOpetateUtil.lGet("stuList");
    // 删除键值
    redisOpetateUtil.del("stuList");
    // list的大小
    int listSize = (int)redisOpetateUtil.listSize();
}

你可能感兴趣的:(spring,boot,redis,sentinel)