Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sentinel support added and DELETE key with member #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/com/mapabc/api/Tile38Template.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public interface Tile38Template {

public void aofShrink();

public String delEntry(String key, String member);

public String intersects(String key, Element element);

public String nearBy(String key, double lng, double lat, int length);
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/mapabc/api/Tile38TemplateImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ public void aofShrink() {
commands.aofShrink();
}

@Override
public String delEntry(String key, String member) {
if (StringUtil.isBlack(key) || StringUtil.isBlack(member)) {
return "key is not null";
}
return commands.delEntry(key,member);
}

@Override
public String intersects(String key, Element element) {
if (StringUtil.isBlack(key)) {
Expand Down
24 changes: 22 additions & 2 deletions src/main/java/com/mapabc/client/Tile38Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,25 @@ public class Tile38Client implements Serializable {
private RedisClient client = null;

private StatefulRedisConnection<String, String> connect = null;

public Tile38Client() {
client = this.createRedisClient("127.0.0.1", 9851);
commands = this.createCommands(client, "");
}

public Tile38Client(String host, int port, String passWord) {
client = this.createRedisClient(host, port);
if (passWord != null){
client = this.createRedisClient(host, port,passWord);
} else {
client = this.createRedisClient(host, port);
}
commands = this.createCommands(client, passWord);
}

public Tile38Client(String sentinelHost, int sentinelPort, String password , String masterId) {
client = this.createRedisClient(sentinelHost , sentinelPort , password , masterId);
commands = this.createCommands(client, password);
}

public void close() {
if (connect != null) {
try {
Expand Down Expand Up @@ -79,5 +87,17 @@ private Tile38Commands createCommands(RedisClient client, String passWord) {
private RedisClient createRedisClient(String host, int port) {
return RedisClient.create(RedisURI.create(host, port));
}

private RedisClient createRedisClient(String host, int port, String passWord) {
RedisURI uri = RedisURI.Builder.redis(host, port).withPassword(passWord.toCharArray()).build();
RedisClient redisClient = RedisClient.create(uri);
redisClient.setOptions(ClientOptions.builder().protocolVersion(ProtocolVersion.RESP2).build());
return redisClient;
}

private RedisClient createRedisClient(String sentinelHost, int sentinelPort, String password , String masterId) {
RedisURI redisURI = RedisURI.Builder.sentinel(sentinelHost, sentinelPort, masterId, password).withDatabase(0).build();
return RedisClient.create(redisURI);
}

}
2 changes: 1 addition & 1 deletion src/main/java/com/mapabc/commands/BatchedCommandType.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public enum BatchedCommandType implements ProtocolKeyword {
NEARBY,
WITHIN,
INTERSECTS,

SETHOOK,
CLUSTER;
public final byte[] bytes;

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/mapabc/commands/Tile38Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public interface Tile38Commands extends Commands {
@Command("AOFSHRINK")
void aofShrink();

@Command("DEL ?0 ?1")
String delEntry(String key,String member);

/******************************************************
** 查询 **
Expand Down Expand Up @@ -287,7 +289,7 @@ public interface Tile38Commands extends Commands {
String setElementWithField(String key, String id, String geojson , String fieldKeyName , String fieldValue);


@Command("SET ?0 ?1 OBJECT ?2 FIELD ?3 ?4 ?5 ?6")
@Command("SET ?0 ?1 OBJECT ?2 FIELD ?3 ?4 FIELD ?5 ?6")
String setElementWithFields(String key, String id, String geojson , String field1KeyName , String field1Value , String field2KeyName , String field2Value);

/**
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/mapabc/entity/Element.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package com.mapabc.entity;

import io.lettuce.core.protocol.CommandArgs;

import java.io.Serializable;

/**
* @Author ke.han
* @Date 2019/11/14 15:33
**/
public class Element implements Serializable {
public CommandArgs<String, String> getCommandArgs(String key, String member){
return null;
}
}
8 changes: 8 additions & 0 deletions src/main/java/com/mapabc/entity/Fence.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.mapabc.entity;

import com.alibaba.fastjson.JSONObject;
import io.lettuce.core.codec.StringCodec;
import io.lettuce.core.protocol.CommandArgs;

import java.io.Serializable;

Expand All @@ -12,6 +14,12 @@ public class Fence extends Element implements Serializable {

private JSONObject fence;

@Override
public CommandArgs<String, String> getCommandArgs(String key, String member) {
String geojson = JSONObject.toJSONString(fence);
return new CommandArgs<>(StringCodec.UTF8).add(key).add(member).add("OBJECT").add(geojson);
}

public Fence() {}

public Fence(JSONObject fence) {
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/mapabc/entity/Rectangle.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.mapabc.entity;


import com.alibaba.fastjson.JSONObject;
import io.lettuce.core.codec.StringCodec;
import io.lettuce.core.protocol.CommandArgs;

import java.io.Serializable;

/**
Expand All @@ -12,6 +16,15 @@ public class Rectangle extends Element implements Serializable {
private Point leftDown;
private Point rightUpper;

@Override
public CommandArgs<String, String> getCommandArgs(String key, String member) {
double lng1 = leftDown.getLng();
double lat1 = leftDown.getLat();
double lng2 = rightUpper.getLng();
double lat2 = rightUpper.getLat();
return new CommandArgs<>(StringCodec.UTF8).add(key).add(member).add("BOUNDS").add(lng1).add(lat1).add(lng2).add(lat2);
}

public Rectangle() {}

public Rectangle(Point leftDown, Point rightUpper) {
Expand Down