Skip to content

Commit 4e9ccd7

Browse files
author
Meir Shpilraien (Spielrein)
authored
Added avoid_replication_traffic API (#356)
1 parent d1f567f commit 4e9ccd7

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/context/mod.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,28 @@ impl Context {
804804
.into()
805805
}
806806
);
807+
808+
api!(
809+
[RedisModule_AvoidReplicaTraffic],
810+
/// Returns true if a client sent the CLIENT PAUSE command to the server or
811+
/// if Redis Cluster does a manual failover, pausing the clients.
812+
/// This is needed when we have a master with replicas, and want to write,
813+
/// without adding further data to the replication channel, that the replicas
814+
/// replication offset, match the one of the master. When this happens, it is
815+
/// safe to failover the master without data loss.
816+
///
817+
/// However modules may generate traffic by calling commands or directly send
818+
/// data to the replication stream.
819+
///
820+
/// So modules may want to try to avoid very heavy background work that has
821+
/// the effect of creating data to the replication channel, when this function
822+
/// returns true. This is mostly useful for modules that have background
823+
/// garbage collection tasks, or that do writes and replicate such writes
824+
/// periodically in timer callbacks or other periodic callbacks.
825+
pub fn avoid_replication_traffic(&self) -> bool {
826+
unsafe { RedisModule_AvoidReplicaTraffic() == 1 }
827+
}
828+
);
807829
}
808830

809831
extern "C" fn post_notification_job_free_callback<F: FnOnce(&Context)>(pd: *mut c_void) {

0 commit comments

Comments
 (0)