Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/redis/commands/sentinel.py: 55%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

31 statements  

1import warnings 

2 

3 

4class SentinelCommands: 

5 """ 

6 A class containing the commands specific to redis sentinel. This class is 

7 to be used as a mixin. 

8 """ 

9 

10 def sentinel(self, *args): 

11 """Redis Sentinel's SENTINEL command.""" 

12 warnings.warn(DeprecationWarning("Use the individual sentinel_* methods")) 

13 

14 def sentinel_get_master_addr_by_name(self, service_name, return_responses=False): 

15 """ 

16 Returns a (host, port) pair for the given ``service_name`` when return_responses is True, 

17 otherwise returns a boolean value that indicates if the command was successful. 

18 """ 

19 return self.execute_command( 

20 "SENTINEL GET-MASTER-ADDR-BY-NAME", 

21 service_name, 

22 once=True, 

23 return_responses=return_responses, 

24 ) 

25 

26 def sentinel_master(self, service_name, return_responses=False): 

27 """ 

28 Returns a dictionary containing the specified masters state, when return_responses is True, 

29 otherwise returns a boolean value that indicates if the command was successful. 

30 """ 

31 return self.execute_command( 

32 "SENTINEL MASTER", service_name, return_responses=return_responses 

33 ) 

34 

35 def sentinel_masters(self): 

36 """ 

37 Returns a list of dictionaries containing each master's state. 

38 

39 Important: This function is called by the Sentinel implementation and is 

40 called directly on the Redis standalone client for sentinels, 

41 so it doesn't support the "once" and "return_responses" options. 

42 """ 

43 return self.execute_command("SENTINEL MASTERS") 

44 

45 def sentinel_monitor(self, name, ip, port, quorum): 

46 """Add a new master to Sentinel to be monitored""" 

47 return self.execute_command("SENTINEL MONITOR", name, ip, port, quorum) 

48 

49 def sentinel_remove(self, name): 

50 """Remove a master from Sentinel's monitoring""" 

51 return self.execute_command("SENTINEL REMOVE", name) 

52 

53 def sentinel_sentinels(self, service_name, return_responses=False): 

54 """ 

55 Returns a list of sentinels for ``service_name``, when return_responses is True, 

56 otherwise returns a boolean value that indicates if the command was successful. 

57 """ 

58 return self.execute_command( 

59 "SENTINEL SENTINELS", service_name, return_responses=return_responses 

60 ) 

61 

62 def sentinel_set(self, name, option, value): 

63 """Set Sentinel monitoring parameters for a given master""" 

64 return self.execute_command("SENTINEL SET", name, option, value) 

65 

66 def sentinel_slaves(self, service_name): 

67 """ 

68 Returns a list of slaves for ``service_name`` 

69 

70 Important: This function is called by the Sentinel implementation and is 

71 called directly on the Redis standalone client for sentinels, 

72 so it doesn't support the "once" and "return_responses" options. 

73 """ 

74 return self.execute_command("SENTINEL SLAVES", service_name) 

75 

76 def sentinel_reset(self, pattern): 

77 """ 

78 This command will reset all the masters with matching name. 

79 The pattern argument is a glob-style pattern. 

80 

81 The reset process clears any previous state in a master (including a 

82 failover in progress), and removes every slave and sentinel already 

83 discovered and associated with the master. 

84 """ 

85 return self.execute_command("SENTINEL RESET", pattern, once=True) 

86 

87 def sentinel_failover(self, new_master_name): 

88 """ 

89 Force a failover as if the master was not reachable, and without 

90 asking for agreement to other Sentinels (however a new version of the 

91 configuration will be published so that the other Sentinels will 

92 update their configurations). 

93 """ 

94 return self.execute_command("SENTINEL FAILOVER", new_master_name) 

95 

96 def sentinel_ckquorum(self, new_master_name): 

97 """ 

98 Check if the current Sentinel configuration is able to reach the 

99 quorum needed to failover a master, and the majority needed to 

100 authorize the failover. 

101 

102 This command should be used in monitoring systems to check if a 

103 Sentinel deployment is ok. 

104 """ 

105 return self.execute_command("SENTINEL CKQUORUM", new_master_name, once=True) 

106 

107 def sentinel_flushconfig(self): 

108 """ 

109 Force Sentinel to rewrite its configuration on disk, including the 

110 current Sentinel state. 

111 

112 Normally Sentinel rewrites the configuration every time something 

113 changes in its state (in the context of the subset of the state which 

114 is persisted on disk across restart). 

115 However sometimes it is possible that the configuration file is lost 

116 because of operation errors, disk failures, package upgrade scripts or 

117 configuration managers. In those cases a way to to force Sentinel to 

118 rewrite the configuration file is handy. 

119 

120 This command works even if the previous configuration file is 

121 completely missing. 

122 """ 

123 return self.execute_command("SENTINEL FLUSHCONFIG") 

124 

125 

126class AsyncSentinelCommands(SentinelCommands): 

127 async def sentinel(self, *args) -> None: 

128 """Redis Sentinel's SENTINEL command.""" 

129 super().sentinel(*args)