Skip to content

Commit 6c91228

Browse files
committed
timeout 0 block and callback ok
1 parent 1386dc3 commit 6c91228

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+312
-255
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ above, provided that you also meet all of these conditions:
176176
table of data to be supplied by an application program that uses
177177
the facility, other than as an argument passed when the facility
178178
is invoked, then you must make a good faith effort to ensure that,
179-
in the event an application does not supply such function or
179+
in the blockEvent an application does not supply such function or
180180
table, the facility still operates, and performs whatever part of
181181
its purpose remains meaningful.
182182

TODO.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
- list的命令区分左右的可以抽象下,不然重复度太高了
1+
- 带有删除性质的命令 要对已经为空的key进行删除,这部分可以抽象到父类中
22
- 重构下命令的参数校验,重复度有点高,可以通过注解的方式标注每一个命令的参数和校验规则,然后走统一的校验逻辑
33
- 是否也能做一个分布式的集群,节点之间需要通信?(利用ZK?)
44
- 支持类似linux管道符'|'和重定向'>'符号, 以及一些linux操作系统的命令?

src/main/java/ginyu/cmd/AbstractRedisCommand.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public void doCommand(String commandName, Arrays arrays, ChannelHandlerContext c
3131
if (commandAnno.checkExpire() && arg instanceof KeyArg) {
3232
KeyArg keyArg = (KeyArg) arg;
3333
Client client = Attributes.getClient(ctx);
34-
Database database = Server.INSTANCE.getDb().getDatabase(client.getDb());
34+
Database database = client.getDatabase();
3535
boolean expired = database.checkIfExpired(keyArg.getKey());
3636
if (expired) {
3737
database.delete(keyArg.getKey());

src/main/java/ginyu/cmd/connection/Select.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected void validate(String commandName, Arrays arrays) {
3030
@Override
3131
protected Resp2 doCommand0(SelectArg arg, ChannelHandlerContext ctx) {
3232
Client client = Attributes.getClient(ctx);
33-
client.setDb(arg.getIndex());
33+
client.select(arg.getIndex());
3434
return SimpleStrings.OK;
3535
}
3636
}

src/main/java/ginyu/cmd/generic/Del.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ protected void validate(String commandName, Arrays arrays) {
3636
@Override
3737
protected Resp2 doCommand0(DelArg arg, ChannelHandlerContext ctx) {
3838
Client client = Attributes.getClient(ctx);
39-
Database database = Server.INSTANCE.getDb().getDatabase(client.getDb());
39+
Database database = client.getDatabase();
4040
int deleted = database.delete(arg.getKeys());
4141
return Integers.create(deleted);
4242
}

src/main/java/ginyu/cmd/generic/Exists.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protected void validate(String commandName, Arrays arrays) {
3535
@Override
3636
protected Resp2 doCommand0(ExistsArg arg, ChannelHandlerContext ctx) {
3737
Client client = Attributes.getClient(ctx);
38-
Database database = Server.INSTANCE.getDb().getDatabase(client.getDb());
38+
Database database = client.getDatabase();
3939
int exists = database.exists(arg.getKeys());
4040
return Integers.create(exists);
4141
}

src/main/java/ginyu/cmd/generic/Expire.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ protected void validate(String commandName, Arrays arrays) {
4040
@Override
4141
protected Resp2 doCommand0(ExpireArg arg, ChannelHandlerContext ctx) {
4242
Client client = Attributes.getClient(ctx);
43-
Database database = Server.INSTANCE.getDb().getDatabase(client.getDb());
43+
Database database = client.getDatabase();
4444
RedisObject redisObject = database.get(arg.getKey());
4545
if (redisObject == null) {
4646
return Integers.ZERO;

src/main/java/ginyu/cmd/generic/ExpireAt.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ protected void validate(String commandName, Arrays arrays) {
4040
@Override
4141
protected Resp2 doCommand0(ExpireAtArg arg, ChannelHandlerContext ctx) {
4242
Client client = Attributes.getClient(ctx);
43-
Database database = Server.INSTANCE.getDb().getDatabase(client.getDb());
43+
Database database = client.getDatabase();
4444
RedisObject redisObject = database.get(arg.getKey());
4545
if (redisObject == null) {
4646
return Integers.ZERO;

src/main/java/ginyu/cmd/generic/PExpire.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ protected void validate(String commandName, Arrays arrays) {
4040
@Override
4141
protected Resp2 doCommand0(PExpireArg arg, ChannelHandlerContext ctx) {
4242
Client client = Attributes.getClient(ctx);
43-
Database database = Server.INSTANCE.getDb().getDatabase(client.getDb());
43+
Database database = client.getDatabase();
4444
RedisObject redisObject = database.get(arg.getKey());
4545
if (redisObject == null) {
4646
return Integers.ZERO;

src/main/java/ginyu/cmd/generic/PTTL.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protected void validate(String commandName, Arrays arrays) {
3535
@Override
3636
protected Resp2 doCommand0(PTTLArg arg, ChannelHandlerContext ctx) {
3737
Client client = Attributes.getClient(ctx);
38-
Database database = Server.INSTANCE.getDb().getDatabase(client.getDb());
38+
Database database = client.getDatabase();
3939
RedisObject value = database.get(arg.getKey());
4040
if (value == null) {
4141
return Integers.N_TWO;

src/main/java/ginyu/cmd/generic/Persist.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protected void validate(String commandName, Arrays arrays) {
3535
@Override
3636
protected Resp2 doCommand0(KeyArg arg, ChannelHandlerContext ctx) {
3737
Client client = Attributes.getClient(ctx);
38-
Database database = Server.INSTANCE.getDb().getDatabase(client.getDb());
38+
Database database = client.getDatabase();
3939
Integer persisted = database.cleanExpired(arg.getKey());
4040
return Integers.create(persisted);
4141
}

src/main/java/ginyu/cmd/generic/Rename.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ protected void validate(String commandName, Arrays arrays) {
3838
@Override
3939
protected Resp2 doCommand0(RenameArg arg, ChannelHandlerContext ctx) {
4040
Client client = Attributes.getClient(ctx);
41-
Database database = Server.INSTANCE.getDb().getDatabase(client.getDb());
41+
Database database = client.getDatabase();
4242
RedisObject value = database.remove(arg.getKey());
4343
if (value == null) {
4444
throw new GinyuException("no such key '%s'", arg.getKey());

src/main/java/ginyu/cmd/generic/TTL.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ protected void validate(String commandName, Arrays arrays) {
3636
@Override
3737
protected Resp2 doCommand0(KeyArg arg, ChannelHandlerContext ctx) {
3838
Client client = Attributes.getClient(ctx);
39-
Database database = Server.INSTANCE.getDb().getDatabase(client.getDb());
39+
Database database = client.getDatabase();
4040
boolean expired = database.checkIfExpired(arg.getKey());
4141
if (expired) {
4242
database.delete(arg.getKey());

src/main/java/ginyu/cmd/generic/Type.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ protected void validate(String commandName, Arrays arrays) {
3636
@Override
3737
protected Resp2 doCommand0(KeyArg arg, ChannelHandlerContext ctx) {
3838
Client client = Attributes.getClient(ctx);
39-
Database database = Server.INSTANCE.getDb().getDatabase(client.getDb());
39+
Database database = client.getDatabase();
4040
RedisObject redisObject = database.get(arg.getKey());
4141
if (redisObject == null) {
4242
return SimpleStrings.NONE;

src/main/java/ginyu/cmd/hash/HDel.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ protected void validate(String commandName, Arrays arrays) {
4242
@Override
4343
protected Resp2 doCommand0(HDelArg arg, ChannelHandlerContext ctx) {
4444
Client client = Attributes.getClient(ctx);
45-
Database database = Server.INSTANCE.getDb().getDatabase(client.getDb());
45+
Database database = client.getDatabase();
4646
HashObject hashObject = Validates.validateType(database.get(arg.getKey()), ObjectType.HASH);
4747
if (hashObject == null) {
4848
return Integers.ZERO;

src/main/java/ginyu/cmd/hash/HExists.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ protected void validate(String commandName, Arrays arrays) {
3838
@Override
3939
protected Resp2 doCommand0(HExistsArg arg, ChannelHandlerContext ctx) {
4040
Client client = Attributes.getClient(ctx);
41-
Database database = Server.INSTANCE.getDb().getDatabase(client.getDb());
41+
Database database = client.getDatabase();
4242
HashObject hashObject = Validates.validateType(database.get(arg.getKey()), ObjectType.HASH);
4343
if (hashObject == null) {
4444
return Integers.ZERO;

src/main/java/ginyu/cmd/hash/HGet.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ protected void validate(String commandName, Arrays arrays) {
3838
@Override
3939
protected Resp2 doCommand0(HGetArg arg, ChannelHandlerContext ctx) {
4040
Client client = Attributes.getClient(ctx);
41-
Database database = Server.INSTANCE.getDb().getDatabase(client.getDb());
41+
Database database = client.getDatabase();
4242
HashObject hashObject = Validates.validateType(database.get(arg.getKey()), ObjectType.HASH);
4343
if (hashObject == null) {
4444
return BulkStrings.NULL;

src/main/java/ginyu/cmd/hash/HGetAll.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected void validate(String commandName, Arrays arrays) {
4141
@Override
4242
protected Resp2 doCommand0(KeyArg arg, ChannelHandlerContext ctx) {
4343
Client client = Attributes.getClient(ctx);
44-
Database database = Server.INSTANCE.getDb().getDatabase(client.getDb());
44+
Database database = client.getDatabase();
4545
HashObject hashObject = Validates.validateType(database.get(arg.getKey()), ObjectType.HASH);
4646
if (hashObject == null) {
4747
return Arrays.EMPTY;

src/main/java/ginyu/cmd/hash/HKeys.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ protected void validate(String commandName, Arrays arrays) {
3636
@Override
3737
protected Resp2 doCommand0(KeyArg arg, ChannelHandlerContext ctx) {
3838
Client client = Attributes.getClient(ctx);
39-
Database database = Server.INSTANCE.getDb().getDatabase(client.getDb());
39+
Database database = client.getDatabase();
4040
HashObject hashObject = Validates.validateType(database.get(arg.getKey()), ObjectType.HASH);
4141
if (hashObject == null) {
4242
return Arrays.EMPTY;

src/main/java/ginyu/cmd/hash/HLen.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected void validate(String commandName, Arrays arrays) {
3737
@Override
3838
protected Resp2 doCommand0(KeyArg arg, ChannelHandlerContext ctx) {
3939
Client client = Attributes.getClient(ctx);
40-
Database database = Server.INSTANCE.getDb().getDatabase(client.getDb());
40+
Database database = client.getDatabase();
4141
HashObject hashObject = Validates.validateType(database.get(arg.getKey()), ObjectType.HASH);
4242
if (hashObject == null) {
4343
return Integers.ZERO;

src/main/java/ginyu/cmd/hash/HMGet.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected Resp2 getDefaultValue(Object arg) throws NoSuchMethodException, Invoca
4848
@Override
4949
protected Resp2 doCommand0(HMGetArg arg, ChannelHandlerContext ctx) {
5050
Client client = Attributes.getClient(ctx);
51-
Database database = Server.INSTANCE.getDb().getDatabase(client.getDb());
51+
Database database = client.getDatabase();
5252
HashObject hashObject = Validates.validateType(database.get(arg.getKey()), ObjectType.HASH);
5353
if (hashObject == null) {
5454
return Arrays.createSpecifiedSizeWithNull(arg.getFields().length);

src/main/java/ginyu/cmd/hash/HSet.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected void validate(String commandName, Arrays arrays) {
5454
@Override
5555
protected Resp2 doCommand0(HSetArg arg, ChannelHandlerContext ctx) {
5656
Client client = Attributes.getClient(ctx);
57-
Database database = Server.INSTANCE.getDb().getDatabase(client.getDb());
57+
Database database = client.getDatabase();
5858
HashObject hashObject = Validates.validateType(database.get(arg.getKey()), ObjectType.HASH);
5959
if (hashObject == null) {
6060
hashObject = new HashObject();

src/main/java/ginyu/cmd/hash/HStrLen.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ protected void validate(String commandName, Arrays arrays) {
3838
@Override
3939
protected Resp2 doCommand0(HStrLenArg arg, ChannelHandlerContext ctx) {
4040
Client client = Attributes.getClient(ctx);
41-
Database database = Server.INSTANCE.getDb().getDatabase(client.getDb());
41+
Database database = client.getDatabase();
4242
HashObject hashObject = Validates.validateType(database.get(arg.getKey()), ObjectType.HASH);
4343
if (hashObject == null) {
4444
return Integers.ZERO;

src/main/java/ginyu/cmd/hash/HVals.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ protected void validate(String commandName, Arrays arrays) {
3636
@Override
3737
protected Resp2 doCommand0(KeyArg arg, ChannelHandlerContext ctx) {
3838
Client client = Attributes.getClient(ctx);
39-
Database database = Server.INSTANCE.getDb().getDatabase(client.getDb());
39+
Database database = client.getDatabase();
4040
HashObject hashObject = Validates.validateType(database.get(arg.getKey()), ObjectType.HASH);
4141
if (hashObject == null) {
4242
return Arrays.EMPTY;

src/main/java/ginyu/cmd/list/BPop.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import ginyu.cmd.AbstractRedisCommand;
44
import ginyu.common.Attributes;
55
import ginyu.core.Client;
6-
import ginyu.core.Server;
76
import ginyu.db.Database;
87
import ginyu.event.Events;
8+
import ginyu.event.list.BlockByBPopEvent;
99
import ginyu.object.ListObject;
1010
import ginyu.object.ObjectType;
1111
import ginyu.protocol.Arrays;
@@ -41,7 +41,7 @@ protected void validate(String commandName, Arrays arrays) {
4141
@Override
4242
protected Resp2 doCommand0(BPopArg arg, ChannelHandlerContext ctx) {
4343
Client client = Attributes.getClient(ctx);
44-
Database database = Server.INSTANCE.getDb().getDatabase(client.getDb());
44+
Database database = client.getDatabase();
4545
for (String key : arg.getKeys()) {
4646
ListObject listObject = Validates.validateType(database.get(key), ObjectType.LIST);
4747
if (listObject != null && !listObject.getOriginal().isEmpty()) {
@@ -50,7 +50,7 @@ protected Resp2 doCommand0(BPopArg arg, ChannelHandlerContext ctx) {
5050
}
5151
}
5252
// 执行到这里说明上面的key都不存在,需要进行订阅
53-
Events.post(new BPopEvent(client, ctx, arg, this.isLeft(), arg.getKeys()));
53+
Events.post(new BlockByBPopEvent(client, arg, this.isLeft()));
5454
return null;
5555
}
5656

src/main/java/ginyu/cmd/list/BPopEvent.java

-49
This file was deleted.

src/main/java/ginyu/cmd/list/LIndex.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ protected void validate(String commandName, Arrays arrays) {
3939
@Override
4040
protected Resp2 doCommand0(LIndexArg arg, ChannelHandlerContext ctx) {
4141
Client client = Attributes.getClient(ctx);
42-
Database database = Server.INSTANCE.getDb().getDatabase(client.getDb());
42+
Database database = client.getDatabase();
4343
ListObject listObject = Validates.validateType(database.get(arg.getKey()), ObjectType.LIST);
4444
if (listObject == null) {
4545
return BulkStrings.NULL;

src/main/java/ginyu/cmd/list/LInsert.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ protected void validate(String commandName, Arrays arrays) {
5656
@Override
5757
protected Resp2 doCommand0(LInsertArg arg, ChannelHandlerContext ctx) {
5858
Client client = Attributes.getClient(ctx);
59-
Database database = Server.INSTANCE.getDb().getDatabase(client.getDb());
59+
Database database = client.getDatabase();
6060
ListObject listObject = Validates.validateType(database.get(arg.getKey()), ObjectType.LIST);
6161
if (listObject == null) {
6262
return Integers.ZERO;

src/main/java/ginyu/cmd/list/LLen.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected void validate(String commandName, Arrays arrays) {
3737
@Override
3838
protected Resp2 doCommand0(KeyArg arg, ChannelHandlerContext ctx) {
3939
Client client = Attributes.getClient(ctx);
40-
Database database = Server.INSTANCE.getDb().getDatabase(client.getDb());
40+
Database database = client.getDatabase();
4141
ListObject listObject = Validates.validateType(database.get(arg.getKey()), ObjectType.LIST);
4242
if (listObject == null) {
4343
return Integers.ZERO;

src/main/java/ginyu/cmd/list/LRange.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected void validate(String commandName, Arrays arrays) {
4141
@Override
4242
protected Resp2 doCommand0(LRangeArg arg, ChannelHandlerContext ctx) {
4343
Client client = Attributes.getClient(ctx);
44-
Database database = Server.INSTANCE.getDb().getDatabase(client.getDb());
44+
Database database = client.getDatabase();
4545
ListObject listObject = Validates.validateType(database.get(arg.getKey()), ObjectType.LIST);
4646
if (listObject == null) {
4747
return Arrays.EMPTY;

src/main/java/ginyu/cmd/list/LTrim.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ protected void validate(String commandName, Arrays arrays) {
4242
@Override
4343
protected Resp2 doCommand0(LRangeArg arg, ChannelHandlerContext ctx) {
4444
Client client = Attributes.getClient(ctx);
45-
Database database = Server.INSTANCE.getDb().getDatabase(client.getDb());
45+
Database database = client.getDatabase();
4646
ListObject listObject = Validates.validateType(database.get(arg.getKey()), ObjectType.LIST);
4747
if (listObject == null) {
4848
return SimpleStrings.OK;

0 commit comments

Comments
 (0)