|
25 | 25 | <dependency> |
26 | 26 | <groupId>org.codeba</groupId> |
27 | 27 | <artifactId>redis-keeper-core</artifactId> |
28 | | - <version>2024.0.0</version> |
| 28 | + <version>2024.1.0</version> |
29 | 29 | </dependency> |
30 | 30 |
|
31 | 31 | <dependency> |
32 | 32 | <groupId>org.codeba</groupId> |
33 | 33 | <artifactId>redis-keeper-support</artifactId> |
34 | | - <version>2024.0.0</version> |
| 34 | + <version>2024.1.0</version> |
35 | 35 | </dependency> |
36 | 36 |
|
37 | 37 | #### Gradle |
38 | | - implementation group: 'org.codeba', name: 'redis-keeper-core', version: '2024.0.0' |
| 38 | + implementation group: 'org.codeba', name: 'redis-keeper-core', version: '2024.1.0' |
39 | 39 |
|
40 | | - implementation group: 'org.codeba', name: 'redis-keeper-support', version: '2024.0.0' |
| 40 | + implementation group: 'org.codeba', name: 'redis-keeper-support', version: '2024.1.0' |
41 | 41 |
|
42 | 42 | #### Sbt |
43 | | - libraryDependencies += "org.codeba" % "redis-keeper-core" % "2024.0.0" |
| 43 | + libraryDependencies += "org.codeba" % "redis-keeper-core" % "2024.1.0" |
44 | 44 |
|
45 | | - libraryDependencies += "org.codeba" % "redis-keeper-support" % "2024.0.0" |
| 45 | + libraryDependencies += "org.codeba" % "redis-keeper-support" % "2024.1.0" |
46 | 46 |
|
47 | 47 |
|
48 | 48 | #### Java |
@@ -90,6 +90,254 @@ Optional<CacheTemplate> polledTemplate = provider.pollTemplate("ds2"); |
90 | 90 | Optional<CacheTemplate> randomedTemplate = provider.randomTemplate("ds2"); |
91 | 91 | ``` |
92 | 92 |
|
| 93 | +## Springboot |
| 94 | + |
| 95 | +1. Maven |
| 96 | + |
| 97 | +```java |
| 98 | +<dependency> |
| 99 | + <groupId>org.codeba</groupId> |
| 100 | + <artifactId>redis-keeper-spring-boot-starter</artifactId> |
| 101 | + <version>2024.1.0</version> |
| 102 | +</dependency> |
| 103 | +``` |
| 104 | + |
| 105 | +2. Example datasource configuration as follows: |
| 106 | + |
| 107 | +```yaml |
| 108 | +redis-keeper: |
| 109 | + redis: |
| 110 | + datasource: |
| 111 | + ds1: |
| 112 | + host: localhost |
| 113 | + port: 6379 |
| 114 | + password: yourPass |
| 115 | + invoke-params-print: true |
| 116 | + |
| 117 | + datasources: |
| 118 | + ds2: |
| 119 | + - host: localhost |
| 120 | + port: 6379 |
| 121 | + database: 1 |
| 122 | + password: yourPass |
| 123 | + invoke-params-print: true |
| 124 | + |
| 125 | + - host: localhost |
| 126 | + port: 6379 |
| 127 | + database: 2 |
| 128 | + password: yourPass |
| 129 | + invoke-params-print: true |
| 130 | + |
| 131 | +``` |
| 132 | + |
| 133 | +3. Examples of common methods: |
| 134 | + |
| 135 | +```java |
| 136 | +@SpringBootTest |
| 137 | +public class AppTest { |
| 138 | + |
| 139 | + @Autowired |
| 140 | + private CacheTemplateProvider<CacheTemplate> provider; |
| 141 | + |
| 142 | + @Test |
| 143 | + public void test() { |
| 144 | + String key = "foo"; |
| 145 | + String value = "bar"; |
| 146 | + |
| 147 | + final CacheTemplate cacheTemplate = provider.getTemplate("ds1").get(); |
| 148 | + // set |
| 149 | + cacheTemplate.set(key, value); |
| 150 | + cacheTemplate.setObject(key, value); |
| 151 | + // get |
| 152 | + cacheTemplate.get(key); |
| 153 | + cacheTemplate.getObject(key); |
| 154 | + cacheTemplate.getLong(key); |
| 155 | + cacheTemplate.getDouble(key); |
| 156 | + // incr |
| 157 | + cacheTemplate.incr(key); |
| 158 | + // set get bit |
| 159 | + cacheTemplate.setBit(key, 7, true); |
| 160 | + cacheTemplate.getBit(key, 7); |
| 161 | + // del exists expire ttl unlink |
| 162 | + cacheTemplate.del(key); |
| 163 | + cacheTemplate.exists(key); |
| 164 | + cacheTemplate.expire(key, 10, TimeUnit.SECONDS); |
| 165 | + cacheTemplate.expireAt(key, System.currentTimeMillis()); |
| 166 | + cacheTemplate.ttl(key); |
| 167 | + cacheTemplate.unlink(key); |
| 168 | + // geo |
| 169 | + cacheTemplate.geoAdd(key, 13.361389, 38.115556, "Sicily"); |
| 170 | + cacheTemplate.geoAdd(key, 15.087269, 37.502669, "Palermo"); |
| 171 | + cacheTemplate.geoDist(key, "Sicily", "Palermo", "km"); |
| 172 | + // hash |
| 173 | + cacheTemplate.hSet(key, "field1", value); |
| 174 | + cacheTemplate.hGet(key, "field1"); |
| 175 | + // hyberloglog |
| 176 | + cacheTemplate.pfAdd(key, Arrays.asList("a")); |
| 177 | + cacheTemplate.pfCount(key); |
| 178 | + // list |
| 179 | + cacheTemplate.rPush(key, "world", "hello"); |
| 180 | + cacheTemplate.lRange(key, 0, -1); |
| 181 | + // set |
| 182 | + cacheTemplate.sAdd(key, "hello"); |
| 183 | + cacheTemplate.sAdd(key, "world"); |
| 184 | + cacheTemplate.sAdd(key, "world"); |
| 185 | + cacheTemplate.sMembers(key); |
| 186 | + // zset |
| 187 | + cacheTemplate.zAdd(key, 1, "one"); |
| 188 | + cacheTemplate.zAdd(key, 2, "two"); |
| 189 | + cacheTemplate.zAdd(key, 3, "three"); |
| 190 | + cacheTemplate.zRange(key, 0, -1); |
| 191 | + // bloom filter |
| 192 | + cacheTemplate.bfReserve(key, 1000, 0.01); |
| 193 | + cacheTemplate.bfAdd(key, "item1"); |
| 194 | + cacheTemplate.bfAdd(key, "item1"); |
| 195 | + cacheTemplate.bfExists(key, "item2"); |
| 196 | + // lock |
| 197 | + cacheTemplate.tryLock(key, 3, TimeUnit.SECONDS); |
| 198 | + cacheTemplate.unlock(key); |
| 199 | + cacheTemplate.forceUnlock(key); |
| 200 | + // rate limiter |
| 201 | + cacheTemplate.trySetRateLimiter(key, 100, 1); |
| 202 | + cacheTemplate.tryAcquire(key); |
| 203 | + cacheTemplate.tryAcquire(key, 10); |
| 204 | + } |
| 205 | + |
| 206 | +} |
| 207 | + |
| 208 | +``` |
| 209 | + |
| 210 | +## Unlimited Expansion |
| 211 | + |
| 212 | +#### CacheTemplate adds new custom methods |
| 213 | + |
| 214 | +1. Maven |
| 215 | + |
| 216 | +```java |
| 217 | +<dependency> |
| 218 | + <groupId>org.codeba</groupId> |
| 219 | + <artifactId>redis-keeper-spring-boot-starter</artifactId> |
| 220 | + <version>2024.1.0</version> |
| 221 | +</dependency> |
| 222 | +``` |
| 223 | + |
| 224 | +2. CacheTemplate adds new custom methods |
| 225 | + |
| 226 | +MyCacheTemplate.java |
| 227 | + |
| 228 | +```java |
| 229 | +import org.codeba.redis.keeper.support.CacheKeeperConfig; |
| 230 | +import org.codeba.redis.keeper.support.DefaultRedissonTemplate; |
| 231 | + |
| 232 | +public class MyCacheTemplate extends DefaultRedissonTemplate implements CacheTemplate { |
| 233 | + |
| 234 | + public MyCacheTemplate(CacheKeeperConfig cacheKeeperConfig) { |
| 235 | + super(cacheKeeperConfig); |
| 236 | + } |
| 237 | + |
| 238 | + public void test() { |
| 239 | + final RedissonClient redissonClient = getDataSource(); |
| 240 | + redissonClient.someMehotd(); |
| 241 | + System.out.println("hello world"); |
| 242 | + } |
| 243 | + |
| 244 | +} |
| 245 | +``` |
| 246 | + |
| 247 | +MyCacheDatasource.java |
| 248 | + |
| 249 | +```java |
| 250 | +import org.codeba.redis.keeper.support.CacheDatasource; |
| 251 | +import org.codeba.redis.keeper.support.CacheKeeperConfig; |
| 252 | + |
| 253 | +public class MyCacheDatasource implements CacheDatasource<MyCacheTemplate> { |
| 254 | + |
| 255 | + @Override |
| 256 | + public MyCacheTemplate instantTemplate(CacheKeeperConfig config) { |
| 257 | + return new MyCacheTemplate(config); |
| 258 | + } |
| 259 | + |
| 260 | +} |
| 261 | +``` |
| 262 | + |
| 263 | +Enabling the new MyCacheDatasource |
| 264 | + |
| 265 | +```java |
| 266 | +import org.codeba.redis.keeper.support.CacheDatasource; |
| 267 | +import org.springframework.context.annotation.Bean; |
| 268 | +import org.springframework.context.annotation.Configuration; |
| 269 | + |
| 270 | +@Configuration |
| 271 | +public class MyConfiguration { |
| 272 | + |
| 273 | + @Bean |
| 274 | + public CacheDatasource<MyCacheTemplate> cacheDatasource() { |
| 275 | + return new MyCacheDatasource(); |
| 276 | + } |
| 277 | + |
| 278 | +} |
| 279 | +``` |
| 280 | + |
| 281 | +3. Enabling the new CacheTemplate |
| 282 | + |
| 283 | +```java |
| 284 | +@SpringBootTest |
| 285 | +public class AppTest { |
| 286 | + |
| 287 | + @Autowired |
| 288 | + private CacheTemplateProvider<MyCacheTemplate> myProvider; |
| 289 | + |
| 290 | + @Test |
| 291 | + public void testMyProvider() { |
| 292 | + final Optional<MyCacheTemplate> templateOptional = myProvider.getTemplate("ds1"); |
| 293 | + |
| 294 | + if (templateOptional.isPresent()) { |
| 295 | + final MyCacheTemplate cacheTemplate = templateOptional.get(); |
| 296 | + |
| 297 | + // Custom Methods |
| 298 | + cacheTemplate.test(); |
| 299 | + |
| 300 | + } |
| 301 | + } |
| 302 | + |
| 303 | +} |
| 304 | +``` |
| 305 | + |
| 306 | +#### CacheDatasource custom redisson configuration |
| 307 | + |
| 308 | +1. Maven |
| 309 | + |
| 310 | +```java |
| 311 | +<dependency> |
| 312 | + <groupId>org.codeba</groupId> |
| 313 | + <artifactId>redis-keeper-spring-boot-starter</artifactId> |
| 314 | + <version>2024.1.0</version> |
| 315 | +</dependency> |
| 316 | +``` |
| 317 | + |
| 318 | +2. For example, custom setting the encoding of redisson serialization and deserialization while enabling the new CacheDatasource. |
| 319 | + |
| 320 | +```java |
| 321 | +import org.codeba.redis.keeper.support.CacheDatasource; |
| 322 | +import org.springframework.context.annotation.Bean; |
| 323 | +import org.springframework.context.annotation.Configuration; |
| 324 | + |
| 325 | +@Configuration |
| 326 | +public class MyConfiguration { |
| 327 | + |
| 328 | + @Bean |
| 329 | + public CacheDatasource<CacheTemplate> cacheDatasource() { |
| 330 | + return new DefaultCacheDatasource(){ |
| 331 | + @Override |
| 332 | + public Consumer<CacheKeeperConfig> configPostProcessor(Consumer<CacheKeeperConfig> consumer) { |
| 333 | + return v -> v.getConfig().setCodec(new JsonJacksonCodec()); |
| 334 | + } |
| 335 | + }; |
| 336 | + } |
| 337 | + |
| 338 | +} |
| 339 | +``` |
| 340 | + |
93 | 341 | ## More Samples |
94 | 342 |
|
95 | 343 | 1. [Redis-Keeper only](https://github.com/codebaorg/redis-keeper/tree/main/redis-keeper-example/redis-keeper-example-standalone) |
|
0 commit comments