RedisService.java 27 KB

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