123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300 |
- 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'
- const apiUrl = `${dc}/ht/web/get-codis`
- 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
- }
- handleChange = (value) => {
- this.setState({
- type: value
- })
- }
- codisChange = (value) => {
- this.setState({
- clusterType: value
- })
- }
- cacheKeyChange = event => {
- const cacheKey = event.target.value
- this.setState({
- cacheKey
- })
- }
- valueChange = event => {
- const value = event.target.value
- this.setState({
- value
- })
- }
- ttlChange = event => {
- const ttl = event.target.value
- this.setState({
- ttl
- })
- }
- subKeyChange = event => {
- const subKey = event.target.value
- this.setState({
- subKey
- })
- }
- socreChange = event => {
- 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
- }
- 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.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.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 () {
- }
- })
- }
- 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="liveCodis">直播Codis</Option>
- <Option value="MarketingCodis">营销抽奖</Option>
- <Option value="TaskCodis">营销任务</Option>
- <Option value="saleCodis">模块化拍品</Option>
- <Option value="orderCodis">模块化订单</Option>
- <Option value="userCodis">模块化用户</Option>
- <Option value="jianghuCodis">微拍江湖</Option>
- <Option value="couponCodis">优惠券</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
|