@Test public void getErrorAfterConnectionReset() throws Exception { class TestConnection extends Connection { public TestConnection() { super("localhost", 6379); } protected boolean sendCommand(Command cmd, byte[]... args) { return super.sendCommand(cmd, args); } } TestConnection conn = new TestConnection(); try { conn.sendCommand(Command.HMSET, new byte[1024 * 1024 + 1][0]); fail("Should throw exception"); } catch (JedisConnectionException jce) { assertEquals("ERR Protocol error: invalid multibulk length", jce.getMessage()); } }
@Around("execution(* redis.clients.jedis.Protocol.*sendCommand(..))") public Object process(ProceedingJoinPoint point) throws Throwable { System.out.println("@Around:执行目标方法之前..."); //访问目标方法的参数: Object[] args = point.getArgs(); //进行业务验证 long begin = System.nanoTime(); if(null!=args && null!=args[1] && args[1] instanceof Command){ logger.info("command:"+((Command)args[1]).name()+","+CacheUtils.getSendCommondSizeType(args)); }else if (null!=args && null!=args[1] && args[1] instanceof byte[]){ logger.info("command:"+new String((byte[])args[1])+","+CacheUtils.getSendCommondSizeType(args)); }else{ logger.info(CacheUtils.getSendCommondSizeType(args)); } Object returnValue = point.proceed(args); long time = System.nanoTime() - begin; logger.info(point.getSignature()+",last "+time/1000000+"ms"); System.out.println("@Around:执行目标方法之后..."); return returnValue; }
@Test public void getErrorAfterConnectionReset() throws Exception { class TestConnection extends Connection { public TestConnection() { super("localhost", 6379); } @Override protected Connection sendCommand(ProtocolCommand cmd, byte[]... args) { return super.sendCommand(cmd, args); } } TestConnection conn = new TestConnection(); try { conn.sendCommand(Command.HMSET, new byte[1024 * 1024 + 1][0]); fail("Should throw exception"); } catch (JedisConnectionException jce) { assertEquals("ERR Protocol error: invalid multibulk length", jce.getMessage()); } }
protected Connection sendCommand(final Command cmd, final String... args) { final byte[][] bargs = new byte[args.length][]; for (int i = 0; i < args.length; i++) { bargs[i] = SafeEncoder.encode(args[i]); } return sendCommand(cmd, bargs); }
@SuppressWarnings({ "unchecked" }) public Object doSendCommandStart(Object[] args) { Command cmd = (Command) args[0]; String host = (String) args[2]; Integer port = (Integer) args[3]; String targetURL = "redis://" + host + ":" + port; String redisAction = cmd.name(); if (logger.isDebugable()) { logger.debug("REDIS INVOKE START: " + targetURL + " action: " + redisAction, null); } Map<String, Object> params = new HashMap<String, Object>(); params.put(CaptureConstants.INFO_CLIENT_REQUEST_URL, targetURL); params.put(CaptureConstants.INFO_CLIENT_REQUEST_ACTION, redisAction); params.put(CaptureConstants.INFO_CLIENT_APPID, appid); params.put(CaptureConstants.INFO_CLIENT_TYPE, "redis.client.Jedis"); UAVServer.instance().runMonitorCaptureOnServerCapPoint(CaptureConstants.CAPPOINT_APP_CLIENT, Monitor.CapturePhase.PRECAP, params); // register adapter UAVServer.instance().runSupporter("com.creditease.uav.apm.supporters.InvokeChainSupporter", "registerAdapter", JedisClientAdapter.class); ivcContextParams = (Map<String, Object>) UAVServer.instance().runSupporter( "com.creditease.uav.apm.supporters.InvokeChainSupporter", "runCap", InvokeChainConstants.CHAIN_APP_CLIENT, InvokeChainConstants.CapturePhase.PRECAP, params, JedisClientAdapter.class, args); return null; }
@Override public Object eval(String script, String key) { Span span = helper.buildSpan(Command.EVAL.name(), key); span.setTag("script", script); try { return super.eval(script, key); } catch (Exception e) { onError(e, span); throw e; } finally { span.finish(); } }
@Override public Object evalsha(String script, String key) { Span span = helper.buildSpan(Command.EVALSHA.name(), key); span.setTag("script", script); try { return super.evalsha(script, key); } catch (Exception e) { onError(e, span); throw e; } finally { span.finish(); } }
/** * Sends the "INFO all" command. */ public Properties infoAll() { sendCommand(Command.INFO, "all"); String reply = getBulkReply(); Properties p = new Properties(); try { p.load(new StringReader(reply)); } catch (IOException e) { throw new JedisDataException(e); } return p; }
protected Connection sendCommand(final Command cmd) { return sendCommand(cmd, EMPTY_ARGS); }
public void ping() { sendCommand(Command.PING); }
public void set(final byte[] key, final byte[] value) { sendCommand(Command.SET, key, value); }
public void set(final byte[] key, final byte[] value, final byte[] nxxx, final byte[] expx, final long time) { sendCommand(Command.SET, key, value, nxxx, expx, toByteArray(time)); }
public void get(final byte[] key) { sendCommand(Command.GET, key); }
public void set(final byte[] key, final byte[] value, final byte[] nxxx) { sendCommand(Command.SET, key, value, nxxx); }
public void set(final byte[] key, final byte[] value, final byte[] nxxx, final byte[] expx, final int time) { sendCommand(Command.SET, key, value, nxxx, expx, toByteArray(time)); }
public void asking() { sendCommand(Command.ASKING); }
public void set(final byte[] key, final byte[] value, final SetParams params) { sendCommand(Command.SET, params.getByteParams(key, value)); }
protected Connection sendCommand(final Command cmd, final byte[]... args) { connect(); Protocol.sendCommand(outputStream, cmd, args); pipelinedCommands++; return this; }
protected Connection sendCommand(final Command cmd) { connect(); Protocol.sendCommand(outputStream, cmd, new byte[0][]); pipelinedCommands++; return this; }
protected Connection sendCommand(Command cmd) { return this.sendCommand(cmd, EMPTY_ARGS); }