java执行redis自定义命令
前几日接到一个需求,运维那边对redis进行了封装,原生的命令如:set、get、del等都不再适用,要用封装的命令操作redis,这类资料太少了,特此记录
定义java封装类采用jedis执行命令
@Component public class RedisUtil { //从YML配置文件中读取数据赋值到属性 //@Value("${spring.redis.you.host}") private String host; //@Value("${spring.redis.you.port}") private int port; //@Value("${spring.redis.you.password}") private String password; public List<String> execCommandRedisLine(Jedis jedis, String command, String... args) throws InvocationTargetException, IllegalAccessException { Protocol.Command cmd = Protocol.Command.valueOf(command.toUpperCase()); Client client = jedis.getClient(); Method method = MethodUtils.getMatchingMethod(Client.class, "sendCommand", Protocol.Command.class, String[].class); method.setAccessible(true); method.invoke(client, cmd, args);