Feature - MapPutListener, MapRemoveListener added to RMap object. #220

pull/5038/head
Nikita Koksharov 2 years ago
parent 7b1d26963b
commit da23ae3d6a

@ -19,6 +19,8 @@ import io.netty.buffer.ByteBuf;
import io.netty.util.ReferenceCountUtil;
import org.redisson.api.*;
import org.redisson.api.MapOptions.WriteMode;
import org.redisson.api.listener.MapPutListener;
import org.redisson.api.listener.MapRemoveListener;
import org.redisson.api.mapreduce.RMapReduce;
import org.redisson.client.RedisClient;
import org.redisson.client.codec.Codec;
@ -1888,4 +1890,28 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
writeBehindService.stop(getRawName());
}
}
@Override
public int addListener(ObjectListener listener) {
if (listener instanceof MapPutListener) {
return addListener("__keyevent@*:hset", (MapPutListener) listener, MapPutListener::onPut);
}
if (listener instanceof MapRemoveListener) {
return addListener("__keyevent@*:hdel", (MapRemoveListener) listener, MapRemoveListener::onRemove);
}
return super.addListener(listener);
}
@Override
public RFuture<Integer> addListenerAsync(ObjectListener listener) {
if (listener instanceof MapPutListener) {
return addListenerAsync("__keyevent@*:hset", (MapPutListener) listener, MapPutListener::onPut);
}
if (listener instanceof MapRemoveListener) {
return addListenerAsync("__keyevent@*:hdel", (MapRemoveListener) listener, MapRemoveListener::onRemove);
}
return super.addListenerAsync(listener);
}
}

@ -623,4 +623,17 @@ public interface RMap<K, V> extends ConcurrentMap<K, V>, RExpirable, RMapAsync<K
*/
Set<java.util.Map.Entry<K, V>> entrySet(int count);
/**
* Adds object event listener
*
* @see org.redisson.api.listener.MapPutListener
* @see org.redisson.api.listener.MapRemoveListener
* @see org.redisson.api.ExpiredObjectListener
* @see org.redisson.api.DeletedObjectListener
*
* @param listener object event listener
* @return listener id
*/
int addListener(ObjectListener listener);
}

@ -418,4 +418,17 @@ public interface RMapAsync<K, V> extends RExpirableAsync {
*/
RFuture<Boolean> clearAsync();
/**
* Adds object event listener
*
* @see org.redisson.api.listener.MapPutListener
* @see org.redisson.api.listener.MapRemoveListener
* @see org.redisson.api.ExpiredObjectListener
* @see org.redisson.api.DeletedObjectListener
*
* @param listener - object event listener
* @return listener id
*/
RFuture<Integer> addListenerAsync(ObjectListener listener);
}

@ -619,4 +619,17 @@ public interface RMapReactive<K, V> extends RExpirableReactive {
*/
RLockReactive getLock(K key);
/**
* Adds object event listener
*
* @see org.redisson.api.listener.MapPutListener
* @see org.redisson.api.listener.MapRemoveListener
* @see org.redisson.api.ExpiredObjectListener
* @see org.redisson.api.DeletedObjectListener
*
* @param listener object event listener
* @return listener id
*/
Mono<Integer> addListener(ObjectListener listener);
}

@ -622,4 +622,18 @@ public interface RMapRx<K, V> extends RExpirableRx {
*/
RLockRx getLock(K key);
/**
* Adds object event listener
*
* @see org.redisson.api.listener.MapPutListener
* @see org.redisson.api.listener.MapRemoveListener
* @see org.redisson.api.ExpiredObjectListener
* @see org.redisson.api.DeletedObjectListener
*
* @param listener object event listener
* @return listener id
*/
Single<Integer> addListener(ObjectListener listener);
}

@ -0,0 +1,36 @@
/**
* Copyright (c) 2013-2022 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.redisson.api.listener;
import org.redisson.api.ObjectListener;
/**
* Redisson Object Event listener for <b>hset</b> event published by Redis.
* <p>
* Redis notify-keyspace-events setting should contain Eh letters
*
* @author Nikita Koksharov
*/
public interface MapPutListener extends ObjectListener {
/**
* Invoked when entry added to RMap object
*
* @param name object name
*/
void onPut(String name);
}

@ -0,0 +1,36 @@
/**
* Copyright (c) 2013-2022 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.redisson.api.listener;
import org.redisson.api.ObjectListener;
/**
* Redisson Object Event listener for <b>hdel</b> event published by Redis.
* <p>
* Redis notify-keyspace-events setting should contain Eh letters
*
* @author Nikita Koksharov
*/
public interface MapRemoveListener extends ObjectListener {
/**
* Invoked when entry removed from RMap object
*
* @param name object name
*/
void onRemove(String name);
}
Loading…
Cancel
Save