In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
The purpose of this article is to share with you the content of examples of Jedis's five types of operations on redis. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Jedis operates on five types of redis: strings, lists, hashes, collections, and ordered collections.
# # JedisUtil
The test case here is run with junit4, and the preparation code is as follows:
Private static final String ipAddr = "10.10.195.112"; private static final int port = 6379; private static Jedis jedis= null; @ BeforeClass public static void init () {jedis= JedisUtil.getInstance () .getJedis (ipAddr, port);} @ AfterClass public static void close () {JedisUtil.getInstance () .closeJedis (jedis,ipAddr, port);}
JedisUtil is a simple encapsulation of jedis. The code is as follows:
Import org.apache.log4j.Logger;import java.util.HashMap;import java.util.Map;import redis.clients.jedis.Jedis;import redis.clients.jedis.JedisPool;import redis.clients.jedis.JedisPoolConfig;public class JedisUtil {private Logger logger = Logger.getLogger (this.getClass (). GetName ()); private JedisUtil () {} private static class RedisUtilHolder {private static final JedisUtil instance = new JedisUtil ();} public static JedisUtil getInstance () {return RedisUtilHolder.instance } private static Map maps = new HashMap (); private static JedisPool getPool (String ip, int port) {String key = ip+ ":" + port; JedisPool pool = null; if (! maps.containsKey (key)) {JedisPoolConfig config = new JedisPoolConfig (); config.setMaxActive (RedisConfig.MAX_ACTIVE); config.setMaxIdle (RedisConfig.MAX_IDLE) Config.setMaxWait (RedisConfig.MAX_WAIT); config.setTestOnBorrow (true); config.setTestOnReturn (true); pool = new JedisPool (config,ip,port,RedisConfig.TIMEOUT); maps.put (key, pool);} else {pool = maps.get (key);} return pool } public Jedis getJedis (String ip, int port) {Jedis jedis = null; int count = 0; do {try {jedis = getPool (ip,port). GetResource () } catch (Exception e) {logger.error ("get redis master1 failed!", e); getPool (ip,port) .principnBrokenResource (jedis);}} while (jedis = = null & & count
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.