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)