|
1 | 1 | /** Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 */ |
2 | 2 | package glide.api; |
3 | 3 |
|
| 4 | +import static command_request.CommandRequestOuterClass.RequestType.Asking; |
4 | 5 | import static command_request.CommandRequestOuterClass.RequestType.ClientGetName; |
5 | 6 | import static command_request.CommandRequestOuterClass.RequestType.ClientId; |
6 | 7 | import static command_request.CommandRequestOuterClass.RequestType.ClusterAddSlots; |
7 | 8 | import static command_request.CommandRequestOuterClass.RequestType.ClusterAddSlotsRange; |
| 9 | +import static command_request.CommandRequestOuterClass.RequestType.ClusterBumpEpoch; |
| 10 | +import static command_request.CommandRequestOuterClass.RequestType.ClusterCountFailureReports; |
8 | 11 | import static command_request.CommandRequestOuterClass.RequestType.ClusterCountKeysInSlot; |
9 | 12 | import static command_request.CommandRequestOuterClass.RequestType.ClusterDelSlots; |
10 | 13 | import static command_request.CommandRequestOuterClass.RequestType.ClusterDelSlotsRange; |
| 14 | +import static command_request.CommandRequestOuterClass.RequestType.ClusterFailover; |
| 15 | +import static command_request.CommandRequestOuterClass.RequestType.ClusterFlushSlots; |
| 16 | +import static command_request.CommandRequestOuterClass.RequestType.ClusterForget; |
11 | 17 | import static command_request.CommandRequestOuterClass.RequestType.ClusterGetKeysInSlot; |
12 | 18 | import static command_request.CommandRequestOuterClass.RequestType.ClusterInfo; |
13 | 19 | import static command_request.CommandRequestOuterClass.RequestType.ClusterKeySlot; |
14 | 20 | import static command_request.CommandRequestOuterClass.RequestType.ClusterLinks; |
| 21 | +import static command_request.CommandRequestOuterClass.RequestType.ClusterMeet; |
15 | 22 | import static command_request.CommandRequestOuterClass.RequestType.ClusterMyId; |
16 | 23 | import static command_request.CommandRequestOuterClass.RequestType.ClusterMyShardId; |
17 | 24 | import static command_request.CommandRequestOuterClass.RequestType.ClusterNodes; |
| 25 | +import static command_request.CommandRequestOuterClass.RequestType.ClusterReplicas; |
| 26 | +import static command_request.CommandRequestOuterClass.RequestType.ClusterReplicate; |
| 27 | +import static command_request.CommandRequestOuterClass.RequestType.ClusterReset; |
| 28 | +import static command_request.CommandRequestOuterClass.RequestType.ClusterSaveConfig; |
| 29 | +import static command_request.CommandRequestOuterClass.RequestType.ClusterSetConfigEpoch; |
| 30 | +import static command_request.CommandRequestOuterClass.RequestType.ClusterSetslot; |
18 | 31 | import static command_request.CommandRequestOuterClass.RequestType.ClusterShards; |
19 | 32 | import static command_request.CommandRequestOuterClass.RequestType.ConfigGet; |
20 | 33 | import static command_request.CommandRequestOuterClass.RequestType.ConfigResetStat; |
|
43 | 56 | import static command_request.CommandRequestOuterClass.RequestType.PubSubShardChannels; |
44 | 57 | import static command_request.CommandRequestOuterClass.RequestType.PubSubShardNumSub; |
45 | 58 | import static command_request.CommandRequestOuterClass.RequestType.RandomKey; |
| 59 | +import static command_request.CommandRequestOuterClass.RequestType.ReadOnly; |
| 60 | +import static command_request.CommandRequestOuterClass.RequestType.ReadWrite; |
46 | 61 | import static command_request.CommandRequestOuterClass.RequestType.SPublish; |
47 | 62 | import static command_request.CommandRequestOuterClass.RequestType.SSubscribe; |
48 | 63 | import static command_request.CommandRequestOuterClass.RequestType.SSubscribeBlocking; |
|
66 | 81 | import static glide.utils.ArrayTransformUtils.concatenateArrays; |
67 | 82 | import static glide.utils.ArrayTransformUtils.convertMapToKeyValueStringArray; |
68 | 83 |
|
| 84 | +import glide.api.commands.ClusterAdminCommands; |
69 | 85 | import glide.api.commands.ClusterManagementClusterCommands; |
| 86 | +import glide.api.commands.ClusterOperationsCommands; |
| 87 | +import glide.api.commands.ConnectionControlCommands; |
70 | 88 | import glide.api.commands.ConnectionManagementClusterCommands; |
71 | 89 | import glide.api.commands.GenericClusterCommands; |
| 90 | +import glide.api.commands.NodeManagementCommands; |
72 | 91 | import glide.api.commands.PubSubClusterCommands; |
73 | 92 | import glide.api.commands.ScriptingAndFunctionsClusterCommands; |
74 | 93 | import glide.api.commands.ServerManagementClusterCommands; |
|
84 | 103 | import glide.api.models.commands.ScriptArgOptions; |
85 | 104 | import glide.api.models.commands.ScriptArgOptionsGlideString; |
86 | 105 | import glide.api.models.commands.batch.ClusterBatchOptions; |
| 106 | +import glide.api.models.commands.cluster.ClusterFailoverOptions; |
| 107 | +import glide.api.models.commands.cluster.ClusterResetOptions; |
| 108 | +import glide.api.models.commands.cluster.ClusterSetSlotOptions; |
87 | 109 | import glide.api.models.commands.function.FunctionRestorePolicy; |
88 | 110 | import glide.api.models.commands.scan.ClusterScanCursor; |
89 | 111 | import glide.api.models.commands.scan.ScanOptions; |
|
122 | 144 | * Documentation</a>. |
123 | 145 | */ |
124 | 146 | public class GlideClusterClient extends BaseClient |
125 | | - implements ConnectionManagementClusterCommands, |
| 147 | + implements ClusterAdminCommands, |
| 148 | + ClusterOperationsCommands, |
| 149 | + ConnectionControlCommands, |
| 150 | + ConnectionManagementClusterCommands, |
126 | 151 | GenericClusterCommands, |
127 | | - ServerManagementClusterCommands, |
| 152 | + NodeManagementCommands, |
| 153 | + PubSubClusterCommands, |
128 | 154 | ScriptingAndFunctionsClusterCommands, |
| 155 | + ServerManagementClusterCommands, |
129 | 156 | TransactionsClusterCommands, |
130 | | - PubSubClusterCommands, |
131 | 157 | ClusterManagementClusterCommands { |
132 | 158 |
|
133 | 159 | /** Constructor using ClientParams from BaseClient. */ |
@@ -1728,6 +1754,161 @@ public CompletableFuture<Void> sunsubscribe(int timeoutMs) { |
1728 | 1754 | }); |
1729 | 1755 | } |
1730 | 1756 |
|
| 1757 | + @Override |
| 1758 | + public CompletableFuture<String> clusterMeet(@NonNull String host, long port) { |
| 1759 | + return commandManager.submitNewCommand( |
| 1760 | + ClusterMeet, new String[] {host, Long.toString(port)}, this::handleStringResponse); |
| 1761 | + } |
| 1762 | + |
| 1763 | + @Override |
| 1764 | + public CompletableFuture<ClusterValue<String>> clusterMeet( |
| 1765 | + @NonNull String host, long port, @NonNull Route route) { |
| 1766 | + return commandManager.submitNewCommand( |
| 1767 | + ClusterMeet, |
| 1768 | + new String[] {host, Long.toString(port)}, |
| 1769 | + route, |
| 1770 | + response -> |
| 1771 | + route instanceof SingleNodeRoute |
| 1772 | + ? ClusterValue.of(handleStringResponse(response)) |
| 1773 | + : ClusterValue.of(handleMapResponse(response))); |
| 1774 | + } |
| 1775 | + |
| 1776 | + @Override |
| 1777 | + public CompletableFuture<String> clusterForget(@NonNull String nodeId) { |
| 1778 | + return commandManager.submitNewCommand( |
| 1779 | + ClusterForget, new String[] {nodeId}, this::handleStringResponse); |
| 1780 | + } |
| 1781 | + |
| 1782 | + @Override |
| 1783 | + public CompletableFuture<String> clusterReplicate(@NonNull String nodeId) { |
| 1784 | + return commandManager.submitNewCommand( |
| 1785 | + ClusterReplicate, new String[] {nodeId}, this::handleStringResponse); |
| 1786 | + } |
| 1787 | + |
| 1788 | + @Override |
| 1789 | + public CompletableFuture<String[]> clusterReplicas(@NonNull String nodeId) { |
| 1790 | + return commandManager.submitNewCommand( |
| 1791 | + ClusterReplicas, |
| 1792 | + new String[] {nodeId}, |
| 1793 | + response -> castArray(handleArrayResponse(response), String.class)); |
| 1794 | + } |
| 1795 | + |
| 1796 | + @Override |
| 1797 | + public CompletableFuture<ClusterValue<String[]>> clusterReplicas( |
| 1798 | + @NonNull String nodeId, @NonNull Route route) { |
| 1799 | + return commandManager.submitNewCommand( |
| 1800 | + ClusterReplicas, |
| 1801 | + new String[] {nodeId}, |
| 1802 | + route, |
| 1803 | + response -> |
| 1804 | + route instanceof SingleNodeRoute |
| 1805 | + ? ClusterValue.ofSingleValue(castArray(handleArrayResponse(response), String.class)) |
| 1806 | + : ClusterValue.ofMultiValue( |
| 1807 | + castMapOfArrays(handleMapResponse(response), String.class))); |
| 1808 | + } |
| 1809 | + |
| 1810 | + @Override |
| 1811 | + public CompletableFuture<Long> clusterCountFailureReports(@NonNull String nodeId) { |
| 1812 | + return commandManager.submitNewCommand( |
| 1813 | + ClusterCountFailureReports, new String[] {nodeId}, this::handleLongResponse); |
| 1814 | + } |
| 1815 | + |
| 1816 | + @Override |
| 1817 | + public CompletableFuture<ClusterValue<Long>> clusterCountFailureReports( |
| 1818 | + @NonNull String nodeId, @NonNull Route route) { |
| 1819 | + return commandManager.submitNewCommand( |
| 1820 | + ClusterCountFailureReports, |
| 1821 | + new String[] {nodeId}, |
| 1822 | + route, |
| 1823 | + response -> |
| 1824 | + route instanceof SingleNodeRoute |
| 1825 | + ? ClusterValue.of(handleLongResponse(response)) |
| 1826 | + : ClusterValue.of(handleMapResponse(response))); |
| 1827 | + } |
| 1828 | + |
| 1829 | + @Override |
| 1830 | + public CompletableFuture<String> clusterFailover() { |
| 1831 | + return commandManager.submitNewCommand( |
| 1832 | + ClusterFailover, new String[0], this::handleStringResponse); |
| 1833 | + } |
| 1834 | + |
| 1835 | + @Override |
| 1836 | + public CompletableFuture<String> clusterFailover(@NonNull ClusterFailoverOptions options) { |
| 1837 | + return commandManager.submitNewCommand( |
| 1838 | + ClusterFailover, options.toArgs(), this::handleStringResponse); |
| 1839 | + } |
| 1840 | + |
| 1841 | + @Override |
| 1842 | + public CompletableFuture<String> clusterSetSlot( |
| 1843 | + long slot, @NonNull ClusterSetSlotOptions options) { |
| 1844 | + String[] args = concatenateArrays(new String[] {Long.toString(slot)}, options.toArgs()); |
| 1845 | + return commandManager.submitNewCommand(ClusterSetslot, args, this::handleStringResponse); |
| 1846 | + } |
| 1847 | + |
| 1848 | + @Override |
| 1849 | + public CompletableFuture<String> clusterBumpEpoch() { |
| 1850 | + return commandManager.submitNewCommand( |
| 1851 | + ClusterBumpEpoch, new String[0], this::handleStringResponse); |
| 1852 | + } |
| 1853 | + |
| 1854 | + @Override |
| 1855 | + public CompletableFuture<String> clusterSetConfigEpoch(long configEpoch) { |
| 1856 | + return commandManager.submitNewCommand( |
| 1857 | + ClusterSetConfigEpoch, |
| 1858 | + new String[] {Long.toString(configEpoch)}, |
| 1859 | + this::handleStringResponse); |
| 1860 | + } |
| 1861 | + |
| 1862 | + @Override |
| 1863 | + public CompletableFuture<String> clusterFlushSlots() { |
| 1864 | + return commandManager.submitNewCommand( |
| 1865 | + ClusterFlushSlots, new String[0], this::handleStringResponse); |
| 1866 | + } |
| 1867 | + |
| 1868 | + @Override |
| 1869 | + public CompletableFuture<String> clusterReset() { |
| 1870 | + return commandManager.submitNewCommand(ClusterReset, new String[0], this::handleStringResponse); |
| 1871 | + } |
| 1872 | + |
| 1873 | + @Override |
| 1874 | + public CompletableFuture<String> clusterReset(@NonNull ClusterResetOptions options) { |
| 1875 | + return commandManager.submitNewCommand( |
| 1876 | + ClusterReset, options.toArgs(), this::handleStringResponse); |
| 1877 | + } |
| 1878 | + |
| 1879 | + @Override |
| 1880 | + public CompletableFuture<String> readonly() { |
| 1881 | + return commandManager.submitNewCommand(ReadOnly, new String[0], this::handleStringResponse); |
| 1882 | + } |
| 1883 | + |
| 1884 | + @Override |
| 1885 | + public CompletableFuture<String> readwrite() { |
| 1886 | + return commandManager.submitNewCommand(ReadWrite, new String[0], this::handleStringResponse); |
| 1887 | + } |
| 1888 | + |
| 1889 | + @Override |
| 1890 | + public CompletableFuture<String> asking() { |
| 1891 | + return commandManager.submitNewCommand(Asking, new String[0], this::handleStringResponse); |
| 1892 | + } |
| 1893 | + |
| 1894 | + @Override |
| 1895 | + public CompletableFuture<String> clusterSaveConfig() { |
| 1896 | + return commandManager.submitNewCommand( |
| 1897 | + ClusterSaveConfig, new String[0], this::handleStringResponse); |
| 1898 | + } |
| 1899 | + |
| 1900 | + @Override |
| 1901 | + public CompletableFuture<ClusterValue<String>> clusterSaveConfig(@NonNull Route route) { |
| 1902 | + return commandManager.submitNewCommand( |
| 1903 | + ClusterSaveConfig, |
| 1904 | + new String[0], |
| 1905 | + route, |
| 1906 | + response -> |
| 1907 | + route instanceof SingleNodeRoute |
| 1908 | + ? ClusterValue.of(handleStringResponse(response)) |
| 1909 | + : ClusterValue.of(handleMapResponse(response))); |
| 1910 | + } |
| 1911 | + |
1731 | 1912 | @Override |
1732 | 1913 | public CompletableFuture<String> clusterInfo() { |
1733 | 1914 | return commandManager.submitNewCommand(ClusterInfo, new String[0], this::handleStringResponse); |
|
0 commit comments