io.vertx.redis.RedisClient.evalsha()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(11.4k)|赞(0)|评价(0)|浏览(194)

本文整理了Java中io.vertx.redis.RedisClient.evalsha方法的一些代码示例,展示了RedisClient.evalsha的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RedisClient.evalsha方法的具体详情如下:
包路径:io.vertx.redis.RedisClient
类名称:RedisClient
方法名:evalsha

RedisClient.evalsha介绍

[英]Execute a Lua script server side. Due to the dynamic nature of this command any response type could be returned for This reason and to ensure type safety the reply is always guaranteed to be a JsonArray. When a reply if for example a String the handler will be called with a JsonArray with a single element containing the String.
[中]在服务器端执行Lua脚本。由于该命令的动态性质,因此可以返回任何响应类型,并且为了确保类型安全,始终保证回复为JsonArray。例如,当回复为字符串时,处理程序将使用包含该字符串的单个元素的JsonArray调用。

代码示例

代码示例来源:origin: io.vertx/vertx-rx-java

/**
 * Execute a Lua script server side. Due to the dynamic nature of this command any response type could be returned
 * for This reason and to ensure type safety the reply is always guaranteed to be a JsonArray.
 *
 * When a reply if for example a String the handler will be called with a JsonArray with a single element containing
 * the String.
 * @param sha1 SHA1 digest of the script cached on the server
 * @param keys List of keys
 * @param values List of values
 * @param handler Handler for the result of this call.
 * @return 
 */
public io.vertx.rxjava.redis.RedisClient evalsha(String sha1, List<String> keys, List<String> values, Handler<AsyncResult<JsonArray>> handler) { 
 delegate.evalsha(sha1, keys, values, handler);
 return this;
}

代码示例来源:origin: vert-x3/vertx-rx

/**
 * Execute a Lua script server side. Due to the dynamic nature of this command any response type could be returned
 * for This reason and to ensure type safety the reply is always guaranteed to be a JsonArray.
 *
 * When a reply if for example a String the handler will be called with a JsonArray with a single element containing
 * the String.
 * @param sha1 SHA1 digest of the script cached on the server
 * @param keys List of keys
 * @param values List of values
 * @param handler Handler for the result of this call.
 * @return 
 */
public io.vertx.rxjava.redis.RedisClient evalsha(String sha1, List<String> keys, List<String> values, Handler<AsyncResult<JsonArray>> handler) { 
 delegate.evalsha(sha1, keys, values, handler);
 return this;
}

代码示例来源:origin: io.vertx/vertx-lang-groovy

public static io.vertx.redis.RedisClient evalsha(io.vertx.redis.RedisClient j_receiver, java.lang.String sha1, java.util.List<java.lang.String> keys, java.util.List<java.lang.String> values, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.util.List<Object>>> handler) {
 io.vertx.core.impl.ConversionHelper.fromObject(j_receiver.evalsha(sha1,
  keys != null ? keys.stream().map(elt -> elt).collect(java.util.stream.Collectors.toList()) : null,
  values != null ? values.stream().map(elt -> elt).collect(java.util.stream.Collectors.toList()) : null,
  handler != null ? new io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.core.json.JsonArray>>() {
  public void handle(io.vertx.core.AsyncResult<io.vertx.core.json.JsonArray> ar) {
   handler.handle(ar.map(event -> io.vertx.core.impl.ConversionHelper.fromJsonArray(event)));
  }
 } : null));
 return j_receiver;
}
public static io.vertx.redis.RedisClient evalScript(io.vertx.redis.RedisClient j_receiver, io.vertx.redis.Script script, java.util.List<java.lang.String> keys, java.util.List<java.lang.String> args, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.util.List<Object>>> handler) {

代码示例来源:origin: org.swisspush.gateleen/gateleen-queue

@Override
  public void exec(int executionCounter) {
    redisClient.evalsha(luaScriptState.getSha(), keys, arguments, event -> {
      if(event.succeeded()){
        future.complete();
      } else {
        String message = event.cause().getMessage();
        if(message != null && message.startsWith("NOSCRIPT")) {
          log.warn("ReOpenCircuitRedisCommand script couldn't be found, reload it");
          log.warn("amount the script got loaded: " + String.valueOf(executionCounter));
          if(executionCounter > 10) {
            future.fail("amount the script got loaded is higher than 10, we abort");
          } else {
            luaScriptState.loadLuaScript(new ReOpenCircuitRedisCommand(luaScriptState, keys, arguments, redisClient, log, future), executionCounter);
          }
        } else {
          future.fail("ReOpenCircuitRedisCommand request failed with message: " + message);
        }
      }
    });
  }
}

代码示例来源:origin: org.swisspush.gateleen/gateleen-queue

@Override
  public void exec(int executionCounter) {
    redisClient.evalsha(luaScriptState.getSha(), keys, arguments, event -> {
      if(event.succeeded()){
        future.complete();
      } else {
        String message = event.cause().getMessage();
        if(message != null && message.startsWith("NOSCRIPT")) {
          log.warn("CloseCircuitRedisCommand script couldn't be found, reload it");
          log.warn("amount the script got loaded: " + String.valueOf(executionCounter));
          if(executionCounter > 10) {
            future.fail("amount the script got loaded is higher than 10, we abort");
          } else {
            luaScriptState.loadLuaScript(new CloseCircuitRedisCommand(luaScriptState, keys, arguments, redisClient, log, future), executionCounter);
          }
        } else {
          future.fail("CloseCircuitRedisCommand request failed with message: " + message);
        }
      }
    });
  }
}

代码示例来源:origin: org.swisspush.gateleen/gateleen-queue

@Override
  public void exec(int executionCounter) {
    redisClient.evalsha(luaScriptState.getSha(), keys, arguments, event -> {
      if(event.succeeded()){
        JsonArray result = event.result();
        future.complete(new ArrayList<>(result.getList()));
      } else {
        String message = event.cause().getMessage();
        if(message != null && message.startsWith("NOSCRIPT")) {
          log.warn("UnlockSampleQueuesRedisCommand script couldn't be found, reload it");
          log.warn("amount the script got loaded: " + String.valueOf(executionCounter));
          if(executionCounter > 10) {
            future.fail("amount the script got loaded is higher than 10, we abort");
          } else {
            luaScriptState.loadLuaScript(new UnlockSampleQueuesRedisCommand(luaScriptState, keys, arguments, redisClient, log, future), executionCounter);
          }
        } else {
          future.fail("UnlockSampleQueuesRedisCommand request failed with message: " + message);
        }
      }
    });
  }
}

代码示例来源:origin: org.swisspush.gateleen/gateleen-queue

@Override
  public void exec(int executionCounter) {
    redisClient.evalsha(luaScriptState.getSha(), keys, arguments, event -> {
      if(event.succeeded()){
        future.complete(event.result().getLong(0));
      } else {
        String message = event.cause().getMessage();
        if(message != null && message.startsWith("NOSCRIPT")) {
          log.warn("HalfOpenCircuitRedisCommand script couldn't be found, reload it");
          log.warn("amount the script got loaded: " + String.valueOf(executionCounter));
          if(executionCounter > 10) {
            future.fail("amount the script got loaded is higher than 10, we abort");
          } else {
            luaScriptState.loadLuaScript(new HalfOpenCircuitRedisCommand(luaScriptState, keys, arguments, redisClient, log, future), executionCounter);
          }
        } else {
          future.fail("HalfOpenCircuitRedisCommand request failed with message: " + message);
        }
      }
    });
  }
}

代码示例来源:origin: org.swisspush.gateleen/gateleen-hook

@Override
  public void exec(int executionCounter) {
    redisClient.evalsha(luaScriptState.getSha(), keys, arguments, event -> {
      if(event.succeeded()){
        Integer insertCount = event.result().getInteger(0);
        Boolean timerStarted = insertCount != null && insertCount > 0;
        future.complete(timerStarted);
      } else {
        String message = event.cause().getMessage();
        if(message != null && message.startsWith("NOSCRIPT")) {
          log.warn("StartQueueTimerRedisCommand script couldn't be found, reload it");
          log.warn("amount the script got loaded: " + String.valueOf(executionCounter));
          if(executionCounter > 10) {
            future.fail("amount the script got loaded is higher than 10, we abort");
          } else {
            luaScriptState.loadLuaScript(new StartQueueTimerRedisCommand(luaScriptState, keys, arguments, redisClient, log, future), executionCounter);
          }
        } else {
          future.fail("StartQueueTimerRedisCommand request failed with message: " + message);
        }
      }
    });

  }
}

代码示例来源:origin: org.swisspush.gateleen/gateleen-hook

@Override
  public void exec(int executionCounter) {
    redisClient.evalsha(luaScriptState.getSha(), keys, arguments, event -> {
      if(event.succeeded()){
        JsonArray jsonArray = event.result();
        if(jsonArray != null){
          future.complete(jsonArray.getList());
        } else {
          future.complete(new ArrayList<>());
        }
      } else {
        String message = event.cause().getMessage();
        if(message != null && message.startsWith("NOSCRIPT")) {
          log.warn("RemoveExpiredQueuesRedisCommand script couldn't be found, reload it");
          log.warn("amount the script got loaded: " + String.valueOf(executionCounter));
          if(executionCounter > 10) {
            future.fail("amount the script got loaded is higher than 10, we abort");
          } else {
            luaScriptState.loadLuaScript(new RemoveExpiredQueuesRedisCommand(luaScriptState, keys, arguments, redisClient, log, future), executionCounter);
          }
        } else {
          future.fail("RemoveExpiredQueuesRedisCommand request failed with message: " + message);
        }
      }
    });

  }
}

代码示例来源:origin: org.swisspush.gateleen/gateleen-queue

@Override
  public void exec(int executionCounter) {
    redisClient.evalsha(luaScriptState.getSha(), keys, arguments, event -> {
      if(event.succeeded()){
        String value = event.result().getString(0);
        if (log.isTraceEnabled()) {
          log.trace("UpdateStatsRedisCommand lua script got result: " + value);
        }
        future.complete(UpdateStatisticsResult.fromString(value, UpdateStatisticsResult.ERROR));
      } else {
        String message = event.cause().getMessage();
        if(message != null && message.startsWith("NOSCRIPT")) {
          log.warn("UpdateStatsRedisCommand script couldn't be found, reload it");
          log.warn("amount the script got loaded: " + String.valueOf(executionCounter));
          if(executionCounter > 10) {
            future.fail("amount the script got loaded is higher than 10, we abort");
          } else {
            luaScriptState.loadLuaScript(new UpdateStatsRedisCommand(luaScriptState, keys, arguments, redisClient, log, future), executionCounter);
          }
        } else {
          future.fail("UpdateStatsRedisCommand request failed with message: " + message);
        }
      }
    });
  }
}

代码示例来源:origin: org.swisspush.gateleen/gateleen-queue

@Override
  public void exec(int executionCounter) {
    redisClient.evalsha(luaScriptState.getSha(), keys, arguments, event -> {
      if(event.succeeded()){
        JsonArray resultArray = event.result();
        try{
          String objectStr = resultArray.getString(0);
          JsonObject obj = new JsonObject(objectStr);
          future.complete(obj);
        }catch (Exception e){
          future.fail("could not get json from lua script. cause: " + e);
        }
      } else {
        String message = event.cause().getMessage();
        if(message != null && message.startsWith("NOSCRIPT")) {
          log.warn("GetAllCircuitsRedisCommand script couldn't be found, reload it");
          log.warn("amount the script got loaded: " + String.valueOf(executionCounter));
          if(executionCounter > 10) {
            future.fail("amount the script got loaded is higher than 10, we abort");
          } else {
            luaScriptState.loadLuaScript(new GetAllCircuitsRedisCommand(luaScriptState, keys, arguments, redisClient, log, future), executionCounter);
          }
        } else {
          future.fail("GetAllCircuitsRedisCommand request failed with message: " + message);
        }
      }
    });
  }
}

代码示例来源:origin: org.swisspush/redisques

@Override
  public void exec(int executionCounter) {
    redisClient.evalsha(luaScripts.get(LuaScript.CHECK).getSha(), keys, arguments, event -> {
      if(event.succeeded()){
        Long value = event.result().getLong(0);
        if (log.isTraceEnabled()) {
          log.trace("Check lua script got result: " + value);
        }
        handler.handle(value == 1L);
      } else {
        String message = event.cause().getMessage();
        if(message != null && message.startsWith("NOSCRIPT")) {
          log.warn("Check script couldn't be found, reload it");
          log.warn("amount the script got loaded: " + String.valueOf(executionCounter));
          if(executionCounter > 10) {
            log.error("amount the script got loaded is higher than 10, we abort");
          } else {
            luaScripts.get(LuaScript.CHECK).loadLuaScript(new Check(keys, arguments, redisClient, handler), executionCounter);
          }
        } else {
          log.error("Check request failed.", event.cause());
        }
      }
    });
  }
}

相关文章

RedisClient类方法