@@ -12,7 +12,11 @@ import {
1212} from "antd" ;
1313import { message } from "antd" ;
1414import { SearchOutlined } from "@ant-design/icons" ;
15- import { REDIS_DATA_TYPE , REDIS_DATA_SHOW } from "@/utils/constant" ;
15+ import {
16+ REDIS_DATA_TYPE ,
17+ REDIS_DATA_SHOW ,
18+ CONNECT_TYPE ,
19+ } from "@/utils/constant" ;
1620import KeysHistoryService from "@/services/KeysHistoryService" ;
1721import Log from "@/services/LogService" ;
1822import "@/pages/CommonCss/zebra.css" ;
@@ -66,17 +70,7 @@ class HostKey extends Component {
6670 } ;
6771 searchInput = React . createRef ( ) ;
6872 componentDidMount ( ) {
69- let pattern = "*" ;
70- let cursor = "0" ;
71- this . setState ( { tableData : [ ] , searchDisable : true , currentPage : 1 } ) ;
72- this . props . node . redis . select ( this . props . db , ( err , res ) => {
73- if ( err ) {
74- message . error ( "" + err ) ;
75- Log . error ( "[cmd=HostKey] componentDidMount error" , err , res ) ;
76- return ;
77- }
78- this . loadRedisDataByPattern ( pattern , cursor , "*" ) ;
79- } ) ;
73+ this . searchKey ( "*" ) ;
8074 this . props . triggerRef ( this ) ;
8175 }
8276 /**
@@ -130,12 +124,26 @@ class HostKey extends Component {
130124 tableData : tableData ,
131125 tableTotal : tableData . length ,
132126 } ) ;
127+ }
128+ if (
129+ this . state . tableTotal <
130+ REDIS_DATA_SHOW . MAX_SEARCH_DATA_SIZE &&
131+ res [ 0 ] !== "0"
132+ ) {
133+ this . loadRedisDataByPattern ( pattern , res [ 0 ] , originalKey ) ;
134+ } else {
133135 // 如果key存在,则添加到搜索历史记录
134- let host = this . props . node . data . host ;
135- let port = this . props . node . data . port ;
136- KeysHistoryService . addKeysHistory ( host , port , originalKey ) ;
136+ if ( this . state . tableTotal !== 0 ) {
137+ let host = this . props . node . data . host ;
138+ let port = this . props . node . data . port ;
139+ KeysHistoryService . addKeysHistory (
140+ host ,
141+ port ,
142+ originalKey
143+ ) ;
144+ }
145+ this . setState ( { searchDisable : false } ) ;
137146 }
138- this . setState ( { searchDisable : false } ) ;
139147 }
140148 ) ;
141149 }
@@ -155,41 +163,53 @@ class HostKey extends Component {
155163 currentPage : 1 ,
156164 tableTotal : 0 ,
157165 } ) ;
158- let redis = this . props . node . redis ;
159166 let directKey = "{我~~++==>>>>们}" ;
160167 if ( key . indexOf ( "*" ) === - 1 ) {
161168 directKey = key ;
162169 }
163- redis . keys ( directKey ) . then (
164- ( value ) => {
165- let pattern = key ;
166- let cursor = "0" ;
167- pattern = "*" + pattern + "*" ;
168- if ( value !== null && value !== undefined && value . length > 0 ) {
169- // 关键字的key,如果存在,显示在第一页第一行
170- let data = [ ] ;
171- data . push ( {
172- key : key ,
173- name : key ,
174- } ) ;
175- // 如果key存在,则添加到搜索历史记录
176- let host = this . props . node . data . host ;
177- let port = this . props . node . data . port ;
178- KeysHistoryService . addKeysHistory ( host , port , key ) ;
179- let tableData = [ ...this . state . tableData , ...data ] ;
180- this . setState ( {
181- tableData : tableData ,
182- tableTotal : tableData . length ,
183- } ) ;
170+ let redisArr = [ this . props . node . redis ] ;
171+ if ( this . props . node . data . connectType === CONNECT_TYPE . CLUSTER ) {
172+ redisArr = this . props . node . redis . nodes ( "master" ) ;
173+ }
174+ redisArr . map ( ( redis ) => {
175+ redis . keys ( directKey ) . then (
176+ ( value ) => {
177+ if (
178+ value !== null &&
179+ value !== undefined &&
180+ value . length > 0
181+ ) {
182+ // 关键字的key,如果存在,显示在第一页第一行
183+ let data = [ ] ;
184+ data . push ( {
185+ key : key ,
186+ name : key ,
187+ } ) ;
188+ // 如果key存在,则添加到搜索历史记录
189+ let host = this . props . node . data . host ;
190+ let port = this . props . node . data . port ;
191+ KeysHistoryService . addKeysHistory ( host , port , key ) ;
192+ let tableData = [ ...this . state . tableData , ...data ] ;
193+ this . setState ( {
194+ tableData : tableData ,
195+ tableTotal : tableData . length ,
196+ } ) ;
197+ }
198+ let pattern = key ;
199+ let cursor = "0" ;
200+ pattern = "*" + pattern + "*" ;
201+ this . loadRedisDataByPattern ( pattern , cursor , key ) ;
202+ } ,
203+ ( err ) => {
204+ // keys 有可能被服务器禁用,所以即使失败,也继续进行loadRedisDataByPattern
205+ Log . error ( "searchKey error" , key , err ) ;
206+ let pattern = key ;
207+ let cursor = "0" ;
208+ pattern = "*" + pattern + "*" ;
209+ this . loadRedisDataByPattern ( pattern , cursor , key ) ;
184210 }
185- this . loadRedisDataByPattern ( pattern , cursor , key ) ;
186- } ,
187- ( err ) => {
188- this . setState ( { searchDisable : false } ) ;
189- message . error ( "" + err ) ;
190- Log . error ( "searchKey error" , key ) ;
191- }
192- ) ;
211+ ) ;
212+ } ) ;
193213 }
194214 /**
195215 *改变页码
@@ -419,9 +439,11 @@ class HostKey extends Component {
419439 ref = { this . searchInput }
420440 onSearch = { this . searchKey . bind ( this ) }
421441 enterButton = {
422- < Button icon = { < SearchOutlined /> } > </ Button >
442+ < Button
443+ disabled = { this . state . searchDisable }
444+ icon = { < SearchOutlined /> }
445+ > </ Button >
423446 }
424- disabled = { this . state . searchDisable }
425447 />
426448 </ AutoComplete >
427449 </ Tooltip >
0 commit comments