关键词搜索

源码搜索 ×
×

Linux Ubuntu 启动、连接redis测试

发布2017-03-18浏览5371次

详情内容

环境说明

Linux OS:Ubuntu server 15.04

Redis:redis-3.0.3.tar.gz(注意:好像redis-3.2.8不提供redis-cli客户端命令操作,当然也有可能是我在同一个窗口操作造成的暂未去再次验证)

Java :jdk1.8.x

Redis启动后请开启不同Xshell进行操作

请保持Redis窗口活跃性,不要手动退出,以确保redis正常工作,监控其是否运行正常。你如果在启动页面按ctrl+z退出,那么redis会受影响。



还是那句话:保持不同的操作窗口。

操作./src/redis-cli命令窗口:





Redis Java连接工具类:

  1. package com.github.boonya.redis;
  2. import java.util.List;
  3. import java.util.Map;
  4. import java.util.Set;
  5. import org.apache.log4j.Logger;
  6. import redis.clients.jedis.BinaryClient.LIST_POSITION;
  7. import redis.clients.jedis.Jedis;
  8. import redis.clients.jedis.JedisPool;
  9. import redis.clients.jedis.JedisPoolConfig;
  10. /**
  11. * Jedis管理工具
  12. *
  13. * @package com.github.boonya.redis.RedisManager
  14. * @date 2017年3月17日 上午9:53:37
  15. * @author pengjunlin
  16. * @comment
  17. * @update
  18. */
  19. public class RedisManager {
  20. private static final Logger LOGGER = Logger.getLogger(RedisManager.class);
  21. private static JedisPool pool = null;
  22. private static RedisManager ru = new RedisManager();
  23. private RedisManager() {
  24. if (pool == null) {
  25. //Redis 安装服务器地址ifconfig查看
  26. String ip = "192.168.234.129";
  27. int port = 6379;
  28. JedisPoolConfig config = new JedisPoolConfig();
  29. // 控制一个pool可分配多少个jedis实例,通过pool.getResource()来获取;
  30. // 如果赋值为-1,则表示不限制;如果pool已经分配了maxActive个jedis实例,则此时pool的状态为exhausted(耗尽)。
  31. config.setMaxTotal(10000);
  32. // 控制一个pool最多有多少个状态为idle(空闲的)的jedis实例。
  33. config.setMaxIdle(2000);
  34. // 表示当borrow(引入)一个jedis实例时,最大的等待时间,如果超过等待时间,则直接抛出JedisConnectionException;
  35. config.setMaxWaitMillis(1000 * 100);
  36. config.setTestOnBorrow(true);
  37. //pool = new JedisPool(config, ip, port, 100000);
  38. pool=new JedisPool(config, ip, port, 60000, "123456");
  39. }
  40. }
  41. /**
  42. * <p>
  43. * 通过key获取储存在redis中的value
  44. * </p>
  45. * <p>
  46. * 并释放连接
  47. * </p>
  48. *
  49. * @param key
  50. * @return 成功返回value 失败返回null
  51. */
  52. public String get(String key) {
  53. Jedis jedis = null;
  54. String value = null;
  55. try {
  56. jedis = pool.getResource();
  57. value = jedis.get(key);
  58. } catch (Exception e) {
  59. LOGGER.error(e.getMessage());
  60. } finally {
  61. returnResource(pool, jedis);
  62. }
  63. return value;
  64. }
  65. /**
  66. * <p>
  67. * 向redis存入key和value,并释放连接资源
  68. * </p>
  69. * <p>
  70. * 如果key已经存在 则覆盖
  71. * </p>
  72. *
  73. * @param key
  74. * @param value
  75. * @return 成功 返回OK 失败返回 0
  76. */
  77. public String set(String key, String value) {
  78. Jedis jedis = null;
  79. try {
  80. jedis = pool.getResource();
  81. return jedis.set(key, value);
  82. } catch (Exception e) {
  83. LOGGER.error(e.getMessage());
  84. return "0";
  85. } finally {
  86. returnResource(pool, jedis);
  87. }
  88. }
  89. /**
  90. * <p>
  91. * 删除指定的key,也可以传入一个包含key的数组
  92. * </p>
  93. *
  94. * @param keys
  95. * 一个key 也可以使 string 数组
  96. * @return 返回删除成功的个数
  97. */
  98. public Long del(String... keys) {
  99. Jedis jedis = null;
  100. try {
  101. jedis = pool.getResource();
  102. return jedis.del(keys);
  103. } catch (Exception e) {
  104. LOGGER.error(e.getMessage());
  105. return 0L;
  106. } finally {
  107. returnResource(pool, jedis);
  108. }
  109. }
  110. /**
  111. * <p>
  112. * 通过key向指定的value值追加值
  113. * </p>
  114. *
  115. * @param key
  116. * @param str
  117. * @return 成功返回 添加后value的长度 失败 返回 添加的 value 的长度 异常返回0L
  118. */
  119. public Long append(String key, String str) {
  120. Jedis jedis = null;
  121. Long res = null;
  122. try {
  123. jedis = pool.getResource();
  124. res = jedis.append(key, str);
  125. } catch (Exception e) {
  126. LOGGER.error(e.getMessage());
  127. return 0L;
  128. } finally {
  129. returnResource(pool, jedis);
  130. }
  131. return res;
  132. }
  133. /**
  134. * <p>
  135. * 判断key是否存在
  136. * </p>
  137. *
  138. * @param key
  139. * @return true OR false
  140. */
  141. public Boolean exists(String key) {
  142. Jedis jedis = null;
  143. try {
  144. jedis = pool.getResource();
  145. return jedis.exists(key);
  146. } catch (Exception e) {
  147. LOGGER.error(e.getMessage());
  148. return false;
  149. } finally {
  150. returnResource(pool, jedis);
  151. }
  152. }
  153. /**
  154. * <p>
  155. * 设置key value,如果key已经存在则返回0,nx==> not exist
  156. * </p>
  157. *
  158. * @param key
  159. * @param value
  160. * @return 成功返回1 如果存在 和 发生异常 返回 0
  161. */
  162. public Long setnx(String key, String value) {
  163. Jedis jedis = null;
  164. try {
  165. jedis = pool.getResource();
  166. return jedis.setnx(key, value);
  167. } catch (Exception e) {
  168. LOGGER.error(e.getMessage());
  169. return 0L;
  170. } finally {
  171. returnResource(pool, jedis);
  172. }
  173. }
  174. /**
  175. * <p>
  176. * 设置key value并制定这个键值的有效期
  177. * </p>
  178. *
  179. * @param key
  180. * @param value
  181. * @param seconds
  182. * 单位:秒
  183. * @return 成功返回OK 失败和异常返回null
  184. */
  185. public String setex(String key, String value, int seconds) {
  186. Jedis jedis = null;
  187. String res = null;
  188. try {
  189. jedis = pool.getResource();
  190. res = jedis.setex(key, seconds, value);
  191. } catch (Exception e) {
  192. LOGGER.error(e.getMessage());
  193. } finally {
  194. returnResource(pool, jedis);
  195. }
  196. return res;
  197. }
  198. /**
  199. * <p>
  200. * 通过key 和offset 从指定的位置开始将原先value替换
  201. * </p>
  202. * <p>
  203. * 下标从0开始,offset表示从offset下标开始替换
  204. * </p>
  205. * <p>
  206. * 如果替换的字符串长度过小则会这样
  207. * </p>
  208. * <p>
  209. * example:
  210. * </p>
  211. * <p>
  212. * value : bigsea@zto.cn
  213. * </p>
  214. * <p>
  215. * str : abc
  216. * </p>
  217. * <P>
  218. * 从下标7开始替换 则结果为
  219. * </p>
  220. * <p>
  221. * RES : bigsea.abc.cn
  222. * </p>
  223. *
  224. * @param key
  225. * @param str
  226. * @param offset
  227. * 下标位置
  228. * @return 返回替换后 value 的长度
  229. */
  230. public Long setrange(String key, String str, int offset) {
  231. Jedis jedis = null;
  232. try {
  233. jedis = pool.getResource();
  234. return jedis.setrange(key, offset, str);
  235. } catch (Exception e) {
  236. LOGGER.error(e.getMessage());
  237. return 0L;
  238. } finally {
  239. returnResource(pool, jedis);
  240. }
  241. }
  242. /**
  243. * <p>
  244. * 通过批量的key获取批量的value
  245. * </p>
  246. *
  247. * @param keys
  248. * string数组 也可以是一个key
  249. * @return 成功返回value的集合, 失败返回null的集合 ,异常返回空
  250. */
  251. public List<String> mget(String... keys) {
  252. Jedis jedis = null;
  253. List<String> values = null;
  254. try {
  255. jedis = pool.getResource();
  256. values = jedis.mget(keys);
  257. } catch (Exception e) {
  258. LOGGER.error(e.getMessage());
  259. } finally {
  260. returnResource(pool, jedis);
  261. }
  262. return values;
  263. }
  264. /**
  265. * <p>
  266. * 批量的设置key:value,可以一个
  267. * </p>
  268. * <p>
  269. * example:
  270. * </p>
  271. * <p>
  272. * obj.mset(new String[]{"key2","value1","key2","value2"})
  273. * </p>
  274. *
  275. * @param keysvalues
  276. * @return 成功返回OK 失败 异常 返回 null
  277. *
  278. */
  279. public String mset(String... keysvalues) {
  280. Jedis jedis = null;
  281. String res = null;
  282. try {
  283. jedis = pool.getResource();
  284. res = jedis.mset(keysvalues);
  285. } catch (Exception e) {
  286. LOGGER.error(e.getMessage());
  287. } finally {
  288. returnResource(pool, jedis);
  289. }
  290. return res;
  291. }
  292. /**
  293. * <p>
  294. * 批量的设置key:value,可以一个,如果key已经存在则会失败,操作会回滚
  295. * </p>
  296. * <p>
  297. * example:
  298. * </p>
  299. * <p>
  300. * obj.msetnx(new String[]{"key2","value1","key2","value2"})
  301. * </p>
  302. *
  303. * @param keysvalues
  304. * @return 成功返回1 失败返回0
  305. */
  306. public Long msetnx(String... keysvalues) {
  307. Jedis jedis = null;
  308. Long res = 0L;
  309. try {
  310. jedis = pool.getResource();
  311. res = jedis.msetnx(keysvalues);
  312. } catch (Exception e) {
  313. LOGGER.error(e.getMessage());
  314. } finally {
  315. returnResource(pool, jedis);
  316. }
  317. return res;
  318. }
  319. /**
  320. * <p>
  321. * 设置key的值,并返回一个旧值
  322. * </p>
  323. *
  324. * @param key
  325. * @param value
  326. * @return 旧值 如果key不存在 则返回null
  327. */
  328. public String getset(String key, String value) {
  329. Jedis jedis = null;
  330. String res = null;
  331. try {
  332. jedis = pool.getResource();
  333. res = jedis.getSet(key, value);
  334. } catch (Exception e) {
  335. LOGGER.error(e.getMessage());
  336. } finally {
  337. returnResource(pool, jedis);
  338. }
  339. return res;
  340. }
  341. /**
  342. * <p>
  343. * 通过下标 和key 获取指定下标位置的 value
  344. * </p>
  345. *
  346. * @param key
  347. * @param startOffset
  348. * 开始位置 从0 开始 负数表示从右边开始截取
  349. * @param endOffset
  350. * @return 如果没有返回null
  351. */
  352. public String getrange(String key, int startOffset, int endOffset) {
  353. Jedis jedis = null;
  354. String res = null;
  355. try {
  356. jedis = pool.getResource();
  357. res = jedis.getrange(key, startOffset, endOffset);
  358. } catch (Exception e) {
  359. LOGGER.error(e.getMessage());
  360. } finally {
  361. returnResource(pool, jedis);
  362. }
  363. return res;
  364. }
  365. /**
  366. * <p>
  367. * 通过key 对value进行加值+1操作,当value不是int类型时会返回错误,当key不存在是则value为1
  368. * </p>
  369. *
  370. * @param key
  371. * @return 加值后的结果
  372. */
  373. public Long incr(String key) {
  374. Jedis jedis = null;
  375. Long res = null;
  376. try {
  377. jedis = pool.getResource();
  378. res = jedis.incr(key);
  379. } catch (Exception e) {
  380. LOGGER.error(e.getMessage());
  381. } finally {
  382. returnResource(pool, jedis);
  383. }
  384. return res;
  385. }
  386. /**
  387. * <p>
  388. * 通过key给指定的value加值,如果key不存在,则这是value为该值
  389. * </p>
  390. *
  391. * @param key
  392. * @param integer
  393. * @return
  394. */
  395. public Long incrBy(String key, Long integer) {
  396. Jedis jedis = null;
  397. Long res = null;
  398. try {
  399. jedis = pool.getResource();
  400. res = jedis.incrBy(key, integer);
  401. } catch (Exception e) {
  402. LOGGER.error(e.getMessage());
  403. } finally {
  404. returnResource(pool, jedis);
  405. }
  406. return res;
  407. }
  408. /**
  409. * <p>
  410. * 对key的值做减减操作,如果key不存在,则设置key为-1
  411. * </p>
  412. *
  413. * @param key
  414. * @return
  415. */
  416. public Long decr(String key) {
  417. Jedis jedis = null;
  418. Long res = null;
  419. try {
  420. jedis = pool.getResource();
  421. res = jedis.decr(key);
  422. } catch (Exception e) {
  423. LOGGER.error(e.getMessage());
  424. } finally {
  425. returnResource(pool, jedis);
  426. }
  427. return res;
  428. }
  429. /**
  430. * <p>
  431. * 减去指定的值
  432. * </p>
  433. *
  434. * @param key
  435. * @param integer
  436. * @return
  437. */
  438. public Long decrBy(String key, Long integer) {
  439. Jedis jedis = null;
  440. Long res = null;
  441. try {
  442. jedis = pool.getResource();
  443. res = jedis.decrBy(key, integer);
  444. } catch (Exception e) {
  445. LOGGER.error(e.getMessage());
  446. } finally {
  447. returnResource(pool, jedis);
  448. }
  449. return res;
  450. }
  451. /**
  452. * <p>
  453. * 通过key获取value值的长度
  454. * </p>
  455. *
  456. * @param key
  457. * @return 失败返回null
  458. */
  459. public Long serlen(String key) {
  460. Jedis jedis = null;
  461. Long res = null;
  462. try {
  463. jedis = pool.getResource();
  464. res = jedis.strlen(key);
  465. } catch (Exception e) {
  466. LOGGER.error(e.getMessage());
  467. } finally {
  468. returnResource(pool, jedis);
  469. }
  470. return res;
  471. }
  472. /**
  473. * <p>
  474. * 通过key给field设置指定的值,如果key不存在,则先创建
  475. * </p>
  476. *
  477. * @param key
  478. * @param field
  479. * 字段
  480. * @param value
  481. * @return 如果存在返回0 异常返回null
  482. */
  483. public Long hset(String key, String field, String value) {
  484. Jedis jedis = null;
  485. Long res = null;
  486. try {
  487. jedis = pool.getResource();
  488. res = jedis.hset(key, field, value);
  489. } catch (Exception e) {
  490. LOGGER.error(e.getMessage());
  491. } finally {
  492. returnResource(pool, jedis);
  493. }
  494. return res;
  495. }
  496. /**
  497. * <p>
  498. * 通过key给field设置指定的值,如果key不存在则先创建,如果field已经存在,返回0
  499. * </p>
  500. *
  501. * @param key
  502. * @param field
  503. * @param value
  504. * @return
  505. */
  506. public Long hsetnx(String key, String field, String value) {
  507. Jedis jedis = null;
  508. Long res = null;
  509. try {
  510. jedis = pool.getResource();
  511. res = jedis.hsetnx(key, field, value);
  512. } catch (Exception e) {
  513. LOGGER.error(e.getMessage());
  514. } finally {
  515. returnResource(pool, jedis);
  516. }
  517. return res;
  518. }
  519. /**
  520. * <p>
  521. * 通过key同时设置 hash的多个field
  522. * </p>
  523. *
  524. * @param key
  525. * @param hash
  526. * @return 返回OK 异常返回null
  527. */
  528. public String hmset(String key, Map<String, String> hash) {
  529. Jedis jedis = null;
  530. String res = null;
  531. try {
  532. jedis = pool.getResource();
  533. res = jedis.hmset(key, hash);
  534. } catch (Exception e) {
  535. LOGGER.error(e.getMessage());
  536. } finally {
  537. returnResource(pool, jedis);
  538. }
  539. return res;
  540. }
  541. /**
  542. * <p>
  543. * 通过key 和 field 获取指定的 value
  544. * </p>
  545. *
  546. * @param key
  547. * @param field
  548. * @return 没有返回null
  549. */
  550. public String hget(String key, String field) {
  551. Jedis jedis = null;
  552. String res = null;
  553. try {
  554. jedis = pool.getResource();
  555. res = jedis.hget(key, field);
  556. } catch (Exception e) {
  557. LOGGER.error(e.getMessage());
  558. } finally {
  559. returnResource(pool, jedis);
  560. }
  561. return res;
  562. }
  563. /**
  564. * <p>
  565. * 通过key 和 fields 获取指定的value 如果没有对应的value则返回null
  566. * </p>
  567. *
  568. * @param key
  569. * @param fields
  570. * 可以使 一个String 也可以是 String数组
  571. * @return
  572. */
  573. public List<String> hmget(String key, String... fields) {
  574. Jedis jedis = null;
  575. List<String> res = null;
  576. try {
  577. jedis = pool.getResource();
  578. res = jedis.hmget(key, fields);
  579. } catch (Exception e) {
  580. LOGGER.error(e.getMessage());
  581. } finally {
  582. returnResource(pool, jedis);
  583. }
  584. return res;
  585. }
  586. /**
  587. * <p>
  588. * 通过key给指定的field的value加上给定的值
  589. * </p>
  590. *
  591. * @param key
  592. * @param field
  593. * @param value
  594. * @return
  595. */
  596. public Long hincrby(String key, String field, Long value) {
  597. Jedis jedis = null;
  598. Long res = null;
  599. try {
  600. jedis = pool.getResource();
  601. res = jedis.hincrBy(key, field, value);
  602. } catch (Exception e) {
  603. LOGGER.error(e.getMessage());
  604. } finally {
  605. returnResource(pool, jedis);
  606. }
  607. return res;
  608. }
  609. /**
  610. * <p>
  611. * 通过key和field判断是否有指定的value存在
  612. * </p>
  613. *
  614. * @param key
  615. * @param field
  616. * @return
  617. */
  618. public Boolean hexists(String key, String field) {
  619. Jedis jedis = null;
  620. Boolean res = false;
  621. try {
  622. jedis = pool.getResource();
  623. res = jedis.hexists(key, field);
  624. } catch (Exception e) {
  625. LOGGER.error(e.getMessage());
  626. } finally {
  627. returnResource(pool, jedis);
  628. }
  629. return res;
  630. }
  631. /**
  632. * <p>
  633. * 通过key返回field的数量
  634. * </p>
  635. *
  636. * @param key
  637. * @return
  638. */
  639. public Long hlen(String key) {
  640. Jedis jedis = null;
  641. Long res = null;
  642. try {
  643. jedis = pool.getResource();
  644. res = jedis.hlen(key);
  645. } catch (Exception e) {
  646. LOGGER.error(e.getMessage());
  647. } finally {
  648. returnResource(pool, jedis);
  649. }
  650. return res;
  651. }
  652. /**
  653. * <p>
  654. * 通过key 删除指定的 field
  655. * </p>
  656. *
  657. * @param key
  658. * @param fields
  659. * 可以是 一个 field 也可以是 一个数组
  660. * @return
  661. */
  662. public Long hdel(String key, String... fields) {
  663. Jedis jedis = null;
  664. Long res = null;
  665. try {
  666. jedis = pool.getResource();
  667. res = jedis.hdel(key, fields);
  668. } catch (Exception e) {
  669. LOGGER.error(e.getMessage());
  670. } finally {
  671. returnResource(pool, jedis);
  672. }
  673. return res;
  674. }
  675. /**
  676. * <p>
  677. * 通过key返回所有的field
  678. * </p>
  679. *
  680. * @param key
  681. * @return
  682. */
  683. public Set<String> hkeys(String key) {
  684. Jedis jedis = null;
  685. Set<String> res = null;
  686. try {
  687. jedis = pool.getResource();
  688. res = jedis.hkeys(key);
  689. } catch (Exception e) {
  690. LOGGER.error(e.getMessage());
  691. } finally {
  692. returnResource(pool, jedis);
  693. }
  694. return res;
  695. }
  696. /**
  697. * <p>
  698. * 通过key返回所有和key有关的value
  699. * </p>
  700. *
  701. * @param key
  702. * @return
  703. */
  704. public List<String> hvals(String key) {
  705. Jedis jedis = null;
  706. List<String> res = null;
  707. try {
  708. jedis = pool.getResource();
  709. res = jedis.hvals(key);
  710. } catch (Exception e) {
  711. LOGGER.error(e.getMessage());
  712. } finally {
  713. returnResource(pool, jedis);
  714. }
  715. return res;
  716. }
  717. /**
  718. * <p>
  719. * 通过key获取所有的field和value
  720. * </p>
  721. *
  722. * @param key
  723. * @return
  724. */
  725. public Map<String, String> hgetall(String key) {
  726. Jedis jedis = null;
  727. Map<String, String> res = null;
  728. try {
  729. jedis = pool.getResource();
  730. res = jedis.hgetAll(key);
  731. } catch (Exception e) {
  732. LOGGER.error(e.getMessage());
  733. } finally {
  734. returnResource(pool, jedis);
  735. }
  736. return res;
  737. }
  738. /**
  739. * <p>
  740. * 通过key向list头部添加字符串
  741. * </p>
  742. *
  743. * @param key
  744. * @param strs
  745. * 可以使一个string 也可以使string数组
  746. * @return 返回list的value个数
  747. */
  748. public Long lpush(String key, String... strs) {
  749. Jedis jedis = null;
  750. Long res = null;
  751. try {
  752. jedis = pool.getResource();
  753. res = jedis.lpush(key, strs);
  754. } catch (Exception e) {
  755. LOGGER.error(e.getMessage());
  756. } finally {
  757. returnResource(pool, jedis);
  758. }
  759. return res;
  760. }
  761. /**
  762. * <p>
  763. * 通过key向list尾部添加字符串
  764. * </p>
  765. *
  766. * @param key
  767. * @param strs
  768. * 可以使一个string 也可以使string数组
  769. * @return 返回list的value个数
  770. */
  771. public Long rpush(String key, String... strs) {
  772. Jedis jedis = null;
  773. Long res = null;
  774. try {
  775. jedis = pool.getResource();
  776. res = jedis.rpush(key, strs);
  777. } catch (Exception e) {
  778. LOGGER.error(e.getMessage());
  779. } finally {
  780. returnResource(pool, jedis);
  781. }
  782. return res;
  783. }
  784. /**
  785. * <p>
  786. * 通过key在list指定的位置之前或者之后 添加字符串元素
  787. * </p>
  788. *
  789. * @param key
  790. * @param where
  791. * LIST_POSITION枚举类型
  792. * @param pivot
  793. * list里面的value
  794. * @param value
  795. * 添加的value
  796. * @return
  797. */
  798. public Long linsert(String key, LIST_POSITION where, String pivot,
  799. String value) {
  800. Jedis jedis = null;
  801. Long res = null;
  802. try {
  803. jedis = pool.getResource();
  804. res = jedis.linsert(key, where, pivot, value);
  805. } catch (Exception e) {
  806. LOGGER.error(e.getMessage());
  807. } finally {
  808. returnResource(pool, jedis);
  809. }
  810. return res;
  811. }
  812. /**
  813. * <p>
  814. * 通过key设置list指定下标位置的value
  815. * </p>
  816. * <p>
  817. * 如果下标超过list里面value的个数则报错
  818. * </p>
  819. *
  820. * @param key
  821. * @param index
  822. * 从0开始
  823. * @param value
  824. * @return 成功返回OK
  825. */
  826. public String lset(String key, Long index, String value) {
  827. Jedis jedis = null;
  828. String res = null;
  829. try {
  830. jedis = pool.getResource();
  831. res = jedis.lset(key, index, value);
  832. } catch (Exception e) {
  833. LOGGER.error(e.getMessage());
  834. } finally {
  835. returnResource(pool, jedis);
  836. }
  837. return res;
  838. }
  839. /**
  840. * <p>
  841. * 通过key从对应的list中删除指定的count个 和 value相同的元素
  842. * </p>
  843. *
  844. * @param key
  845. * @param count
  846. * 当count为0时删除全部
  847. * @param value
  848. * @return 返回被删除的个数
  849. */
  850. public Long lrem(String key, long count, String value) {
  851. Jedis jedis = null;
  852. Long res = null;
  853. try {
  854. jedis = pool.getResource();
  855. res = jedis.lrem(key, count, value);
  856. } catch (Exception e) {
  857. LOGGER.error(e.getMessage());
  858. } finally {
  859. returnResource(pool, jedis);
  860. }
  861. return res;
  862. }
  863. /**
  864. * <p>
  865. * 通过key保留list中从strat下标开始到end下标结束的value值
  866. * </p>
  867. *
  868. * @param key
  869. * @param start
  870. * @param end
  871. * @return 成功返回OK
  872. */
  873. public String ltrim(String key, long start, long end) {
  874. Jedis jedis = null;
  875. String res = null;
  876. try {
  877. jedis = pool.getResource();
  878. res = jedis.ltrim(key, start, end);
  879. } catch (Exception e) {
  880. LOGGER.error(e.getMessage());
  881. } finally {
  882. returnResource(pool, jedis);
  883. }
  884. return res;
  885. }
  886. /**
  887. * <p>
  888. * 通过key从list的头部删除一个value,并返回该value
  889. * </p>
  890. *
  891. * @param key
  892. * @return
  893. */
  894. synchronized public String lpop(String key) {
  895. Jedis jedis = null;
  896. String res = null;
  897. try {
  898. jedis = pool.getResource();
  899. res = jedis.lpop(key);
  900. } catch (Exception e) {
  901. LOGGER.error(e.getMessage());
  902. } finally {
  903. returnResource(pool, jedis);
  904. }
  905. return res;
  906. }
  907. /**
  908. * <p>
  909. * 通过key从list尾部删除一个value,并返回该元素
  910. * </p>
  911. *
  912. * @param key
  913. * @return
  914. */
  915. synchronized public String rpop(String key) {
  916. Jedis jedis = null;
  917. String res = null;
  918. try {
  919. jedis = pool.getResource();
  920. res = jedis.rpop(key);
  921. } catch (Exception e) {
  922. LOGGER.error(e.getMessage());
  923. } finally {
  924. returnResource(pool, jedis);
  925. }
  926. return res;
  927. }
  928. /**
  929. * <p>
  930. * 通过key从一个list的尾部删除一个value并添加到另一个list的头部,并返回该value
  931. * </p>
  932. * <p>
  933. * 如果第一个list为空或者不存在则返回null
  934. * </p>
  935. *
  936. * @param srckey
  937. * @param dstkey
  938. * @return
  939. */
  940. public String rpoplpush(String srckey, String dstkey) {
  941. Jedis jedis = null;
  942. String res = null;
  943. try {
  944. jedis = pool.getResource();
  945. res = jedis.rpoplpush(srckey, dstkey);
  946. } catch (Exception e) {
  947. LOGGER.error(e.getMessage());
  948. } finally {
  949. returnResource(pool, jedis);
  950. }
  951. return res;
  952. }
  953. /**
  954. * <p>
  955. * 通过key获取list中指定下标位置的value
  956. * </p>
  957. *
  958. * @param key
  959. * @param index
  960. * @return 如果没有返回null
  961. */
  962. public String lindex(String key, long index) {
  963. Jedis jedis = null;
  964. String res = null;
  965. try {
  966. jedis = pool.getResource();
  967. res = jedis.lindex(key, index);
  968. } catch (Exception e) {
  969. LOGGER.error(e.getMessage());
  970. } finally {
  971. returnResource(pool, jedis);
  972. }
  973. return res;
  974. }
  975. /**
  976. * <p>
  977. * 通过key返回list的长度
  978. * </p>
  979. *
  980. * @param key
  981. * @return
  982. */
  983. public Long llen(String key) {
  984. Jedis jedis = null;
  985. Long res = null;
  986. try {
  987. jedis = pool.getResource();
  988. res = jedis.llen(key);
  989. } catch (Exception e) {
  990. LOGGER.error(e.getMessage());
  991. } finally {
  992. returnResource(pool, jedis);
  993. }
  994. return res;
  995. }
  996. /**
  997. * <p>
  998. * 通过key获取list指定下标位置的value
  999. * </p>
  1000. * <p>
  1001. * 如果start 为 0 end 为 -1 则返回全部的list中的value
  1002. * </p>
  1003. *
  1004. * @param key
  1005. * @param start
  1006. * @param end
  1007. * @return
  1008. */
  1009. public List<String> lrange(String key, long start, long end) {
  1010. Jedis jedis = null;
  1011. List<String> res = null;
  1012. try {
  1013. jedis = pool.getResource();
  1014. res = jedis.lrange(key, start, end);
  1015. } catch (Exception e) {
  1016. LOGGER.error(e.getMessage());
  1017. } finally {
  1018. returnResource(pool, jedis);
  1019. }
  1020. return res;
  1021. }
  1022. /**
  1023. * <p>
  1024. * 通过key向指定的set中添加value
  1025. * </p>
  1026. *
  1027. * @param key
  1028. * @param members
  1029. * 可以是一个String 也可以是一个String数组
  1030. * @return 添加成功的个数
  1031. */
  1032. public Long sadd(String key, String... members) {
  1033. Jedis jedis = null;
  1034. Long res = null;
  1035. try {
  1036. jedis = pool.getResource();
  1037. res = jedis.sadd(key, members);
  1038. } catch (Exception e) {
  1039. LOGGER.error(e.getMessage());
  1040. } finally {
  1041. returnResource(pool, jedis);
  1042. }
  1043. return res;
  1044. }
  1045. /**
  1046. * <p>
  1047. * 通过key删除set中对应的value值
  1048. * </p>
  1049. *
  1050. * @param key
  1051. * @param members
  1052. * 可以是一个String 也可以是一个String数组
  1053. * @return 删除的个数
  1054. */
  1055. public Long srem(String key, String... members) {
  1056. Jedis jedis = null;
  1057. Long res = null;
  1058. try {
  1059. jedis = pool.getResource();
  1060. res = jedis.srem(key, members);
  1061. } catch (Exception e) {
  1062. LOGGER.error(e.getMessage());
  1063. } finally {
  1064. returnResource(pool, jedis);
  1065. }
  1066. return res;
  1067. }
  1068. /**
  1069. * <p>
  1070. * 通过key随机删除一个set中的value并返回该值
  1071. * </p>
  1072. *
  1073. * @param key
  1074. * @return
  1075. */
  1076. public String spop(String key) {
  1077. Jedis jedis = null;
  1078. String res = null;
  1079. try {
  1080. jedis = pool.getResource();
  1081. res = jedis.spop(key);
  1082. } catch (Exception e) {
  1083. LOGGER.error(e.getMessage());
  1084. } finally {
  1085. returnResource(pool, jedis);
  1086. }
  1087. return res;
  1088. }
  1089. /**
  1090. * <p>
  1091. * 通过key获取set中的差集
  1092. * </p>
  1093. * <p>
  1094. * 以第一个set为标准
  1095. * </p>
  1096. *
  1097. * @param keys
  1098. * 可以使一个string 则返回set中所有的value 也可以是string数组
  1099. * @return
  1100. */
  1101. public Set<String> sdiff(String... keys) {
  1102. Jedis jedis = null;
  1103. Set<String> res = null;
  1104. try {
  1105. jedis = pool.getResource();
  1106. res = jedis.sdiff(keys);
  1107. } catch (Exception e) {
  1108. LOGGER.error(e.getMessage());
  1109. } finally {
  1110. returnResource(pool, jedis);
  1111. }
  1112. return res;
  1113. }
  1114. /**
  1115. * <p>
  1116. * 通过key获取set中的差集并存入到另一个key中
  1117. * </p>
  1118. * <p>
  1119. * 以第一个set为标准
  1120. * </p>
  1121. *
  1122. * @param dstkey
  1123. * 差集存入的key
  1124. * @param keys
  1125. * 可以使一个string 则返回set中所有的value 也可以是string数组
  1126. * @return
  1127. */
  1128. public Long sdiffstore(String dstkey, String... keys) {
  1129. Jedis jedis = null;
  1130. Long res = null;
  1131. try {
  1132. jedis = pool.getResource();
  1133. res = jedis.sdiffstore(dstkey, keys);
  1134. } catch (Exception e) {
  1135. LOGGER.error(e.getMessage());
  1136. } finally {
  1137. returnResource(pool, jedis);
  1138. }
  1139. return res;
  1140. }
  1141. /**
  1142. * <p>
  1143. * 通过key获取指定set中的交集
  1144. * </p>
  1145. *
  1146. * @param keys
  1147. * 可以使一个string 也可以是一个string数组
  1148. * @return
  1149. */
  1150. public Set<String> sinter(String... keys) {
  1151. Jedis jedis = null;
  1152. Set<String> res = null;
  1153. try {
  1154. jedis = pool.getResource();
  1155. res = jedis.sinter(keys);
  1156. } catch (Exception e) {
  1157. LOGGER.error(e.getMessage());
  1158. } finally {
  1159. returnResource(pool, jedis);
  1160. }
  1161. return res;
  1162. }
  1163. /**
  1164. * <p>
  1165. * 通过key获取指定set中的交集 并将结果存入新的set中
  1166. * </p>
  1167. *
  1168. * @param dstkey
  1169. * @param keys
  1170. * 可以使一个string 也可以是一个string数组
  1171. * @return
  1172. */
  1173. public Long sinterstore(String dstkey, String... keys) {
  1174. Jedis jedis = null;
  1175. Long res = null;
  1176. try {
  1177. jedis = pool.getResource();
  1178. res = jedis.sinterstore(dstkey, keys);
  1179. } catch (Exception e) {
  1180. LOGGER.error(e.getMessage());
  1181. } finally {
  1182. returnResource(pool, jedis);
  1183. }
  1184. return res;
  1185. }
  1186. /**
  1187. * <p>
  1188. * 通过key返回所有set的并集
  1189. * </p>
  1190. *
  1191. * @param keys
  1192. * 可以使一个string 也可以是一个string数组
  1193. * @return
  1194. */
  1195. public Set<String> sunion(String... keys) {
  1196. Jedis jedis = null;
  1197. Set<String> res = null;
  1198. try {
  1199. jedis = pool.getResource();
  1200. res = jedis.sunion(keys);
  1201. } catch (Exception e) {
  1202. LOGGER.error(e.getMessage());
  1203. } finally {
  1204. returnResource(pool, jedis);
  1205. }
  1206. return res;
  1207. }
  1208. /**
  1209. * <p>
  1210. * 通过key返回所有set的并集,并存入到新的set中
  1211. * </p>
  1212. *
  1213. * @param dstkey
  1214. * @param keys
  1215. * 可以使一个string 也可以是一个string数组
  1216. * @return
  1217. */
  1218. public Long sunionstore(String dstkey, String... keys) {
  1219. Jedis jedis = null;
  1220. Long res = null;
  1221. try {
  1222. jedis = pool.getResource();
  1223. res = jedis.sunionstore(dstkey, keys);
  1224. } catch (Exception e) {
  1225. LOGGER.error(e.getMessage());
  1226. } finally {
  1227. returnResource(pool, jedis);
  1228. }
  1229. return res;
  1230. }
  1231. /**
  1232. * <p>
  1233. * 通过key将set中的value移除并添加到第二个set中
  1234. * </p>
  1235. *
  1236. * @param srckey
  1237. * 需要移除的
  1238. * @param dstkey
  1239. * 添加的
  1240. * @param member
  1241. * set中的value
  1242. * @return
  1243. */
  1244. public Long smove(String srckey, String dstkey, String member) {
  1245. Jedis jedis = null;
  1246. Long res = null;
  1247. try {
  1248. jedis = pool.getResource();
  1249. res = jedis.smove(srckey, dstkey, member);
  1250. } catch (Exception e) {
  1251. LOGGER.error(e.getMessage());
  1252. } finally {
  1253. returnResource(pool, jedis);
  1254. }
  1255. return res;
  1256. }
  1257. /**
  1258. * <p>
  1259. * 通过key获取set中value的个数
  1260. * </p>
  1261. *
  1262. * @param key
  1263. * @return
  1264. */
  1265. public Long scard(String key) {
  1266. Jedis jedis = null;
  1267. Long res = null;
  1268. try {
  1269. jedis = pool.getResource();
  1270. res = jedis.scard(key);
  1271. } catch (Exception e) {
  1272. LOGGER.error(e.getMessage());
  1273. } finally {
  1274. returnResource(pool, jedis);
  1275. }
  1276. return res;
  1277. }
  1278. /**
  1279. * <p>
  1280. * 通过key判断value是否是set中的元素
  1281. * </p>
  1282. *
  1283. * @param key
  1284. * @param member
  1285. * @return
  1286. */
  1287. public Boolean sismember(String key, String member) {
  1288. Jedis jedis = null;
  1289. Boolean res = null;
  1290. try {
  1291. jedis = pool.getResource();
  1292. res = jedis.sismember(key, member);
  1293. } catch (Exception e) {
  1294. LOGGER.error(e.getMessage());
  1295. } finally {
  1296. returnResource(pool, jedis);
  1297. }
  1298. return res;
  1299. }
  1300. /**
  1301. * <p>
  1302. * 通过key获取set中随机的value,不删除元素
  1303. * </p>
  1304. *
  1305. * @param key
  1306. * @return
  1307. */
  1308. public String srandmember(String key) {
  1309. Jedis jedis = null;
  1310. String res = null;
  1311. try {
  1312. jedis = pool.getResource();
  1313. res = jedis.srandmember(key);
  1314. } catch (Exception e) {
  1315. LOGGER.error(e.getMessage());
  1316. } finally {
  1317. returnResource(pool, jedis);
  1318. }
  1319. return res;
  1320. }
  1321. /**
  1322. * <p>
  1323. * 通过key获取set中所有的value
  1324. * </p>
  1325. *
  1326. * @param key
  1327. * @return
  1328. */
  1329. public Set<String> smembers(String key) {
  1330. Jedis jedis = null;
  1331. Set<String> res = null;
  1332. try {
  1333. jedis = pool.getResource();
  1334. res = jedis.smembers(key);
  1335. } catch (Exception e) {
  1336. LOGGER.error(e.getMessage());
  1337. } finally {
  1338. returnResource(pool, jedis);
  1339. }
  1340. return res;
  1341. }
  1342. /**
  1343. * <p>
  1344. * 通过key向zset中添加value,score,其中score就是用来排序的
  1345. * </p>
  1346. * <p>
  1347. * 如果该value已经存在则根据score更新元素
  1348. * </p>
  1349. *
  1350. * @param key
  1351. * @param score
  1352. * @param member
  1353. * @return
  1354. */
  1355. public Long zadd(String key, double score, String member) {
  1356. Jedis jedis = null;
  1357. Long res = null;
  1358. try {
  1359. jedis = pool.getResource();
  1360. res = jedis.zadd(key, score, member);
  1361. } catch (Exception e) {
  1362. LOGGER.error(e.getMessage());
  1363. } finally {
  1364. returnResource(pool, jedis);
  1365. }
  1366. return res;
  1367. }
  1368. /**
  1369. * <p>
  1370. * 通过key删除在zset中指定的value
  1371. * </p>
  1372. *
  1373. * @param key
  1374. * @param members
  1375. * 可以使一个string 也可以是一个string数组
  1376. * @return
  1377. */
  1378. public Long zrem(String key, String... members) {
  1379. Jedis jedis = null;
  1380. Long res = null;
  1381. try {
  1382. jedis = pool.getResource();
  1383. res = jedis.zrem(key, members);
  1384. } catch (Exception e) {
  1385. LOGGER.error(e.getMessage());
  1386. } finally {
  1387. returnResource(pool, jedis);
  1388. }
  1389. return res;
  1390. }
  1391. /**
  1392. * <p>
  1393. * 通过key增加该zset中value的score的值
  1394. * </p>
  1395. *
  1396. * @param key
  1397. * @param score
  1398. * @param member
  1399. * @return
  1400. */
  1401. public Double zincrby(String key, double score, String member) {
  1402. Jedis jedis = null;
  1403. Double res = null;
  1404. try {
  1405. jedis = pool.getResource();
  1406. res = jedis.zincrby(key, score, member);
  1407. } catch (Exception e) {
  1408. LOGGER.error(e.getMessage());
  1409. } finally {
  1410. returnResource(pool, jedis);
  1411. }
  1412. return res;
  1413. }
  1414. /**
  1415. * <p>
  1416. * 通过key返回zset中value的排名
  1417. * </p>
  1418. * <p>
  1419. * 下标从小到大排序
  1420. * </p>
  1421. *
  1422. * @param key
  1423. * @param member
  1424. * @return
  1425. */
  1426. public Long zrank(String key, String member) {
  1427. Jedis jedis = null;
  1428. Long res = null;
  1429. try {
  1430. jedis = pool.getResource();
  1431. res = jedis.zrank(key, member);
  1432. } catch (Exception e) {
  1433. LOGGER.error(e.getMessage());
  1434. } finally {
  1435. returnResource(pool, jedis);
  1436. }
  1437. return res;
  1438. }
  1439. /**
  1440. * <p>
  1441. * 通过key返回zset中value的排名
  1442. * </p>
  1443. * <p>
  1444. * 下标从大到小排序
  1445. * </p>
  1446. *
  1447. * @param key
  1448. * @param member
  1449. * @return
  1450. */
  1451. public Long zrevrank(String key, String member) {
  1452. Jedis jedis = null;
  1453. Long res = null;
  1454. try {
  1455. jedis = pool.getResource();
  1456. res = jedis.zrevrank(key, member);
  1457. } catch (Exception e) {
  1458. LOGGER.error(e.getMessage());
  1459. } finally {
  1460. returnResource(pool, jedis);
  1461. }
  1462. return res;
  1463. }
  1464. /**
  1465. * <p>
  1466. * 通过key将获取score从start到end中zset的value
  1467. * </p>
  1468. * <p>
  1469. * socre从大到小排序
  1470. * </p>
  1471. * <p>
  1472. * 当start为0 end为-1时返回全部
  1473. * </p>
  1474. *
  1475. * @param key
  1476. * @param start
  1477. * @param end
  1478. * @return
  1479. */
  1480. public Set<String> zrevrange(String key, long start, long end) {
  1481. Jedis jedis = null;
  1482. Set<String> res = null;
  1483. try {
  1484. jedis = pool.getResource();
  1485. res = jedis.zrevrange(key, start, end);
  1486. } catch (Exception e) {
  1487. LOGGER.error(e.getMessage());
  1488. } finally {
  1489. returnResource(pool, jedis);
  1490. }
  1491. return res;
  1492. }
  1493. /**
  1494. * <p>
  1495. * 通过key返回指定score内zset中的value
  1496. * </p>
  1497. *
  1498. * @param key
  1499. * @param max
  1500. * @param min
  1501. * @return
  1502. */
  1503. public Set<String> zrangebyscore(String key, String max, String min) {
  1504. Jedis jedis = null;
  1505. Set<String> res = null;
  1506. try {
  1507. jedis = pool.getResource();
  1508. res = jedis.zrevrangeByScore(key, max, min);
  1509. } catch (Exception e) {
  1510. LOGGER.error(e.getMessage());
  1511. } finally {
  1512. returnResource(pool, jedis);
  1513. }
  1514. return res;
  1515. }
  1516. /**
  1517. * <p>
  1518. * 通过key返回指定score内zset中的value
  1519. * </p>
  1520. *
  1521. * @param key
  1522. * @param max
  1523. * @param min
  1524. * @return
  1525. */
  1526. public Set<String> zrangeByScore(String key, double max, double min) {
  1527. Jedis jedis = null;
  1528. Set<String> res = null;
  1529. try {
  1530. jedis = pool.getResource();
  1531. res = jedis.zrevrangeByScore(key, max, min);
  1532. } catch (Exception e) {
  1533. LOGGER.error(e.getMessage());
  1534. } finally {
  1535. returnResource(pool, jedis);
  1536. }
  1537. return res;
  1538. }
  1539. /**
  1540. * <p>
  1541. * 返回指定区间内zset中value的数量
  1542. * </p>
  1543. *
  1544. * @param key
  1545. * @param min
  1546. * @param max
  1547. * @return
  1548. */
  1549. public Long zcount(String key, String min, String max) {
  1550. Jedis jedis = null;
  1551. Long res = null;
  1552. try {
  1553. jedis = pool.getResource();
  1554. res = jedis.zcount(key, min, max);
  1555. } catch (Exception e) {
  1556. LOGGER.error(e.getMessage());
  1557. } finally {
  1558. returnResource(pool, jedis);
  1559. }
  1560. return res;
  1561. }
  1562. /**
  1563. * <p>
  1564. * 通过key返回zset中的value个数
  1565. * </p>
  1566. *
  1567. * @param key
  1568. * @return
  1569. */
  1570. public Long zcard(String key) {
  1571. Jedis jedis = null;
  1572. Long res = null;
  1573. try {
  1574. jedis = pool.getResource();
  1575. res = jedis.zcard(key);
  1576. } catch (Exception e) {
  1577. LOGGER.error(e.getMessage());
  1578. } finally {
  1579. returnResource(pool, jedis);
  1580. }
  1581. return res;
  1582. }
  1583. /**
  1584. * <p>
  1585. * 通过key获取zset中value的score值
  1586. * </p>
  1587. *
  1588. * @param key
  1589. * @param member
  1590. * @return
  1591. */
  1592. public Double zscore(String key, String member) {
  1593. Jedis jedis = null;
  1594. Double res = null;
  1595. try {
  1596. jedis = pool.getResource();
  1597. res = jedis.zscore(key, member);
  1598. } catch (Exception e) {
  1599. LOGGER.error(e.getMessage());
  1600. } finally {
  1601. returnResource(pool, jedis);
  1602. }
  1603. return res;
  1604. }
  1605. /**
  1606. * <p>
  1607. * 通过key删除给定区间内的元素
  1608. * </p>
  1609. *
  1610. * @param key
  1611. * @param start
  1612. * @param end
  1613. * @return
  1614. */
  1615. public Long zremrangeByRank(String key, long start, long end) {
  1616. Jedis jedis = null;
  1617. Long res = null;
  1618. try {
  1619. jedis = pool.getResource();
  1620. res = jedis.zremrangeByRank(key, start, end);
  1621. } catch (Exception e) {
  1622. LOGGER.error(e.getMessage());
  1623. } finally {
  1624. returnResource(pool, jedis);
  1625. }
  1626. return res;
  1627. }
  1628. /**
  1629. * <p>
  1630. * 通过key删除指定score内的元素
  1631. * </p>
  1632. *
  1633. * @param key
  1634. * @param start
  1635. * @param end
  1636. * @return
  1637. */
  1638. public Long zremrangeByScore(String key, double start, double end) {
  1639. Jedis jedis = null;
  1640. Long res = null;
  1641. try {
  1642. jedis = pool.getResource();
  1643. res = jedis.zremrangeByScore(key, start, end);
  1644. } catch (Exception e) {
  1645. LOGGER.error(e.getMessage());
  1646. } finally {
  1647. returnResource(pool, jedis);
  1648. }
  1649. return res;
  1650. }
  1651. /**
  1652. * <p>
  1653. * 返回满足pattern表达式的所有key
  1654. * </p>
  1655. * <p>
  1656. * keys(*)
  1657. * </p>
  1658. * <p>
  1659. * 返回所有的key
  1660. * </p>
  1661. *
  1662. * @param pattern
  1663. * @return
  1664. */
  1665. public Set<String> keys(String pattern) {
  1666. Jedis jedis = null;
  1667. Set<String> res = null;
  1668. try {
  1669. jedis = pool.getResource();
  1670. res = jedis.keys(pattern);
  1671. } catch (Exception e) {
  1672. LOGGER.error(e.getMessage());
  1673. } finally {
  1674. returnResource(pool, jedis);
  1675. }
  1676. return res;
  1677. }
  1678. /**
  1679. * <p>
  1680. * 通过key判断值得类型
  1681. * </p>
  1682. *
  1683. * @param key
  1684. * @return
  1685. */
  1686. public String type(String key) {
  1687. Jedis jedis = null;
  1688. String res = null;
  1689. try {
  1690. jedis = pool.getResource();
  1691. res = jedis.type(key);
  1692. } catch (Exception e) {
  1693. LOGGER.error(e.getMessage());
  1694. } finally {
  1695. returnResource(pool, jedis);
  1696. }
  1697. return res;
  1698. }
  1699. /**
  1700. * 返还到连接池
  1701. *
  1702. * @param pool
  1703. * @param jedis
  1704. */
  1705. @SuppressWarnings("deprecation")
  1706. public static void returnResource(JedisPool pool, Jedis jedis) {
  1707. if (jedis != null) {
  1708. pool.returnResource(jedis);
  1709. }
  1710. }
  1711. public static RedisManager getRu() {
  1712. return ru;
  1713. }
  1714. public static void setRu(RedisManager ru) {
  1715. RedisManager.ru = ru;
  1716. }
  1717. public static void main(String[] args) {
  1718. RedisManager redisManager = new RedisManager();
  1719. for (int i = 0; i < 100; i++) {
  1720. redisManager.set("boonya"+i, "boonya"+i);
  1721. }
  1722. for (int i = 0; i < 100; i++) {
  1723. System.out.println(redisManager.get("boonya"+i));
  1724. }
  1725. }
  1726. }

测试输出:

boonya0
boonya1
boonya2
boonya3
boonya4
boonya5
boonya6
boonya7
boonya8
boonya9
boonya10
boonya11
boonya12
boonya13
boonya14
boonya15
boonya16
boonya17
boonya18
boonya19
boonya20
boonya21
boonya22
boonya23
boonya24
boonya25
boonya26
boonya27
boonya28
boonya29
boonya30
boonya31
boonya32
boonya33
boonya34
boonya35
boonya36
boonya37
boonya38
boonya39
boonya40
boonya41
boonya42
boonya43
boonya44
boonya45
boonya46
boonya47
boonya48
boonya49
boonya50
boonya51
boonya52
boonya53
boonya54
boonya55
boonya56
boonya57
boonya58
boonya59
boonya60
boonya61
boonya62
boonya63
boonya64
boonya65
boonya66
boonya67
boonya68
boonya69
boonya70
boonya71
boonya72
boonya73
boonya74
boonya75
boonya76
boonya77
boonya78
boonya79
boonya80
boonya81
boonya82
boonya83
boonya84
boonya85
boonya86
boonya87
boonya88
boonya89
boonya90
boonya91
boonya92
boonya93
boonya94
boonya95
boonya96
boonya97
boonya98
boonya99

Redis 异常ERR Client sent AUTH, but no password is set

redis 127.0.0.1:6379> CONFIG SET requirepass "123456"
OK
redis 127.0.0.1:6379> AUTH 123456
Ok


设置下这个配置密码就好了。

Java客户端异常Could not get a resource from the pool


出现以上问题,请设置redis密码。

相关技术文章

点击QQ咨询
开通会员
返回顶部
×
微信扫码支付
微信扫码支付
确定支付下载
请使用微信描二维码支付
×

提示信息

×

选择支付方式

  • 微信支付
  • 支付宝付款
确定支付下载