library changed to redisson
parent
7e44b6ab63
commit
f750945e6e
6
pom.xml
6
pom.xml
|
@ -51,9 +51,9 @@
|
||||||
<version>0.9.0</version>
|
<version>0.9.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.lettuce</groupId>
|
<groupId>org.redisson</groupId>
|
||||||
<artifactId>lettuce-core</artifactId>
|
<artifactId>redisson</artifactId>
|
||||||
<version>6.1.8.RELEASE</version>
|
<version>3.17.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.md-5</groupId>
|
<groupId>net.md-5</groupId>
|
||||||
|
|
|
@ -73,7 +73,7 @@ public class ProxySystem extends Plugin {
|
||||||
|
|
||||||
this.players = this.mongoManager.getMongoDatabase().getCollection("players");
|
this.players = this.mongoManager.getMongoDatabase().getCollection("players");
|
||||||
|
|
||||||
this.redisManager = new RedisManager("redis://localhost");
|
this.redisManager = new RedisManager("redis://127.0.0.1:6379");
|
||||||
this.redisManager.connect();
|
this.redisManager.connect();
|
||||||
|
|
||||||
loadListeners();
|
loadListeners();
|
||||||
|
@ -88,7 +88,7 @@ public class ProxySystem extends Plugin {
|
||||||
this.mongoManager.getMongoClient().close();
|
this.mongoManager.getMongoClient().close();
|
||||||
|
|
||||||
//this.redisManager.getConnection().close();
|
//this.redisManager.getConnection().close();
|
||||||
this.redisManager.getClient().shutdown();
|
//this.redisManager.getClient().shutdown();
|
||||||
|
|
||||||
instance = null;
|
instance = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import net.krakatoa.proxy.ProxySystem;
|
import net.krakatoa.proxy.ProxySystem;
|
||||||
|
import net.krakatoa.proxy.redis.PlayerTest;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import net.md_5.bungee.api.chat.ClickEvent;
|
import net.md_5.bungee.api.chat.ClickEvent;
|
||||||
import net.md_5.bungee.api.chat.HoverEvent;
|
import net.md_5.bungee.api.chat.HoverEvent;
|
||||||
|
@ -30,6 +31,7 @@ import org.bson.conversions.Bson;
|
||||||
import org.msgpack.core.MessageBufferPacker;
|
import org.msgpack.core.MessageBufferPacker;
|
||||||
import org.msgpack.core.MessagePack;
|
import org.msgpack.core.MessagePack;
|
||||||
import org.msgpack.core.MessageUnpacker;
|
import org.msgpack.core.MessageUnpacker;
|
||||||
|
import org.redisson.api.RBucket;
|
||||||
|
|
||||||
public class PostLoginListener implements Listener {
|
public class PostLoginListener implements Listener {
|
||||||
|
|
||||||
|
@ -114,7 +116,7 @@ public class PostLoginListener implements Listener {
|
||||||
|
|
||||||
packer.close();
|
packer.close();
|
||||||
|
|
||||||
ProxySystem.getInstance().getRedisManager().getRedisKeyCommands()
|
/* ProxySystem.getInstance().getRedisManager().getRedisKeyCommands()
|
||||||
.set("player:" + proxiedPlayer.getUniqueId().toString(),
|
.set("player:" + proxiedPlayer.getUniqueId().toString(),
|
||||||
packer.toByteArray());
|
packer.toByteArray());
|
||||||
/*
|
/*
|
||||||
|
@ -125,8 +127,15 @@ public class PostLoginListener implements Listener {
|
||||||
map.put("skin", "steve");
|
map.put("skin", "steve");
|
||||||
map.put("money", "101001");
|
map.put("money", "101001");
|
||||||
map.put("state", "online");
|
map.put("state", "online");
|
||||||
ProxySystem.getInstance().getRedisManager().getRedisHashCommands()
|
//ProxySystem.getInstance().getRedisManager().getRedisHashCommands()
|
||||||
.hset("player", proxiedPlayer.getUniqueId().toString(), map);
|
// .hset("player", proxiedPlayer.getUniqueId().toString(), map);
|
||||||
|
|
||||||
|
RBucket<PlayerTest> bucket = ProxySystem.getInstance().getRedisManager().getRedissonClient()
|
||||||
|
.getBucket("player:" + proxiedPlayer.getUniqueId().toString());
|
||||||
|
|
||||||
|
PlayerTest playerTest = bucket.get();
|
||||||
|
|
||||||
|
ProxySystem.getInstance().getLogger().info("playerTest " + playerTest);
|
||||||
|
|
||||||
MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(packer.toByteArray());
|
MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(packer.toByteArray());
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
package net.krakatoa.proxy.redis;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class PlayerTest {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private int money;
|
||||||
|
private String car;
|
||||||
|
|
||||||
|
}
|
|
@ -1,19 +0,0 @@
|
||||||
package net.krakatoa.proxy.redis;
|
|
||||||
|
|
||||||
import io.lettuce.core.dynamic.Commands;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public interface RedisHashCommands extends Commands {
|
|
||||||
|
|
||||||
//Mono<Long> hdel(Key key, Key... fields);
|
|
||||||
|
|
||||||
//Mono<Boolean> hset(Key key, Key field, Value value);
|
|
||||||
|
|
||||||
Boolean hset(String key, String field, String value);
|
|
||||||
|
|
||||||
Long hset(String key, String field, String... value);
|
|
||||||
|
|
||||||
Long hset(String key, String field, Map<String, String> map);
|
|
||||||
|
|
||||||
//Mono<String> hmset(Key key, Map<Key, Value> map);
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
package net.krakatoa.proxy.redis;
|
|
||||||
|
|
||||||
import io.lettuce.core.dynamic.Commands;
|
|
||||||
import io.lettuce.core.dynamic.annotation.Key;
|
|
||||||
|
|
||||||
public interface RedisKeyCommands extends Commands {
|
|
||||||
|
|
||||||
String get(String key);
|
|
||||||
|
|
||||||
String set(String key, byte[] byteArray);
|
|
||||||
|
|
||||||
String set(String key, String value);
|
|
||||||
|
|
||||||
Long del(Key... keys);
|
|
||||||
|
|
||||||
Long del(String key);
|
|
||||||
}
|
|
|
@ -1,28 +1,29 @@
|
||||||
package net.krakatoa.proxy.redis;
|
package net.krakatoa.proxy.redis;
|
||||||
|
|
||||||
import io.lettuce.core.RedisClient;
|
|
||||||
import io.lettuce.core.dynamic.RedisCommandFactory;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import org.redisson.Redisson;
|
||||||
|
import org.redisson.api.RedissonClient;
|
||||||
|
import org.redisson.config.Config;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class RedisManager {
|
public class RedisManager {
|
||||||
|
|
||||||
private final String connectionUri;
|
private final String connectionUri;
|
||||||
|
|
||||||
private RedisClient client;
|
private Config config;
|
||||||
|
private RedissonClient redissonClient;
|
||||||
|
|
||||||
//private StatefulRedisConnection<String, String> connection;
|
//private StatefulRedisConnection<String, String> connection;
|
||||||
//private RedisStringCommands<String, String> commands;
|
//private RedisStringCommands<String, String> commands;
|
||||||
//private RedisKeyReactiveCommands<String, String> keyReactiveCommands;
|
//private RedisKeyReactiveCommands<String, String> keyReactiveCommands;
|
||||||
|
|
||||||
private RedisKeyCommands redisKeyCommands;
|
|
||||||
private RedisHashCommands redisHashCommands;
|
|
||||||
|
|
||||||
public void connect() {
|
public void connect() {
|
||||||
this.client = RedisClient.create(this.getConnectionUri());
|
this.config = new Config();
|
||||||
RedisCommandFactory factory = new RedisCommandFactory(client.connect());
|
this.config.useSingleServer().setAddress(this.connectionUri);
|
||||||
factory.setVerifyCommandMethods(false);
|
|
||||||
this.redisKeyCommands = factory.getCommands(RedisKeyCommands.class);
|
this.redissonClient = Redisson.create(this.config);
|
||||||
this.redisHashCommands = factory.getCommands(RedisHashCommands.class);
|
|
||||||
//this.connection = client.connect();
|
//this.connection = client.connect();
|
||||||
//this.commands = connection.sync();
|
//this.commands = connection.sync();
|
||||||
//this.keyReactiveCommands = this.connection.reactive();
|
//this.keyReactiveCommands = this.connection.reactive();
|
||||||
|
|
Loading…
Reference in New Issue