皓月白熏 2022-09-21 21:55 采纳率: 80.8%
浏览 25
已结题

vertx操作redis 想通过写一个json的配置文件,然后读取,去操作。 我这么写的,读不到配置问题、请问什么原因?

vertx操作redis
想通过写一个json的配置文件,然后读取,去操作。
我这么写的,读不到配置问题、请问什么原因?

{
  "options": {
    "config": {
      "redis_client_account": {
        "host": "localhost",
        "port": 6379,
        "select": 7,
        "auth": "123"
      },
      "maxPoolSize":200,
      "maxWaitQueueSize":50,
      "connectTimeout":5000,
      "idleTimeout":60
    }
  }
}
public class RedisTest extends AbstractVerticle {
  public static void main(String[] args) {
    Vertx vertx = Vertx.vertx();
    //部署verticle
    vertx.deployVerticle(new RedisTest());


  }

  private static RedisClient redisClient;
  private JsonObject config;

  @Override
  public void init(Vertx vertx, Context context) {
    super.init(vertx, context);
    this.config = context.config();
    JsonObject redisConfig = config.getJsonObject("redis_client_account", new JsonObject());
    System.out.println(redisConfig);

    RedisOptions options = new RedisOptions(redisConfig);
    Redis redis = Redis.createClient(vertx, options);
    RedisAPI api = RedisAPI.api(redis);
    set(api);

    get(api);
  }


  private void set(RedisAPI api) {

  }

  String redisCompressEncryptKey = "key1";

  private void get(RedisAPI api) {
    api.get(redisCompressEncryptKey, req -> {
      String redisCompressEncryptValue;
      if (req.succeeded()) {
        redisCompressEncryptValue = req.result().toString();
        System.out.println(redisCompressEncryptValue);
        if (Boolean.parseBoolean(redisCompressEncryptValue)) {
          System.out.println(redisCompressEncryptValue);
        }
      }
    });
  }

}

报错

{}
九月 21, 2022 9:55:04 下午 io.vertx.core.impl.ContextBase
严重: Unhandled exception
java.lang.NullPointerException
    at com.hao.starter.RedisTest.lambda$get$0(RedisTest.java:54)
    at io.vertx.core.impl.future.FutureImpl$3.onSuccess(FutureImpl.java:141)
    at io.vertx.core.impl.future.FutureBase.emitSuccess(FutureBase.java:60)
    at io.vertx.core.impl.future.FutureImpl.tryComplete(FutureImpl.java:211)
    at io.vertx.core.impl.future.Composition$1.onSuccess(Composition.java:62)
    at io.vertx.core.impl.future.FutureBase.emitSuccess(FutureBase.java:60)
    at io.vertx.core.impl.future.FutureImpl.tryComplete(FutureImpl.java:211)
    at io.vertx.core.impl.future.Eventually$1.onSuccess(Eventually.java:44)
    at io.vertx.core.impl.future.FutureBase.emitSuccess(FutureBase.java:60)
    at io.vertx.core.impl.future.SucceededFuture.addListener(SucceededFuture.java:88)
    at io.vertx.core.impl.future.Eventually.onSuccess(Eventually.java:41)
    at io.vertx.core.impl.future.FutureBase.emitSuccess(FutureBase.java:60)
    at io.vertx.core.impl.future.FutureImpl.tryComplete(FutureImpl.java:211)
    at io.vertx.core.impl.future.PromiseImpl.tryComplete(PromiseImpl.java:23)
    at io.vertx.core.Promise.tryComplete(Promise.java:121)
    at io.vertx.redis.client.impl.RedisStandaloneConnection.handle(RedisStandaloneConnection.java:405)
    at io.vertx.redis.client.impl.RESPParser.handleResponse(RESPParser.java:316)
    at io.vertx.redis.client.impl.RESPParser.handleLength(RESPParser.java:174)
    at io.vertx.redis.client.impl.RESPParser.handleBulk(RESPParser.java:240)
    at io.vertx.redis.client.impl.RESPParser.handle(RESPParser.java:97)
    at io.vertx.redis.client.impl.RESPParser.handle(RESPParser.java:24)
    at io.vertx.core.net.impl.NetSocketImpl.lambda$new$1(NetSocketImpl.java:98)
    at io.vertx.core.streams.impl.InboundBuffer.handleEvent(InboundBuffer.java:239)
    at io.vertx.core.streams.impl.InboundBuffer.write(InboundBuffer.java:129)
    at io.vertx.core.net.impl.NetSocketImpl$DataMessageHandler.handle(NetSocketImpl.java:418)
    at io.vertx.core.impl.EventLoopContext.emit(EventLoopContext.java:55)
    at io.vertx.core.impl.ContextBase.emit(ContextBase.java:239)
    at io.vertx.core.net.impl.NetSocketImpl.handleMessage(NetSocketImpl.java:394)
    at io.vertx.core.net.impl.ConnectionBase.read(ConnectionBase.java:157)
    at io.vertx.core.net.impl.VertxHandler.channelRead(VertxHandler.java:153)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:722)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:658)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:584)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:496)
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    at java.lang.Thread.run(Thread.java:750)
  • 写回答

3条回答 默认 最新

  • CSDN专家-sinJack 2022-09-21 22:57
    关注

    检查一下54行空指针异常代码。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 10月7日
  • 已采纳回答 9月29日
  • 创建了问题 9月21日

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?