2222import lombok .extern .slf4j .Slf4j ;
2323import org .apache .commons .collections4 .CollectionUtils ;
2424import org .apache .commons .collections4 .MapUtils ;
25- import org .redisson .api .RAtomicLong ;
26- import org .redisson .api .RMap ;
27- import org .redisson .api .RMapCache ;
28- import org .redisson .api .RedissonClient ;
25+ import org .redisson .api .*;
2926import org .redisson .api .map .event .MapEntryListener ;
3027import org .redisson .spring .cache .RedissonSpringCacheManager ;
3128import org .springframework .cache .CacheManager ;
@@ -149,6 +146,34 @@ public <T> T getItemFromHash(String key) {
149146 return null ;
150147 }
151148
149+ @ Override
150+ public void addItemsToCache (String cacheName , Map <String , Object > items ) {
151+ RBatch batch = redisClient .createBatch ();
152+ RMapCacheAsync <Object , Object > map = batch .getMapCache (cacheName );
153+ for (Map .Entry <String , Object > item : items .entrySet ()) {
154+ map .fastPutAsync (item .getKey (), new CacheElement (item .getValue (), instanceID ));
155+ }
156+ batch .execute ();
157+ CentralCacheType centralCacheType = getCacheType (cacheName );
158+ if (centralCacheType == CentralCacheType .STREAM_SYNCED_LOCAL ) {
159+ sendCacheClearMessage (cacheName );
160+ }
161+ }
162+
163+ @ Override
164+ public void addItemsToCache (String cacheName , Map <String , Object > items , Long timeToLive , TimeUnit timeUnit ) {
165+ RBatch batch = redisClient .createBatch ();
166+ RMapCacheAsync <Object , Object > map = batch .getMapCache (cacheName );
167+ for (Map .Entry <String , Object > item : items .entrySet ()) {
168+ map .fastPutAsync (item .getKey (), new CacheElement (item .getValue (), instanceID ), timeToLive , timeUnit );
169+ }
170+ batch .execute ();
171+ CentralCacheType centralCacheType = getCacheType (cacheName );
172+ if (centralCacheType == CentralCacheType .STREAM_SYNCED_LOCAL ) {
173+ sendCacheClearMessage (cacheName );
174+ }
175+ }
176+
152177 public void addItemToCache (String cacheName , String key , Object value , Long timeToLive , Long timeToIdle , TimeUnit timeUnit ) {
153178 CentralCacheType centralCacheType = getCacheType (cacheName );
154179 insertIntoCentralCache (cacheName , key , value , timeToLive , timeToIdle , timeUnit );
@@ -157,13 +182,38 @@ public void addItemToCache(String cacheName, String key, Object value, Long time
157182 }
158183 }
159184
185+ @ Override
186+ public void addItemsToCache (String cacheName , Map <String , Object > items , Long timeToLive , Long timeToIdle , TimeUnit timeUnit ) {
187+ RBatch batch = redisClient .createBatch ();
188+ RMapCacheAsync <Object , Object > map = batch .getMapCache (cacheName );
189+ for (Map .Entry <String , Object > item : items .entrySet ()) {
190+ map .fastPutAsync (item .getKey (), new CacheElement (item .getValue (), instanceID ), timeToLive , timeUnit );
191+ }
192+ batch .execute ();
193+ CentralCacheType centralCacheType = getCacheType (cacheName );
194+ if (centralCacheType == CentralCacheType .STREAM_SYNCED_LOCAL ) {
195+ sendCacheClearMessage (cacheName );
196+ }
197+ }
198+
160199 @ Override
161200 public void addItemToHash (String key , Object value , Long timeToLive , TimeUnit timeUnit ) {
162201 RMap <String , CacheElement > map = redisClient .getMap (key );
163202 map .fastPut (key , new CacheElement (value , instanceID ));
164203 map .expire (Duration .of (timeToLive , timeUnit .toChronoUnit ()));
165204 }
166205
206+ @ Override
207+ public void addItemsToHash (Map <String , Object > items , Long timeToLive , TimeUnit timeUnit ) {
208+ RBatch batch = redisClient .createBatch ();
209+ for (Map .Entry <String , Object > item : items .entrySet ()) {
210+ RMapAsync <String , CacheElement > map = batch .getMap (item .getKey ());
211+ map .fastPutAsync (item .getKey (), new CacheElement (item .getValue (), instanceID ));
212+ map .expireAsync (Duration .of (timeToLive , timeUnit .toChronoUnit ()));
213+ }
214+ batch .execute ();
215+ }
216+
167217 @ Override
168218 public void removeItemFromHash (String key ) {
169219 RMap <String , CacheElement > map = redisClient .getMap (key );
0 commit comments