Skip to content

Commit 3013d7e

Browse files
author
codeba
committed
feat: Support more redis commands
1 parent 469a35e commit 3013d7e

File tree

25 files changed

+7349
-1607
lines changed

25 files changed

+7349
-1607
lines changed

redis-keeper-core/src/main/java/org/codeba/redis/keeper/core/CacheTemplate.java

Lines changed: 130 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/*
22
* Copyright (c) 2024-2025, redis-keeper ([email protected])
33
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
1515
*/
1616

1717
package org.codeba.redis.keeper.core;
@@ -1441,6 +1441,14 @@ public interface CacheTemplate {
14411441
*/
14421442
boolean lRem(String key, Object element);
14431443

1444+
/**
1445+
* L rem all.
1446+
*
1447+
* @param key the key
1448+
* @param element the element
1449+
*/
1450+
void lRemAll(String key, Object element);
1451+
14441452
/**
14451453
* L rem async completable future.
14461454
*
@@ -1450,6 +1458,33 @@ public interface CacheTemplate {
14501458
*/
14511459
CompletableFuture<Boolean> lRemAsync(String key, Object element);
14521460

1461+
/**
1462+
* L rem all async completable future.
1463+
*
1464+
* @param key the key
1465+
* @param element the element
1466+
* @return the completable future
1467+
*/
1468+
CompletableFuture<Boolean> lRemAllAsync(String key, Object element);
1469+
1470+
/**
1471+
* L rem optional.
1472+
*
1473+
* @param key the key
1474+
* @param index the index
1475+
* @return the optional
1476+
*/
1477+
Optional<Object> lRem(String key, int index);
1478+
1479+
/**
1480+
* L rem async completable future.
1481+
*
1482+
* @param key the key
1483+
* @param index the index
1484+
* @return the completable future
1485+
*/
1486+
CompletableFuture<Object> lRemAsync(String key, int index);
1487+
14531488
/**
14541489
* L set.
14551490
*
@@ -3293,6 +3328,22 @@ public interface CacheTemplate {
32933328
*/
32943329
boolean bfReserve(String key, long expectedInsertions, double falseProbability);
32953330

3331+
/**
3332+
* Delete bf boolean.
3333+
*
3334+
* @param key the key
3335+
* @return the boolean
3336+
*/
3337+
boolean deleteBf(String key);
3338+
3339+
/**
3340+
* Delete bf async completable future.
3341+
*
3342+
* @param key the key
3343+
* @return the completable future
3344+
*/
3345+
CompletableFuture<Boolean> deleteBfAsync(String key);
3346+
32963347
/**
32973348
* Try lock boolean.
32983349
*
@@ -3415,6 +3466,44 @@ public interface CacheTemplate {
34153466
*/
34163467
CompletableFuture<Long> existsAsync(String... keys);
34173468

3469+
/**
3470+
* Expire boolean.
3471+
*
3472+
* @param key the key
3473+
* @param timeToLive the time to live
3474+
* @param timeUnit the time unit
3475+
* @return the boolean
3476+
*/
3477+
boolean expire(String key, long timeToLive, TimeUnit timeUnit);
3478+
3479+
/**
3480+
* Expire async completable future.
3481+
*
3482+
* @param key the key
3483+
* @param timeToLive the time to live
3484+
* @param timeUnit the time unit
3485+
* @return the completable future
3486+
*/
3487+
CompletableFuture<Boolean> expireAsync(String key, long timeToLive, TimeUnit timeUnit);
3488+
3489+
/**
3490+
* Expire at boolean.
3491+
*
3492+
* @param key the key
3493+
* @param timestamp the timestamp
3494+
* @return the boolean
3495+
*/
3496+
boolean expireAt(String key, long timestamp);
3497+
3498+
/**
3499+
* Expire at async completable future.
3500+
*
3501+
* @param key the key
3502+
* @param timestamp the timestamp
3503+
* @return the completable future
3504+
*/
3505+
CompletableFuture<Boolean> expireAtAsync(String key, long timestamp);
3506+
34183507
/**
34193508
* Del long.
34203509
*
@@ -3431,6 +3520,22 @@ public interface CacheTemplate {
34313520
*/
34323521
CompletableFuture<Long> delAsync(String... keys);
34333522

3523+
/**
3524+
* Unlink long.
3525+
*
3526+
* @param keys the keys
3527+
* @return the long
3528+
*/
3529+
long unlink(String... keys);
3530+
3531+
/**
3532+
* Unlink async completable future.
3533+
*
3534+
* @param keys the keys
3535+
* @return the completable future
3536+
*/
3537+
CompletableFuture<Long> unlinkAsync(String... keys);
3538+
34343539
/**
34353540
* Ttl long.
34363541
*
@@ -3447,6 +3552,22 @@ public interface CacheTemplate {
34473552
*/
34483553
CompletableFuture<Long> ttlAsync(String key);
34493554

3555+
/**
3556+
* P ttl long.
3557+
*
3558+
* @param key the key
3559+
* @return the long
3560+
*/
3561+
long pTTL(String key);
3562+
3563+
/**
3564+
* P ttl async completable future.
3565+
*
3566+
* @param key the key
3567+
* @return the completable future
3568+
*/
3569+
CompletableFuture<Long> pTTLAsync(String key);
3570+
34503571
/**
34513572
* Scan iterable.
34523573
*

redis-keeper-example/pom.xml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<!--
22
~ Copyright (c) 2024-2025, redis-keeper ([email protected])
33
~
4-
~ Licensed under the Apache License, Version 2.0 (the "License");
5-
~ you may not use this file except in compliance with the License.
6-
~ You may obtain a copy of the License at
4+
~ Licensed under the Apache License, Version 2.0 (the "License");
5+
~ you may not use this file except in compliance with the License.
6+
~ You may obtain a copy of the License at
77
~
8-
~ http://www.apache.org/licenses/LICENSE-2.0
8+
~ http://www.apache.org/licenses/LICENSE-2.0
99
~
10-
~ Unless required by applicable law or agreed to in writing, software
11-
~ distributed under the License is distributed on an "AS IS" BASIS,
12-
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
~ See the License for the specific language governing permissions and
14-
~ limitations under the License.
10+
~ Unless required by applicable law or agreed to in writing, software
11+
~ distributed under the License is distributed on an "AS IS" BASIS,
12+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
~ See the License for the specific language governing permissions and
14+
~ limitations under the License.
1515
-->
1616

1717
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -21,7 +21,7 @@
2121
<parent>
2222
<groupId>org.springframework.boot</groupId>
2323
<artifactId>spring-boot-starter-parent</artifactId>
24-
<version>2.7.0</version>
24+
<version>2.7.12</version>
2525
<relativePath/>
2626
</parent>
2727

redis-keeper-spring/src/main/java/org/codeba/redis/keeper/spring/CacheTemplateProxy.java

Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/*
22
* Copyright (c) 2024-2025, redis-keeper ([email protected])
33
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
1515
*/
1616

1717
package org.codeba.redis.keeper.spring;
@@ -22,12 +22,40 @@
2222
import org.codeba.redis.keeper.core.CacheTemplateProvider;
2323
import org.codeba.redis.keeper.core.Provider;
2424

25+
import java.lang.reflect.InvocationHandler;
26+
import java.lang.reflect.Method;
27+
import java.lang.reflect.Proxy;
28+
import java.util.Optional;
29+
2530
/**
2631
* The type Cache template proxy.
2732
*
2833
* @author codeba
2934
*/
30-
public class CacheTemplateProxy {
35+
public class CacheTemplateProxy implements InvocationHandler {
36+
private String datasource;
37+
private CacheDatasourceStatus status;
38+
private CacheTemplateProvider<?> templateProvider;
39+
40+
/**
41+
* Instantiates a new Cache template proxy.
42+
*
43+
* @param datasource the datasource
44+
*/
45+
public CacheTemplateProxy(String datasource) {
46+
this.datasource = datasource;
47+
}
48+
49+
/**
50+
* Instantiates a new Cache template proxy.
51+
*
52+
* @param datasource the datasource
53+
* @param status the status
54+
*/
55+
public CacheTemplateProxy(String datasource, CacheDatasourceStatus status) {
56+
this.datasource = datasource;
57+
this.status = status;
58+
}
3159

3260
/**
3361
* As template cache template.
@@ -59,7 +87,10 @@ public static CacheTemplate asTemplate(final String datasource, final CacheDatas
5987
* @return the t
6088
*/
6189
public static <T> T asTemplate(final String datasource, Class<T> templateClass) {
62-
return (T) getInvokeTemplate(datasource, null);
90+
return (T) Proxy.newProxyInstance(
91+
templateClass.getClassLoader(),
92+
new Class[]{templateClass},
93+
new CacheTemplateProxy(datasource));
6394
}
6495

6596
/**
@@ -72,13 +103,30 @@ public static <T> T asTemplate(final String datasource, Class<T> templateClass)
72103
* @return the t
73104
*/
74105
public static <T> T asTemplate(final String datasource, final CacheDatasourceStatus status, Class<T> templateClass) {
75-
return (T) getInvokeTemplate(datasource, status);
106+
return (T) Proxy.newProxyInstance(
107+
templateClass.getClassLoader(),
108+
new Class[]{templateClass},
109+
new CacheTemplateProxy(datasource, status));
110+
}
111+
112+
@Override
113+
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
114+
final String key = Provider.keyWithStatus(this.datasource, this.status);
115+
final Optional<?> template = getTemplateProvider().getTemplate(key);
116+
return method.invoke(template.get(), args);
76117
}
77118

78-
private static Object getInvokeTemplate(final String datasource, final CacheDatasourceStatus status) {
79-
final CacheTemplateProvider provider = ApplicationContextUtil.getBean(CacheTemplateProvider.class);
80-
final String key = Provider.keyWithStatus(datasource, status);
81-
return provider.getTemplate(key).get();
119+
/**
120+
* Gets template provider.
121+
*
122+
* @return the template provider
123+
*/
124+
private CacheTemplateProvider<?> getTemplateProvider() {
125+
if (this.templateProvider == null) {
126+
templateProvider = ApplicationContextUtil.getBean(CacheTemplateProvider.class);
127+
}
128+
return this.templateProvider;
82129
}
83130

131+
84132
}

redis-keeper-support/src/main/java/org/codeba/redis/keeper/support/CacheDatasource.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/*
22
* Copyright (c) 2024-2025, redis-keeper ([email protected])
33
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
1515
*/
1616

1717
package org.codeba.redis.keeper.support;

redis-keeper-support/src/main/java/org/codeba/redis/keeper/support/CacheKeeperConfig.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/*
22
* Copyright (c) 2024-2025, redis-keeper ([email protected])
33
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
1515
*/
1616

1717
package org.codeba.redis.keeper.support;

0 commit comments

Comments
 (0)