codis.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. import React from 'react'
  2. import { FilterTable } from 'wptpc-design'
  3. import { dc } from '@/conf/config'
  4. import { getcodis, setcodis, delcodis, delscodis } from './service'
  5. import { Button, Input, Select, InputGroup, message, Modal, Checkbox } from 'antd'
  6. import moment from 'moment'
  7. const apiUrl = `${dc}/ht/web/get-codis`
  8. const { Option } = Select
  9. const { confirm } = Modal
  10. class SummaryList extends React.PureComponent {
  11. state = {
  12. showModal: false,
  13. params: {},
  14. dataSource: [],
  15. type: 'string',
  16. value: '',
  17. ttl: '',
  18. subKey: '',
  19. cacheKey: '',
  20. socre: '',
  21. list: '',
  22. request: '',
  23. res: '',
  24. endTime: '',
  25. endTimedate: '',
  26. remaintime: -3,
  27. msg: '',
  28. clusterType: 'codis',
  29. isCheck: false
  30. }
  31. handleChange = (value) => {
  32. this.setState({
  33. type: value
  34. })
  35. }
  36. codisChange = (value) => {
  37. this.setState({
  38. clusterType: value
  39. })
  40. }
  41. cacheKeyChange = event => {
  42. const cacheKey = event.target.value
  43. this.setState({
  44. cacheKey
  45. })
  46. }
  47. valueChange = event => {
  48. const value = event.target.value
  49. this.setState({
  50. value
  51. })
  52. }
  53. ttlChange = event => {
  54. const ttl = event.target.value
  55. this.setState({
  56. ttl
  57. })
  58. }
  59. subKeyChange = event => {
  60. const subKey = event.target.value
  61. this.setState({
  62. subKey
  63. })
  64. }
  65. socreChange = event => {
  66. const socre = event.target.value
  67. this.setState({
  68. socre
  69. })
  70. }
  71. getredis = () => {
  72. if (!this.state.type) {
  73. message.error('类型不能为空')
  74. return false
  75. }
  76. if (!this.state.cacheKey) {
  77. message.error('请输入要查询的缓存')
  78. return false
  79. }
  80. getcodis({
  81. type: this.state.type,
  82. clusterType: this.state.clusterType,
  83. cacheKey: this.state.cacheKey,
  84. wx: this.state.isCheck
  85. }).then(res => {
  86. if (res.code === 0) {
  87. this.setState({
  88. endTimedate: moment((res.newTime + res.data.time) * 1000).format('YYYY-MM-DD HH:mm') + ':00',
  89. endTime: res.newTime + res.data.time,
  90. remaintime: res.data.time,
  91. request: JSON.stringify(JSON.parse(res.data.data), null, 4),
  92. msg: res.data.status
  93. })
  94. }
  95. })
  96. }
  97. setredis = (value) => {
  98. if (!this.state.type) {
  99. message.error('类型不能为空')
  100. return false
  101. }
  102. if (!this.state.cacheKey) {
  103. message.error('请输入要设置的缓存')
  104. return false
  105. }
  106. if (!this.state.value) {
  107. message.error('设置的值不能为空')
  108. return false
  109. }
  110. if (!this.state.ttl) {
  111. message.error('缓存过期时间不能为空')
  112. return false
  113. }
  114. if (this.state.type === 'hash' && !this.state.subKey) {
  115. message.error('键值不能为空')
  116. return false
  117. }
  118. setcodis({
  119. type: this.state.type,
  120. cacheKey: this.state.cacheKey,
  121. value: this.state.value,
  122. ttl: this.state.ttl,
  123. subKey: this.state.subKey,
  124. socre: this.state.socre,
  125. clusterType: this.state.clusterType,
  126. list: value,
  127. wx: this.state.isCheck
  128. }).then(res => {
  129. if (res.code === 0) {
  130. this.setState({
  131. endTimedate: moment((res.newTime + res.data.time) * 1000).format('YYYY-MM-DD HH:mm') + ':00',
  132. endTime: res.newTime + res.data.time,
  133. remaintime: res.data.time,
  134. request: JSON.stringify(JSON.parse(res.data.data), null, 4),
  135. msg: res.data.status
  136. })
  137. }
  138. })
  139. }
  140. delredis = (value) => {
  141. if (!this.state.type) {
  142. message.error('类型不能为空')
  143. return false
  144. }
  145. if (!this.state.cacheKey) {
  146. message.error('请输入要删除的缓存')
  147. return false
  148. }
  149. if (!this.state.subKey && this.state.type === 'hash') {
  150. message.error('键值不能为空')
  151. return false
  152. }
  153. delcodis({
  154. type: this.state.type,
  155. cacheKey: this.state.cacheKey,
  156. subKey: this.state.subKey,
  157. value: this.state.value,
  158. clusterType: this.state.clusterType,
  159. list: value,
  160. wx: this.state.isCheck
  161. }).then(res => {
  162. if (res.code === 0) {
  163. this.setState({
  164. endTimedate: moment((res.newTime + res.data.time) * 1000).format('YYYY-MM-DD HH:mm') + ':00',
  165. endTime: res.newTime + res.data.time,
  166. remaintime: res.data.time,
  167. request: JSON.stringify(JSON.parse(res.data.data), null, 4),
  168. msg: res.data.status
  169. })
  170. }
  171. })
  172. }
  173. delsredis = () => {
  174. if (!this.state.type) {
  175. message.error('类型不能为空')
  176. return false
  177. }
  178. if (!this.state.cacheKey) {
  179. message.error('请输入要删除的缓存')
  180. return false
  181. }
  182. confirm({
  183. title: '删除确认',
  184. content: '你确认要删除此缓存嘛',
  185. okText: '确认',
  186. okType: 'danger',
  187. cancelText: '取消',
  188. onOk: () => {
  189. delscodis({
  190. type: this.state.type,
  191. clusterType: this.state.clusterType,
  192. cacheKey: this.state.cacheKey,
  193. wx: this.state.isCheck
  194. }).then(res => {
  195. if (res.code === 0) {
  196. this.setState({
  197. endTimedate: moment((res.newTime + res.data.time) * 1000).format('YYYY-MM-DD HH:mm') + ':00',
  198. endTime: res.newTime + res.data.time,
  199. remaintime: res.data.time,
  200. msg: res.data.status
  201. })
  202. }
  203. })
  204. },
  205. onCancel () {
  206. }
  207. })
  208. }
  209. cleans = () => {
  210. this.setState({
  211. subKey: '',
  212. socre: '',
  213. cacheKey: '',
  214. ttl: '',
  215. value: '',
  216. request: '',
  217. remaintime: '',
  218. msg: ''
  219. })
  220. }
  221. render () {
  222. const { type, remaintime, msg } = this.state
  223. return (
  224. <div style={{ width: 1000, margin: '0 auto' }}>
  225. <div className="example-input" style={{ }}>
  226. <Button type="danger" onClick={this.delsredis}>删除</Button>
  227. <Select defaultValue="codis" style={{ width: 100 }} value={this.state.clusterType} onChange={this.codisChange}>
  228. <Option value="codis">codis</Option>
  229. <Option value="activity">activity</Option>
  230. <Option value="other">other</Option>
  231. <Option value="fengkongCodis">风控</Option>
  232. <Option value="yingTanCodis">鹰潭</Option>
  233. <Option value="nongChangCodis">农场</Option>
  234. <Option value="liveCodis">直播Codis</Option>
  235. <Option value="MarketingCodis">营销抽奖</Option>
  236. <Option value="TaskCodis">营销任务</Option>
  237. <Option value="saleCodis">模块化拍品</Option>
  238. <Option value="orderCodis">模块化订单</Option>
  239. <Option value="userCodis">模块化用户</Option>
  240. <Option value="jianghuCodis">微拍江湖</Option>
  241. <Option value="couponCodis">优惠券</Option>
  242. </Select>
  243. <Input placeholder="default size" style={{ width: 520 }} value={this.state.cacheKey} onChange={this.cacheKeyChange} />
  244. <Select defaultValue="string" style={{ width: 80 }} value={this.state.type} onChange={this.handleChange}>
  245. <Option value="string">string</Option>
  246. <Option value="hash">hash</Option>
  247. <Option value="list">list</Option>
  248. <Option value="set">set</Option>
  249. <Option value="zset">zset</Option>
  250. </Select>
  251. <Button type="primary" onClick={this.getredis}>获取</Button>
  252. </div>
  253. {/* <input type="checkbox" style={{ "margin-left":167 }} name="vehicle" value="1" />是否不带wx_前缀 */}
  254. <Checkbox style={{ 'margin-left': 167 }} value={this.state.isCheck} onChange={(e) => { this.setState({ isCheck: e.target.checked }) }}/>是否不带wx_前缀
  255. <br/>
  256. { remaintime > -2 && '过期时间:' + this.state.endTimedate}<br/>
  257. { remaintime > -2 && '过期时间戳:' + this.state.endTime}<br/>
  258. { remaintime > -2 && '剩余秒数:' + this.state.remaintime}<br/>
  259. <div style={{ width: 800, height: 300, border: '1px solid #000', minHeight: 100, overflowY: 'scroll' }}>
  260. <pre style={{ whiteSpace: 'pre-wrap', wordWrap: 'break-word' }}>
  261. { remaintime > -2 && this.state.request}<br/> </pre>
  262. </div>
  263. <br/>
  264. <div style={{ width: 800, border: '1px solid red', minHeight: 50 }}>{this.state.msg}
  265. </div>
  266. <br/>
  267. <div>
  268. { type === 'hash' && <Input placeholder="subKey" style={{ width: 300 }} value={this.state.subKey} onChange={this.subKeyChange} />}
  269. { type === 'zset' && <Input placeholder="socre" style={{ width: 120 }} value={this.state.socre} onChange={this.socreChange} />}
  270. <Input placeholder="value" style={{ width: 120 }} value={this.state.value} onChange={this.valueChange} />
  271. <Input placeholder="ttl(秒)" style={{ width: 120 }} value={this.state.ttl} onChange={this.ttlChange} />
  272. <Button type="dashed" style={{ marginLeft: 10 }} onClick={this.cleans}>清空</Button>
  273. { type !== 'list' && <Button style={{ marginLeft: 10 }} onClick={() => { this.setredis() }}>设置</Button>}
  274. { type !== 'string' && type !== 'list' && <Button type="danger" style={{ marginLeft: 10 }} onClick={() => { this.delredis() }}>删key</Button>}
  275. { type === 'list' && <Button style={{ marginLeft: 10 }} onClick={() => { this.setredis('left') }}>lpush</Button>}
  276. { type === 'list' && <Button style={{ marginLeft: 10 }} onClick={() => { this.setredis('right') }}>rpush</Button>}
  277. { type === 'list' && <Button type="danger" style={{ marginLeft: 10 }} onClick={() => { this.delredis('left') }}>lpop</Button>}
  278. { type === 'list' && <Button type="danger" style={{ marginLeft: 10 }} onClick={() => { this.delredis('right') }}>rpop</Button>}
  279. </div>
  280. </div>
  281. )
  282. }
  283. }
  284. export default SummaryList