Browse Source

liveCodis

康栓栓 4 years ago
parent
commit
ea06f09275
1 changed files with 257 additions and 248 deletions
  1. 257 248
      src/pages/ht/codis.js

+ 257 - 248
src/pages/ht/codis.js

@@ -1,287 +1,296 @@
 import React from 'react'
 import { FilterTable } from 'wptpc-design'
 import { dc } from '@/conf/config'
-import { getcodis,setcodis,delcodis,delscodis } from './service';
-import { Button,Input,Select,InputGroup,message,Modal, Checkbox } from 'antd';
-import moment from 'moment';
+import { getcodis, setcodis, delcodis, delscodis } from './service'
+import { Button, Input, Select, InputGroup, message, Modal, Checkbox } from 'antd'
+import moment from 'moment'
 const apiUrl = `${dc}/ht/web/get-codis`
-const { Option } = Select;
-const { confirm } = Modal;
-
-
-
+const { Option } = Select
+const { confirm } = Modal
 
 class SummaryList extends React.PureComponent {
-
     state = {
-        showModal: false,
-        params: {},
-        dataSource: [],
-        type: 'string',
-        value: '',
-        ttl: '',
-        subKey: '',
-        cacheKey: '',
-        socre:'',
-        list:'',
-        request:'',
-        res:'',
-        endTime:'',
-        endTimedate:'',
-        remaintime:-3,
-        msg:'',
-        clusterType:'codis',
-        isCheck: false
+      showModal: false,
+      params: {},
+      dataSource: [],
+      type: 'string',
+      value: '',
+      ttl: '',
+      subKey: '',
+      cacheKey: '',
+      socre: '',
+      list: '',
+      request: '',
+      res: '',
+      endTime: '',
+      endTimedate: '',
+      remaintime: -3,
+      msg: '',
+      clusterType: 'codis',
+      isCheck: false
     }
+
     handleChange = (value) => {
-        this.setState({
-            type: value
-        });
+      this.setState({
+        type: value
+      })
     }
+
     codisChange = (value) => {
-        this.setState({
-            clusterType: value
-        });
+      this.setState({
+        clusterType: value
+      })
     }
+
     cacheKeyChange = event => {
-        const cacheKey = event.target.value;
-        this.setState({
-            cacheKey,
-        });
+      const cacheKey = event.target.value
+      this.setState({
+        cacheKey
+      })
     }
+
     valueChange = event => {
-        const value = event.target.value;
-        this.setState({
-            value,
-        });
+      const value = event.target.value
+      this.setState({
+        value
+      })
     }
+
     ttlChange = event => {
-        const ttl = event.target.value;
-        this.setState({
-            ttl,
-        });
+      const ttl = event.target.value
+      this.setState({
+        ttl
+      })
     }
+
     subKeyChange = event => {
-        const subKey = event.target.value;
-        this.setState({
-            subKey,
-        });
+      const subKey = event.target.value
+      this.setState({
+        subKey
+      })
     }
+
     socreChange = event => {
-        const socre = event.target.value;
-        this.setState({
-            socre,
-        });
+      const socre = event.target.value
+      this.setState({
+        socre
+      })
     }
+
     getredis = () => {
-        if(!this.state.type){
-            message.error("类型不能为空");
-            return false;
-        }
-        if(!this.state.cacheKey){
-            message.error("请输入要查询的缓存");
-            return false;
+      if (!this.state.type) {
+        message.error('类型不能为空')
+        return false
+      }
+      if (!this.state.cacheKey) {
+        message.error('请输入要查询的缓存')
+        return false
+      }
+      getcodis({
+        type: this.state.type,
+        clusterType: this.state.clusterType,
+        cacheKey: this.state.cacheKey,
+        wx: this.state.isCheck
+      }).then(res => {
+        if (res.code === 0) {
+          this.setState({
+            endTimedate: moment((res.newTime + res.data.time) * 1000).format('YYYY-MM-DD HH:mm') + ':00',
+            endTime: res.newTime + res.data.time,
+            remaintime: res.data.time,
+            request: JSON.stringify(JSON.parse(res.data.data), null, 4),
+            msg: res.data.status
+          })
         }
-        getcodis({
-            type:this.state.type,
-            clusterType:this.state.clusterType,
-            cacheKey:this.state.cacheKey,
-            wx:this.state.isCheck
-        }).then(res => {
-            if (res.code === 0) {
-                this.setState({
-                    endTimedate:moment((res.newTime + res.data.time)*1000).format('YYYY-MM-DD HH:mm') + ':00',
-                    endTime:res.newTime + res.data.time,
-                    remaintime:res.data.time,
-                    request:JSON.stringify(JSON.parse(res.data.data), null, 4),
-                    msg:res.data.status,
-                });
-            }
-        });
+      })
     }
+
     setredis = (value) => {
-        if(!this.state.type){
-            message.error("类型不能为空");
-            return false;
-        }
-        if(!this.state.cacheKey){
-            message.error("请输入要设置的缓存");
-            return false;
-        }
-        if(!this.state.value){
-            message.error("设置的值不能为空");
-            return false;
+      if (!this.state.type) {
+        message.error('类型不能为空')
+        return false
+      }
+      if (!this.state.cacheKey) {
+        message.error('请输入要设置的缓存')
+        return false
+      }
+      if (!this.state.value) {
+        message.error('设置的值不能为空')
+        return false
+      }
+      if (!this.state.ttl) {
+        message.error('缓存过期时间不能为空')
+        return false
+      }
+      if (this.state.type === 'hash' && !this.state.subKey) {
+        message.error('键值不能为空')
+        return false
+      }
+      setcodis({
+        type: this.state.type,
+        cacheKey: this.state.cacheKey,
+        value: this.state.value,
+        ttl: this.state.ttl,
+        subKey: this.state.subKey,
+        socre: this.state.socre,
+        clusterType: this.state.clusterType,
+        list: value,
+        wx: this.state.isCheck
+      }).then(res => {
+        if (res.code === 0) {
+          this.setState({
+            endTimedate: moment((res.newTime + res.data.time) * 1000).format('YYYY-MM-DD HH:mm') + ':00',
+            endTime: res.newTime + res.data.time,
+            remaintime: res.data.time,
+            request: JSON.stringify(JSON.parse(res.data.data), null, 4),
+            msg: res.data.status
+          })
         }
-        if(!this.state.ttl){
-            message.error("缓存过期时间不能为空");
-            return false;
-        }
-        if(this.state.type === 'hash' && !this.state.subKey){
-            message.error("键值不能为空");
-            return false;
-        }
-        setcodis({
-            type:this.state.type,
-            cacheKey:this.state.cacheKey,
-            value:this.state.value,
-            ttl:this.state.ttl,
-            subKey:this.state.subKey,
-            socre:this.state.socre,
-            clusterType:this.state.clusterType,
-            list:value,
-            wx:this.state.isCheck
-        }).then(res => {
-            if (res.code === 0) {
-                this.setState({
-                    endTimedate:moment((res.newTime + res.data.time)*1000).format('YYYY-MM-DD HH:mm') + ':00',
-                    endTime:res.newTime + res.data.time,
-                    remaintime:res.data.time,
-                    request:JSON.stringify(JSON.parse(res.data.data), null, 4),
-                    msg:res.data.status,
-                });
-            }
-        });
+      })
     }
+
     delredis = (value) => {
-        if(!this.state.type){
-            message.error("类型不能为空");
-            return false;
-        }
-        if(!this.state.cacheKey){
-            message.error("请输入要删除的缓存");
-            return false;
+      if (!this.state.type) {
+        message.error('类型不能为空')
+        return false
+      }
+      if (!this.state.cacheKey) {
+        message.error('请输入要删除的缓存')
+        return false
+      }
+      if (!this.state.subKey && this.state.type === 'hash') {
+        message.error('键值不能为空')
+        return false
+      }
+      delcodis({
+        type: this.state.type,
+        cacheKey: this.state.cacheKey,
+        subKey: this.state.subKey,
+        value: this.state.value,
+        clusterType: this.state.clusterType,
+        list: value,
+        wx: this.state.isCheck
+      }).then(res => {
+        if (res.code === 0) {
+          this.setState({
+            endTimedate: moment((res.newTime + res.data.time) * 1000).format('YYYY-MM-DD HH:mm') + ':00',
+            endTime: res.newTime + res.data.time,
+            remaintime: res.data.time,
+            request: JSON.stringify(JSON.parse(res.data.data), null, 4),
+            msg: res.data.status
+          })
         }
-        if(!this.state.subKey && this.state.type==='hash'){
-            message.error("键值不能为空");
-            return false;
-        }
-        delcodis({
-            type:this.state.type,
-            cacheKey:this.state.cacheKey,
-            subKey:this.state.subKey,
-            value:this.state.value,
-            clusterType:this.state.clusterType,
-            list:value,
-            wx:this.state.isCheck
-        }).then(res => {
-            if (res.code === 0) {
-                this.setState({
-                    endTimedate:moment((res.newTime + res.data.time)*1000).format('YYYY-MM-DD HH:mm') + ':00',
-                    endTime:res.newTime + res.data.time,
-                    remaintime:res.data.time,
-                    request:JSON.stringify(JSON.parse(res.data.data), null, 4),
-                    msg:res.data.status,
-                });
-            }
-        });
+      })
     }
-    delsredis = () => {
-        if(!this.state.type){
-            message.error("类型不能为空");
-            return false;
-        }
-        if(!this.state.cacheKey){
-            message.error("请输入要删除的缓存");
-            return false;
-        }
-        confirm({
-            title: '删除确认',
-            content: '你确认要删除此缓存嘛',
-            okText: '确认',
-            okType: 'danger',
-            cancelText: '取消',
-            onOk:() =>{
-                delscodis({
-                    type:this.state.type,
-                    clusterType:this.state.clusterType,
-                    cacheKey:this.state.cacheKey,
-                    wx:this.state.isCheck
-                }).then(res => {
-                    if (res.code === 0) {
-                        this.setState({
-                            endTimedate:moment((res.newTime + res.data.time)*1000).format('YYYY-MM-DD HH:mm') + ':00',
-                            endTime:res.newTime + res.data.time,
-                            remaintime:res.data.time,
-                            msg:res.data.status,
-                        });
-                    }
-                });
-            },
-            onCancel() {
 
-            },
-        });
+    delsredis = () => {
+      if (!this.state.type) {
+        message.error('类型不能为空')
+        return false
+      }
+      if (!this.state.cacheKey) {
+        message.error('请输入要删除的缓存')
+        return false
+      }
+      confirm({
+        title: '删除确认',
+        content: '你确认要删除此缓存嘛',
+        okText: '确认',
+        okType: 'danger',
+        cancelText: '取消',
+        onOk: () => {
+          delscodis({
+            type: this.state.type,
+            clusterType: this.state.clusterType,
+            cacheKey: this.state.cacheKey,
+            wx: this.state.isCheck
+          }).then(res => {
+            if (res.code === 0) {
+              this.setState({
+                endTimedate: moment((res.newTime + res.data.time) * 1000).format('YYYY-MM-DD HH:mm') + ':00',
+                endTime: res.newTime + res.data.time,
+                remaintime: res.data.time,
+                msg: res.data.status
+              })
+            }
+          })
+        },
+        onCancel () {
 
+        }
+      })
     }
-    cleans = () =>{
-        this.setState({
-            subKey:'',
-            socre:'',
-            cacheKey:'',
-            ttl:'',
-            value:'',
-            request:'',
-            remaintime:'',
-            msg:'',
-        })
+
+    cleans = () => {
+      this.setState({
+        subKey: '',
+        socre: '',
+        cacheKey: '',
+        ttl: '',
+        value: '',
+        request: '',
+        remaintime: '',
+        msg: ''
+      })
     }
+
     render () {
-        const { type  , remaintime ,msg } = this.state;
-        return (
-            <div style={{ width: 1000,margin:"0 auto" }}>
-                <div className="example-input" style={{  }}>
-                    <Button type="danger"  onClick={this.delsredis}>删除</Button>
-                    <Select defaultValue="codis" style={{ width: 100 }} value={this.state.clusterType} onChange={this.codisChange}>
-                        <Option value="codis">codis</Option>
-                        <Option value="activity">activity</Option>
-                        <Option value="other">other</Option>
-                        <Option value="fengkongCodis">风控</Option>
-                        <Option value="yingTanCodis">鹰潭</Option>
-                        <Option value="nongChangCodis">农场</Option>
-                        <Option value="saleCodis">模块化拍品</Option>
-                        <Option value="orderCodis">模块化订单</Option>
-                        <Option value="userCodis">模块化用户</Option>
-                    </Select>
-                    <Input placeholder="default size" style={{ width: 520 }} value={this.state.cacheKey} onChange={this.cacheKeyChange} />
-                    <Select defaultValue="string" style={{ width: 80 }} value={this.state.type} onChange={this.handleChange}>
-                    <Option value="string">string</Option>
-                    <Option value="hash">hash</Option>
-                    <Option value="list">list</Option>
-                    <Option value="set">set</Option>
-                    <Option value="zset">zset</Option>
-                    </Select>
-                    <Button type="primary" onClick={this.getredis}>获取</Button>
-                </div>
-                {/*<input type="checkbox" style={{ "margin-left":167 }} name="vehicle" value="1" />是否不带wx_前缀*/}
-                <Checkbox style={{ "margin-left":167 }} value={this.state.isCheck} onChange={(e)=>{this.setState({isCheck: e.target.checked})}}/>是否不带wx_前缀
-                <br/>
-                { remaintime > -2 && "过期时间:" + this.state.endTimedate}<br/>
-                { remaintime > -2 && "过期时间戳:" + this.state.endTime}<br/>
-                { remaintime > -2 && "剩余秒数:" + this.state.remaintime}<br/>
-                <div style={{  width:800, height:300, border:"1px solid #000",minHeight:100,overflowY: 'scroll', }}>
-                    <pre style={{ whiteSpace: 'pre-wrap', wordWrap: 'break-word' }}>
-                    { remaintime > -2 &&  this.state.request}<br/> </pre>
-                </div>
-                <br/>
-                <div style={{  width:800,  border:"1px solid red",minHeight:50 }}>{this.state.msg}
-                </div>
-                <br/>
-                <div>
-                    { type ==='hash' && <Input placeholder="subKey" style={{ width: 300 }} value={this.state.subKey} onChange={this.subKeyChange} />}
-                    { type ==='zset' && <Input placeholder="socre" style={{ width: 120 }} value={this.state.socre} onChange={this.socreChange} />}
-                    <Input placeholder="value" style={{ width: 120 }} value={this.state.value} onChange={this.valueChange} />
-                    <Input placeholder="ttl(秒)" style={{ width: 120 }} value={this.state.ttl} onChange={this.ttlChange} />
-                    <Button type="dashed" style={{marginLeft:10}} onClick={this.cleans}>清空</Button>
-                    { type !=='list'  && <Button style={{marginLeft:10}} onClick={() => {this.setredis()}}>设置</Button>}
-                    { type !=='string' && type !=='list' && <Button type="danger" style={{marginLeft:10}} onClick={() => {this.delredis()}}>删key</Button>}
-                    { type ==='list' && <Button style={{marginLeft:10}} onClick={() => { this.setredis("left")}}>lpush</Button>}
-                    { type ==='list' && <Button style={{marginLeft:10}} onClick={() => { this.setredis("right")}}>rpush</Button>}
-                    { type ==='list' && <Button type="danger" style={{marginLeft:10}} onClick={() => {this.delredis("left")}}>lpop</Button>}
-                    { type ==='list' && <Button type="danger" style={{marginLeft:10}} onClick={() => {this.delredis("right")}}>rpop</Button>}
-                </div>
-            </div>
-        )
+      const { type, remaintime, msg } = this.state
+      return (
+        <div style={{ width: 1000, margin: '0 auto' }}>
+          <div className="example-input" style={{ }}>
+            <Button type="danger" onClick={this.delsredis}>删除</Button>
+            <Select defaultValue="codis" style={{ width: 100 }} value={this.state.clusterType} onChange={this.codisChange}>
+              <Option value="codis">codis</Option>
+              <Option value="activity">activity</Option>
+              <Option value="other">other</Option>
+              <Option value="fengkongCodis">风控</Option>
+              <Option value="yingTanCodis">鹰潭</Option>
+              <Option value="nongChangCodis">农场</Option>
+              <Option value="liveCodis">直播Codis</Option>
+              <Option value="saleCodis">模块化拍品</Option>
+              <Option value="orderCodis">模块化订单</Option>
+              <Option value="userCodis">模块化用户</Option>
+            </Select>
+            <Input placeholder="default size" style={{ width: 520 }} value={this.state.cacheKey} onChange={this.cacheKeyChange} />
+            <Select defaultValue="string" style={{ width: 80 }} value={this.state.type} onChange={this.handleChange}>
+              <Option value="string">string</Option>
+              <Option value="hash">hash</Option>
+              <Option value="list">list</Option>
+              <Option value="set">set</Option>
+              <Option value="zset">zset</Option>
+            </Select>
+            <Button type="primary" onClick={this.getredis}>获取</Button>
+          </div>
+          {/* <input type="checkbox" style={{ "margin-left":167 }} name="vehicle" value="1" />是否不带wx_前缀 */}
+          <Checkbox style={{ 'margin-left': 167 }} value={this.state.isCheck} onChange={(e) => { this.setState({ isCheck: e.target.checked }) }}/>是否不带wx_前缀
+          <br/>
+          { remaintime > -2 && '过期时间:' + this.state.endTimedate}<br/>
+          { remaintime > -2 && '过期时间戳:' + this.state.endTime}<br/>
+          { remaintime > -2 && '剩余秒数:' + this.state.remaintime}<br/>
+          <div style={{ width: 800, height: 300, border: '1px solid #000', minHeight: 100, overflowY: 'scroll' }}>
+            <pre style={{ whiteSpace: 'pre-wrap', wordWrap: 'break-word' }}>
+              { remaintime > -2 && this.state.request}<br/> </pre>
+          </div>
+          <br/>
+          <div style={{ width: 800, border: '1px solid red', minHeight: 50 }}>{this.state.msg}
+          </div>
+          <br/>
+          <div>
+            { type === 'hash' && <Input placeholder="subKey" style={{ width: 300 }} value={this.state.subKey} onChange={this.subKeyChange} />}
+            { type === 'zset' && <Input placeholder="socre" style={{ width: 120 }} value={this.state.socre} onChange={this.socreChange} />}
+            <Input placeholder="value" style={{ width: 120 }} value={this.state.value} onChange={this.valueChange} />
+            <Input placeholder="ttl(秒)" style={{ width: 120 }} value={this.state.ttl} onChange={this.ttlChange} />
+            <Button type="dashed" style={{ marginLeft: 10 }} onClick={this.cleans}>清空</Button>
+            { type !== 'list' && <Button style={{ marginLeft: 10 }} onClick={() => { this.setredis() }}>设置</Button>}
+            { type !== 'string' && type !== 'list' && <Button type="danger" style={{ marginLeft: 10 }} onClick={() => { this.delredis() }}>删key</Button>}
+            { type === 'list' && <Button style={{ marginLeft: 10 }} onClick={() => { this.setredis('left') }}>lpush</Button>}
+            { type === 'list' && <Button style={{ marginLeft: 10 }} onClick={() => { this.setredis('right') }}>rpush</Button>}
+            { type === 'list' && <Button type="danger" style={{ marginLeft: 10 }} onClick={() => { this.delredis('left') }}>lpop</Button>}
+            { type === 'list' && <Button type="danger" style={{ marginLeft: 10 }} onClick={() => { this.delredis('right') }}>rpop</Button>}
+          </div>
+        </div>
+      )
     }
 }
 
-export default SummaryList
+export default SummaryList