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

31 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-07 07:16 +0000

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): 

15 """Returns a (host, port) pair for the given ``service_name``""" 

16 return self.execute_command("SENTINEL GET-MASTER-ADDR-BY-NAME", service_name) 

17 

18 def sentinel_master(self, service_name): 

19 """Returns a dictionary containing the specified masters state.""" 

20 return self.execute_command("SENTINEL MASTER", service_name) 

21 

22 def sentinel_masters(self): 

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

24 return self.execute_command("SENTINEL MASTERS") 

25 

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

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

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

29 

30 def sentinel_remove(self, name): 

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

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

33 

34 def sentinel_sentinels(self, service_name): 

35 """Returns a list of sentinels for ``service_name``""" 

36 return self.execute_command("SENTINEL SENTINELS", service_name) 

37 

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

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

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

41 

42 def sentinel_slaves(self, service_name): 

43 """Returns a list of slaves for ``service_name``""" 

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

45 

46 def sentinel_reset(self, pattern): 

47 """ 

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

49 The pattern argument is a glob-style pattern. 

50 

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

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

53 discovered and associated with the master. 

54 """ 

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

56 

57 def sentinel_failover(self, new_master_name): 

58 """ 

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

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

61 configuration will be published so that the other Sentinels will 

62 update their configurations). 

63 """ 

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

65 

66 def sentinel_ckquorum(self, new_master_name): 

67 """ 

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

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

70 authorize the failover. 

71 

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

73 Sentinel deployment is ok. 

74 """ 

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

76 

77 def sentinel_flushconfig(self): 

78 """ 

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

80 current Sentinel state. 

81 

82 Normally Sentinel rewrites the configuration every time something 

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

84 is persisted on disk across restart). 

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

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

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

88 rewrite the configuration file is handy. 

89 

90 This command works even if the previous configuration file is 

91 completely missing. 

92 """ 

93 return self.execute_command("SENTINEL FLUSHCONFIG") 

94 

95 

96class AsyncSentinelCommands(SentinelCommands): 

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

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

99 super().sentinel(*args)