RedisService.java 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863
  1. package com.cyksj.redis;
  2. import com.cyksj.common.constant.RandomConstant;
  3. import com.cyksj.common.util.StringUtil;
  4. import lombok.AllArgsConstructor;
  5. import lombok.Getter;
  6. import org.springframework.beans.factory.annotation.Value;
  7. import org.springframework.data.redis.core.RedisTemplate;
  8. import org.springframework.data.redis.core.ZSetOperations;
  9. import org.springframework.stereotype.Service;
  10. import javax.annotation.PostConstruct;
  11. import javax.annotation.Resource;
  12. import java.util.Arrays;
  13. import java.util.List;
  14. import java.util.Map;
  15. import java.util.Set;
  16. import java.util.concurrent.TimeUnit;
  17. /**
  18. * @description 定义常用的 Redis操作
  19. * @author chan
  20. * @date 2021-03-31 5:34 下午
  21. */
  22. @Service
  23. @SuppressWarnings("all")
  24. public class RedisService {
  25. @Resource
  26. private RedisTemplate<String, Object> redisTemplate;
  27. public static String env = "dev";
  28. @Value("${spring.profiles.active}")
  29. private String active;
  30. @PostConstruct
  31. public void init(){
  32. env = active + ":";
  33. }
  34. /**
  35. * 指定缓存失效时间
  36. *
  37. * @param key 键
  38. * @param time 时间(秒)
  39. * @return Boolean
  40. */
  41. public Boolean expire(String key, Long time) {
  42. try {
  43. if (time > 0) {
  44. redisTemplate.expire(key, time, TimeUnit.SECONDS);
  45. }
  46. return true;
  47. } catch (Exception e) {
  48. e.printStackTrace();
  49. return false;
  50. }
  51. }
  52. /**
  53. * 根据key获取过期时间
  54. *
  55. * @param key 键 不能为 null
  56. * @return 时间(秒) 返回 0代表为永久有效
  57. */
  58. public Long getExpire(String key) {
  59. return redisTemplate.getExpire(key, TimeUnit.SECONDS);
  60. }
  61. /**
  62. * 判断 key是否存在
  63. *
  64. * @param key 键
  65. * @return true 存在 false不存在
  66. */
  67. public Boolean hasKey(String key) {
  68. try {
  69. return redisTemplate.hasKey(key);
  70. } catch (Exception e) {
  71. e.printStackTrace();
  72. return false;
  73. }
  74. }
  75. /**
  76. * 删除缓存
  77. *
  78. * @param key 可以传一个值 或多个
  79. */
  80. public void del(String... key) {
  81. if (key != null && key.length > 0) {
  82. if (key.length == 1) {
  83. redisTemplate.delete(key[0]);
  84. } else {
  85. redisTemplate.delete(Arrays.asList(key));
  86. }
  87. }
  88. }
  89. /**
  90. * 普通缓存获取
  91. *
  92. * @param key 键
  93. * @return 值
  94. */
  95. public Object get(String key) {
  96. return key == null ? null : redisTemplate.opsForValue().get(key);
  97. }
  98. /**
  99. * String缓存获取
  100. * @param key 键
  101. * @return 值
  102. */
  103. public String getStr(String key) {
  104. return key == null ? null : StringUtil.getString(redisTemplate.opsForValue().get(key));
  105. }
  106. /**
  107. * 普通缓存放入
  108. *
  109. * @param key 键
  110. * @param value 值
  111. * @return true成功 false失败
  112. */
  113. public Boolean set(String key, Object value) {
  114. try {
  115. redisTemplate.opsForValue().set(key, value);
  116. return true;
  117. } catch (Exception e) {
  118. e.printStackTrace();
  119. return false;
  120. }
  121. }
  122. /**
  123. * 普通缓存放入并设置时间
  124. *
  125. * @param key 键
  126. * @param value 值
  127. * @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期
  128. * @return true成功 false 失败
  129. */
  130. public Boolean set(String key, Object value, Long time) {
  131. try {
  132. if (time > 0) {
  133. redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS);
  134. } else {
  135. set(key, value);
  136. }
  137. return true;
  138. } catch (Exception e) {
  139. e.printStackTrace();
  140. return false;
  141. }
  142. }
  143. /**
  144. * 递增
  145. *
  146. * @param key 键
  147. * @param delta 要增加几(大于0)
  148. * @return Long
  149. */
  150. public Long incr(String key, Long delta) {
  151. if (delta < 0) {
  152. throw new RuntimeException("递增因子必须大于0");
  153. }
  154. return redisTemplate.opsForValue().increment(key, delta);
  155. }
  156. /**
  157. * 递减
  158. *
  159. * @param key 键
  160. * @param delta 要减少几
  161. * @return Long
  162. */
  163. public Long decr(String key, Long delta) {
  164. if (delta < 0) {
  165. throw new RuntimeException("递减因子必须大于0");
  166. }
  167. return redisTemplate.opsForValue().increment(key, -delta);
  168. }
  169. /**
  170. * HashGet
  171. *
  172. * @param key 键 不能为 null
  173. * @param item 项 不能为 null
  174. * @return 值
  175. */
  176. public Object hget(String key, String item) {
  177. return redisTemplate.opsForHash().get(key, item);
  178. }
  179. /**
  180. * 获取 hashKey对应的所有键值
  181. *
  182. * @param key 键
  183. * @return 对应的多个键值
  184. */
  185. public Map<Object, Object> hmget(String key) {
  186. return redisTemplate.opsForHash().entries(key);
  187. }
  188. /**
  189. * HashSet
  190. *
  191. * @param key 键
  192. * @param map 对应多个键值
  193. * @return true 成功 false 失败
  194. */
  195. public Boolean hmset(String key, Map<Object, Object> map) {
  196. try {
  197. redisTemplate.opsForHash().putAll(key, map);
  198. return true;
  199. } catch (Exception e) {
  200. e.printStackTrace();
  201. return false;
  202. }
  203. }
  204. /**
  205. * HashSet 并设置时间
  206. *
  207. * @param key 键
  208. * @param map 对应多个键值
  209. * @param time 时间(秒)
  210. * @return true成功 false失败
  211. */
  212. public Boolean hmset(String key, Map<String, Object> map, Long time) {
  213. try {
  214. redisTemplate.opsForHash().putAll(key, map);
  215. if (time > 0) {
  216. expire(key, time);
  217. }
  218. return true;
  219. } catch (Exception e) {
  220. e.printStackTrace();
  221. return false;
  222. }
  223. }
  224. /**
  225. * 向一张hash表中放入数据,如果不存在将创建
  226. *
  227. * @param key 键
  228. * @param item 项
  229. * @param value 值
  230. * @return true 成功 false失败
  231. */
  232. public Boolean hset(String key, String item, Object value) {
  233. try {
  234. redisTemplate.opsForHash().put(key, item, value);
  235. return true;
  236. } catch (Exception e) {
  237. e.printStackTrace();
  238. return false;
  239. }
  240. }
  241. /**
  242. * 向一张hash表中放入数据,如果不存在将创建
  243. *
  244. * @param key 键
  245. * @param item 项
  246. * @param value 值
  247. * @param time 时间(秒) 注意:如果已存在的hash表有时间,这里将会替换原有的时间
  248. * @return true 成功 false失败
  249. */
  250. public Boolean hset(String key, String item, Object value, Long time) {
  251. try {
  252. redisTemplate.opsForHash().put(key, item, value);
  253. if (time > 0) {
  254. expire(key, time);
  255. }
  256. return true;
  257. } catch (Exception e) {
  258. e.printStackTrace();
  259. return false;
  260. }
  261. }
  262. /**
  263. * 删除hash表中的值
  264. *
  265. * @param key 键 不能为 null
  266. * @param item 项 可以使多个不能为 null
  267. */
  268. public void hdel(String key, Object... item) {
  269. redisTemplate.opsForHash().delete(key, item);
  270. }
  271. /**
  272. * 判断hash表中是否有该项的值
  273. *
  274. * @param key 键 不能为 null
  275. * @param item 项 不能为 null
  276. * @return true 存在 false不存在
  277. */
  278. public Boolean hHasKey(String key, String item) {
  279. return redisTemplate.opsForHash().hasKey(key, item);
  280. }
  281. /**
  282. * hash递增 如果不存在,就会创建一个 并把新增后的值返回
  283. *
  284. * @param key 键
  285. * @param item 项
  286. * @param by 要增加几(大于0)
  287. * @return Double
  288. */
  289. public Double hincr(String key, String item, Double by) {
  290. return redisTemplate.opsForHash().increment(key, item, by);
  291. }
  292. /**
  293. * hash递减
  294. *
  295. * @param key 键
  296. * @param item 项
  297. * @param by 要减少记(小于0)
  298. * @return Double
  299. */
  300. public Double hdecr(String key, String item, Double by) {
  301. return redisTemplate.opsForHash().increment(key, item, -by);
  302. }
  303. /**
  304. * 根据 key获取 Set中的所有值
  305. *
  306. * @param key 键
  307. * @return Set
  308. */
  309. public Set<Object> sGet(String key) {
  310. try {
  311. return redisTemplate.opsForSet().members(key);
  312. } catch (Exception e) {
  313. e.printStackTrace();
  314. return null;
  315. }
  316. }
  317. /**
  318. * 根据value从一个set中查询,是否存在
  319. *
  320. * @param key 键
  321. * @param value 值
  322. * @return true 存在 false不存在
  323. */
  324. public Boolean sHasKey(String key, Object value) {
  325. try {
  326. return redisTemplate.opsForSet().isMember(key, value);
  327. } catch (Exception e) {
  328. e.printStackTrace();
  329. return false;
  330. }
  331. }
  332. /**
  333. * 将数据放入set缓存
  334. *
  335. * @param key 键
  336. * @param values 值 可以是多个
  337. * @return 成功个数
  338. */
  339. public Long sSet(String key, Object... values) {
  340. try {
  341. return redisTemplate.opsForSet().add(key, values);
  342. } catch (Exception e) {
  343. e.printStackTrace();
  344. return 0L;
  345. }
  346. }
  347. /**
  348. * 将set数据放入缓存
  349. *
  350. * @param key 键
  351. * @param time 时间(秒)
  352. * @param values 值 可以是多个
  353. * @return 成功个数
  354. */
  355. public Long sSetAndTime(String key, Long time, Object... values) {
  356. try {
  357. Long count = redisTemplate.opsForSet().add(key, values);
  358. if (time > 0) {
  359. expire(key, time);
  360. }
  361. return count;
  362. } catch (Exception e) {
  363. e.printStackTrace();
  364. return 0L;
  365. }
  366. }
  367. /**
  368. * 获取set缓存的长度
  369. *
  370. * @param key 键
  371. * @return Long
  372. */
  373. public Long sGetSetSize(String key) {
  374. try {
  375. return redisTemplate.opsForSet().size(key);
  376. } catch (Exception e) {
  377. e.printStackTrace();
  378. return 0L;
  379. }
  380. }
  381. /**
  382. * 移除值为value的
  383. *
  384. * @param key 键
  385. * @param values 值 可以是多个
  386. * @return 移除的个数
  387. */
  388. public Long setRemove(String key, Object... values) {
  389. try {
  390. return redisTemplate.opsForSet().remove(key, values);
  391. } catch (Exception e) {
  392. e.printStackTrace();
  393. return 0L;
  394. }
  395. }
  396. /**
  397. * 获取list缓存的内容
  398. *
  399. * @param key 键
  400. * @param start 开始
  401. * @param end 结束 0 到 -1代表所有值
  402. * @return List
  403. */
  404. public List<Object> lGet(String key, Long start, Long end) {
  405. try {
  406. return redisTemplate.opsForList().range(key, start, end);
  407. } catch (Exception e) {
  408. e.printStackTrace();
  409. return null;
  410. }
  411. }
  412. /**
  413. * 获取list缓存的长度
  414. *
  415. * @param key 键
  416. * @return Long
  417. */
  418. public Long lGetListSize(String key) {
  419. try {
  420. return redisTemplate.opsForList().size(key);
  421. } catch (Exception e) {
  422. e.printStackTrace();
  423. return 0L;
  424. }
  425. }
  426. /**
  427. * 通过索引 获取list中的值
  428. *
  429. * @param key 键
  430. * @param index 索引 index>=0时, 0 表头,1 第二个元素,依次类推;
  431. * index<0时,-1,表尾,-2倒数第二个元素,依次类推
  432. * @return Object
  433. */
  434. public Object lGetIndex(String key, Long index) {
  435. try {
  436. return redisTemplate.opsForList().index(key, index);
  437. } catch (Exception e) {
  438. e.printStackTrace();
  439. return null;
  440. }
  441. }
  442. /**
  443. * 将list放入缓存
  444. *
  445. * @param key 键
  446. * @param value 值
  447. * @return Boolean
  448. */
  449. public Boolean lSet(String key, Object value) {
  450. try {
  451. redisTemplate.opsForList().rightPush(key, value);
  452. return true;
  453. } catch (Exception e) {
  454. e.printStackTrace();
  455. return false;
  456. }
  457. }
  458. /**
  459. * 将list放入缓存
  460. *
  461. * @param key 键
  462. * @param value 值
  463. * @param time 时间(秒)
  464. * @return Boolean
  465. */
  466. public Boolean lSet(String key, Object value, Long time) {
  467. try {
  468. redisTemplate.opsForList().rightPush(key, value);
  469. if (time > 0) {
  470. expire(key, time);
  471. }
  472. return true;
  473. } catch (Exception e) {
  474. e.printStackTrace();
  475. return false;
  476. }
  477. }
  478. /**
  479. * 将list放入缓存
  480. *
  481. * @param key 键
  482. * @param value 值
  483. * @return Boolean
  484. */
  485. public Boolean lSet(String key, List<Object> value) {
  486. try {
  487. redisTemplate.opsForList().rightPushAll(key, value);
  488. return true;
  489. } catch (Exception e) {
  490. e.printStackTrace();
  491. return false;
  492. }
  493. }
  494. /**
  495. * 将list放入缓存
  496. *
  497. * @param key 键
  498. * @param value 值
  499. * @param time 时间(秒)
  500. * @return Boolean
  501. */
  502. public Boolean lSet(String key, List<Object> value, Long time) {
  503. try {
  504. redisTemplate.opsForList().rightPushAll(key, value);
  505. if (time > 0) {
  506. expire(key, time);
  507. }
  508. return true;
  509. } catch (Exception e) {
  510. e.printStackTrace();
  511. return false;
  512. }
  513. }
  514. /**
  515. * 根据索引修改list中的某条数据
  516. *
  517. * @param key 键
  518. * @param index 索引
  519. * @param value 值
  520. * @return Boolean
  521. */
  522. public Boolean lUpdateIndex(String key, Long index, Object value) {
  523. try {
  524. redisTemplate.opsForList().set(key, index, value);
  525. return true;
  526. } catch (Exception e) {
  527. e.printStackTrace();
  528. return false;
  529. }
  530. }
  531. /**
  532. * 移除N个值为value
  533. *
  534. * @param key 键
  535. * @param count 移除多少个
  536. * @param value 值
  537. * @return 移除的个数
  538. */
  539. public Long lRemove(String key, Long count, Object value) {
  540. try {
  541. return redisTemplate.opsForList().remove(key, count, value);
  542. } catch (Exception e) {
  543. e.printStackTrace();
  544. return 0L;
  545. }
  546. }
  547. public boolean setNx(String key, Object value, Long time) {
  548. if (time > 0) {
  549. return redisTemplate.opsForValue().setIfAbsent(key, value, time, TimeUnit.SECONDS);
  550. }
  551. return false;
  552. }
  553. /**
  554. * 添加元素到ZSet
  555. */
  556. public Boolean zAdd(String key, double score, Object value) {
  557. try {
  558. return redisTemplate.opsForZSet().add(key, value, score);
  559. } catch (Exception e) {
  560. e.printStackTrace();
  561. return false;
  562. }
  563. }
  564. // 增加ZSet元素的分数
  565. public Double zIncrementScore(String key, String value, double delta) {
  566. try {
  567. return redisTemplate.opsForZSet().incrementScore(key, value, delta);
  568. } catch (Exception e) {
  569. e.printStackTrace();
  570. return null;
  571. }
  572. }
  573. // 封装获取ZSet分数操作
  574. public Double zScore(String key, Object value) {
  575. try {
  576. return redisTemplate.opsForZSet().score(key, value);
  577. } catch (Exception e) {
  578. e.printStackTrace();
  579. return null;
  580. }
  581. }
  582. // 封装ZSet添加或更新分数操作
  583. public Boolean zAddOrUpdateScore(String key, Object value, double score) {
  584. try {
  585. return redisTemplate.opsForZSet().add(key, value, score);
  586. } catch (Exception e) {
  587. e.printStackTrace();
  588. return false;
  589. }
  590. }
  591. /**
  592. * 获取ZSet的大小
  593. */
  594. public Long zCard(String key) {
  595. try {
  596. return redisTemplate.opsForZSet().zCard(key);
  597. } catch (Exception e) {
  598. e.printStackTrace();
  599. return null;
  600. }
  601. }
  602. /**
  603. * 获取ZSet的大小
  604. */
  605. public Long zCount(String key, long start, long end) {
  606. try {
  607. return redisTemplate.opsForZSet().count(key, start, end);
  608. } catch (Exception e) {
  609. e.printStackTrace();
  610. return null;
  611. }
  612. }
  613. // 封装获取ZSet范围内成员的方法
  614. public Set<Object> zRange(String key, long start, long end) {
  615. try {
  616. ZSetOperations<String, Object> zSetOperations = redisTemplate.opsForZSet();
  617. return zSetOperations.range(key, start, end);
  618. } catch (Exception e) {
  619. e.printStackTrace();
  620. return null;
  621. }
  622. }
  623. /**
  624. * 删除ZSet中分数范围内的元素
  625. */
  626. public Long zRemoveRangeByScore(String key, double min, double max) {
  627. try {
  628. return redisTemplate.opsForZSet().removeRangeByScore(key, min, max);
  629. } catch (Exception e) {
  630. e.printStackTrace();
  631. return 0L;
  632. }
  633. }
  634. /**
  635. * 返回有序集 key 中,所有分数介于 min 和 max 之间(包括等于 min 或 max)的成员。
  636. * 有序集成员按分数值递增(从小到大)次序排列。
  637. * 此方法还支持限制返回的元素数量。
  638. *
  639. * @param key 有序集合的key
  640. * @param min 分数范围的最小值
  641. * @param max 分数范围的最大值
  642. * @param offset 开始返回的索引位置
  643. * @param count 返回的最大元素数量
  644. * @return 介于最小值和最大值之间的成员的集合
  645. */
  646. public Set<Object> zRangeByScore(String key, double min, double max, long offset, long count) {
  647. return redisTemplate.opsForZSet().rangeByScore(key, min, max, offset, count);
  648. }
  649. /**
  650. * 从ZSet获取所有成员及其分数
  651. * @param key ZSet的键
  652. * @return ZSet中所有成员及其分数的集合
  653. */
  654. public Set<ZSetOperations.TypedTuple<Object>> zRangeWithScores(String key, long start, long end){
  655. return redisTemplate.opsForZSet().rangeWithScores(key, start, end);
  656. }
  657. /**
  658. * 检查指定值是否存在于有序集合中
  659. * @param key
  660. * @param value
  661. * @return
  662. */
  663. public boolean checkValueExistsInZSet(String key, String value) {
  664. // 检查指定值是否存在于有序集合中
  665. return redisTemplate.opsForZSet().score(key, value) != null;
  666. }
  667. /**
  668. * 从ZSet中删除指定的成员
  669. *
  670. * @param key ZSet的键
  671. * @param value 要删除的成员值
  672. * @return 被成功移除的成员数量
  673. */
  674. public Long zRemove(String key, Object value) {
  675. try {
  676. return redisTemplate.opsForZSet().remove(key, value);
  677. } catch (Exception e) {
  678. e.printStackTrace();
  679. return 0L;
  680. }
  681. }
  682. public Set<String> keys(String name) {
  683. return redisTemplate.keys(name);
  684. }
  685. @AllArgsConstructor
  686. @Getter
  687. public enum key {
  688. CORP_AUTH_MAPPING_KEY("mapping:corp:", "企业微信授权跳转", 60 * 60 * 24L),
  689. CORP_ACCESSO_TOKEN_KEY("corp:access_token:", "corp_access_token", 60 * 30L),
  690. MAPPING_INDEX_KEY("mapper:index:", "授权跳转", 60 * 10L),
  691. WX_LOGIN_AUTH_URI("wx_login_auth_uri:%s:%s", "微信网页授权登录uri", 60 * 60 * 24L),
  692. RECOMMEND_COUPON_DAY("recommend_coupon_day:%s", "推荐优惠券弹窗", 60 * 60 * 24L),
  693. EMAIL_CODE_KEY("email_code_key:%s", "邮箱验证码", 60 * 3),
  694. PHONE_CODE_KEY("phone_code_key:", "短信验证码", 60 * 3),
  695. PHONE_CODE_USER_NUM_KEY_DAY("phone_code_user_num_key:", "近一天获取验证码次数", 60 * 60 * 24l),
  696. PHONE_CODE_BALCK_KEY("phone_code_balck_key:", "手机黑名单", -1l),
  697. PHONE_CODE_RETRY_TIME_KEY("phone_code_retry_time_key:", "手机登录重试key", 60 * 3),
  698. BALCK_USER_IP_KEY("balck_user_ip_key:", "拉黑用户ip", 60 * 60 * 24),
  699. LOTTERY_KEY("lottery_key:%s", "抽奖key", 60 * 60 * 24l),
  700. TASK_TIME_LIMIT_KEY("task_time_limit:%s", "一次性任务key", 30),
  701. WX_GZH_QRCODE_LOGIN("wx_gzh_qrcode_login:%s", "微信公众号扫码登录key", 60),
  702. WX_GZH_QRCODE_BIND("wx_gzh_qrcode_bind:%s", "pc手机用户购买车票绑定wx", 60),
  703. WX_GZH_QRCODE_SHARED_LOGIN("wx_gzh_qrcode_shared_login:%s", "微信公众号扫码分享邀请key", 60),
  704. EQUIPMENT_DISTRIBUTE_COUPON_KEY("equipment_distribute_coupon_key:%s", "实物设备分销新用户优惠券展示key", 60),
  705. CMS_USER_KEY("cms:user:%s:", "user缓存前缀", 60 * 60 * 24L * 7),
  706. CMS_USER_ROLE_KEY("cms:user:role:%s:", "user角色缓存前缀", 60 * 60 * 24L * 7),
  707. CMS_USER_PERMISSION_KEY("cms:user:permission:%s:", "user权限缓存前缀", 60 * 60 * 24L * 7),
  708. REPEAT_USER_KEY("repeat_user_key:%s:", "重复用户插入key", 60l),
  709. BUSINESS_FIRST_ORDER_USER_KEY("business_first_order_user_key:%s:", "商务分销首单提成key", 60l),
  710. PC_WEB_CACHE("pc_web_cache", "首页平台缓存", 10 * 60),
  711. H5_WEB_CACHE("h5_web_cache", "h5首页平台缓存", 10 * 60),
  712. YH_HOME_PAGHE_CACHE("yh_home_paghe_cache:", "银河首页缓存", 30 * 60),
  713. YH_HOME_PAGHE_CACHE_SHOP("yh_home_paghe_cache:shop:", "银河首页店铺缓存", 40 * 60),
  714. REGISTER_HOME_PAGE_CACHE("register_home_page_cache:", "注册首页缓存", 10 * 60),
  715. CPS_BACK_LOGIN_KEY("cps_back_login:", "cps商务后台登录key", 3 * 60),
  716. CPS_AUTH_SUCCESS_KEY("cps_auth_success_key:%s", "cps后台微信授权", 60 * 10),
  717. YH_SHOP_BACK_LOGIN_KEY("yh_shop_back_login:", "店铺主后台key", 3 * 60),
  718. YH_SHOP_AUTH_SUCCESS_KEY("yh_shop_auth_success_key:%s", "店铺主后台微信授权", 60 * 10),
  719. QUESTION_RESPONSE_KEY("question_response_key:%s", "问卷回答key", 60 * 60 * 24L),
  720. IMPORT_ACCOUNT_CACHE_KEY("import_account_cache_key:%s", "导入缓存key", 60 * 10L),
  721. MAKERTING_MSG_KEY("makerting_msg_key", "营销短信", 60 * 60 * 24 * 30),
  722. PHONE_AREA_CODE("phone_area_code:key", "国家或地区码", 60 * 60 * 24 * 15),
  723. CORP_CHAT_GROUP_CODE("corp_chat_group_code:", "企业微信群动态码", 60 * 60 * 24 * 15),
  724. CORP_SERVICE_QR_CODE("corp_service_qr_code:", "企业微信客服活码", 60 * 60 * 24 * 15),
  725. GENERAL_POPULARIZE_CODE("general_popularize_code:", "普通推广者关联优惠券", 10l),
  726. //企业微信欢迎语 临时素材 mediaId
  727. CORP_WECLOME_MEDIA("corp:%s:weclome:media:","临时素材 mediaId",60*60*24*3 - 60*60*1L),
  728. CORP_UPLOAD_ATTACHMENTS("corp:%s:upload:attachments:","临时附件",60*60*24*3 - 60*60*1L),
  729. CORP_DYNAMIC_RULE_TAG_KEY("corp_dynamic_rule_tag_key:", "企业微信动态标签key", 60 * 60L),
  730. ORDER_DON_POST_DATA_USER_KEY("order_don_post_data_user_key:", "用户订单回传缓存key", -1L),
  731. ABROAD_SUCCESS_URL("abroad:pay:success_url:","海外支付成功页",60 * 60 * 24L),
  732. CHAT_GPT_TOKEN_KEY("chat_gpt_token_key:", "chatGPT直连token key", 60 * 10l),
  733. CHAT_GPT_TOKEN_EXCEPTION_KEY("chat_gpt_token_exception_key:", "chatGPT直连token异常 key", -1l),
  734. ORDER_COMMENT_KEY("order_comment_key:", "订单评价", 10l),
  735. USER_BIND_ACCOUNT_INFO_KEY("user_bind_account_info_key:", "用户绑定其他账号key", 10l),
  736. TASK_RECEIVED_KEY("task_received_key:%s:%s", "领取任务奖励key", 10l),
  737. CORP_GROUP_CHAT_LIST("corp_group_chat_list:%s", "企业微信客户群列表", 60 * 60 * 24),
  738. PLUS_GOODS_ADDRESS_KEY("plus_goods_address_key:", "优惠加购实物地址key", 10 * 60l),
  739. GROUPS_TRIPS_OUTSIDE_RELATION("groups_trips_outside_relation:key:%s:%s", "额外车位", 30l),
  740. DISTRIBUTE_RULE_TIME_KEY("DISTRIBUTE_RULE_TIME_KEY", "渠道规格记录时间key", 5 * 60L),
  741. //巨量广告平台临时存储 callback
  742. OCEANENGINE_MONITOR_CALLBCAK("oceanengine:monitor:callback","巨量广告投放临时数据",60L*60L*24L),
  743. CORP_FOLLOW_ACTIVE_CODE_KEY("corp_follow_active_code_key:%s:%s", "活动客服活码key", 60 * 61),
  744. CORP_FOLLOW_ACTIVE_CODE_CLEAN_KEY("corp_follow_active_code_key:%s", "活动客服活码清除key", -1),
  745. REAL_GOODS_BENEFITS_KEY("real_goods_benefits_key:%s", "实物权益key", 60 * 5l),
  746. USER_DISTRIBUTE_ADD_KEY("user_distribute_add_key:%s", "分销用户新增key", 30l),
  747. CORP_CUSTOMER_ACQUISTION_CLICKID("corp:customer:post:%s","巨量投放,获客链接 跳转存储点击id",60*60*24),
  748. CORP_CUSTOMER_ACQUISTION_START_CHAT("corp:customer:post:start_chat","获客链接 发起回话存储点击id",60*60*24),
  749. CORP_CUSTOMER_ACQUISTION_START_CHAT_COUNT("corp:customer:post:start_chat:count:%s","获客链接 发起回话回传计数",60*60*24),
  750. CORP_CUSTOMER_ACQUISTION_START_CHAT_SET("corp:customer:post:start_chat_set","获客链接 发起回话待回传set",60*60*24),
  751. //获客链接 到企业微信内将平台标识与unionId 对应
  752. CORP_CUSTOMER_ACQUISTION_UNIONID_CLICKID("corp:customer:unionId:%s","unionid 对应的clickId",60*60*24),
  753. WEEKEND_DUTY_UNDERSTAFFED_NOTIFY("weekend_duty_understaffed_notify","周末值班人员不足短信通知key",60*60),
  754. DOUBLE_VERIFY_CODE_VIEW_MINUTES_KEY("double_verify_code_view_minutes_key","双重验证码查看同时间段人数限制",60),
  755. WX_INDENT_BIND_KEY("wx_indent_bind:key:", "微信身份授权绑定key", 60 * 60 * 24),
  756. EQUIPMENT_USER_SERVICE_RECORD("equipment_user_service_record:", "用户设备客服获取记录key", 60 * 60 * 24),
  757. INFORMATION_KEY("information_key:", "文章", 30 * 60L),
  758. CLOSE_ORDER_TIME_KEY("close_order_time_key:", "关闭订单key", 3 * 60),
  759. CLOSE_UPGRADE_ORDER_TIME_KEY("close_upgrade_order_time_key:", "关闭订单key", 3 * 60),
  760. CHATGPT_CONVERSATION_LIMIT("chatgpt:conversation:limit:", "chatGpt 对话限制", 3 * 60 * 60L),
  761. CHATGPT_CAR_SCORES("chatgpt:car:scores","chatGpt 车队分数", 48 * 60 * 60L),
  762. CHATGPT_CAR_HIGH_CHAT("chatgpt:car:high:chat:","chatGpt gpt4 对话次数", 48 * 60 * 60L),
  763. CHATGPT_CAR_LOW_CHAT("chatgpt:car:low:chat:","chatGpt 3.5 对话次数", 48 * 60 * 60L),
  764. //车票到期前每日通知key
  765. TICKET_EXPIRY_NOTIFY_DAY("ticket_expiry_notify_day:%s:%s", "车票到期前每日通知key", 60 * 60 * 24L),
  766. MIDJOURNEY_FAST_LIMIT("midjourney:fast:limit:", "midjourney fast次数", 60 * 60 * 24L * 7),
  767. MIDJOURNEY_RELAX_LIMIT("midjourney:relax:limit:", "midjourney relax次数", 60 * 60 * 24L * 7),
  768. MIDJOURNEY_EXPIRE_TIME("midjourney:expire:time:", "midjourney expire time", 60 * 60 * 48L),
  769. MIDJOURNEY_USER("midjourney:user:", "midjourney user", 60 * 60 * 2L),
  770. MIDJOURNEY_CONVERSATION("midjourney:conversation:", "midjourney conversation", 60 * 60 * 2L),
  771. MIDJOURNEY_ACCOUNT("midjourney:account:", "midjourney account", 60 * 60 * 48L),
  772. MIDJOURNEY_QUERY("midjourney:query:", "midjourney query", 60 * 60 * 2L),
  773. MIDJOURNEY_RELAX_CONVERSATION("midjourney:relax:conversation:", "midjourney relax conversation", 60 * 60 * 2L),
  774. MIDJOURNEY_ACCOUNT_USED("midjourney:account:used:", "midjourney account used", 60 * 60 * 48L),
  775. ;
  776. private String name;
  777. private String desc;
  778. private long timeout;
  779. public String getEnvName() {
  780. return this.name + env;
  781. }
  782. public String getNameFormat(Object ... str) {
  783. return String.format(this.getEnvName(), str);
  784. }
  785. }
  786. }