如何檢視servlet&jsp版本?
阿新 • • 發佈:2020-11-27
1.
引入依賴:
<dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.9.0</version> </dependency>
測試類:
public class JedisConnTest { //使用jedis操作String 型別 @Test publicvoid testString() { Jedis jedis = new Jedis("192.168.53.177", 6379); jedis.set("alias", "lisi"); String result = jedis.get("alias"); System.out.println(result); jedis.close(); } // 使用jedis操作map型別 @Test public void testMap() { Jedis jedis= new Jedis("192.168.53.177", 6379); jedis.hset("user", "name", "zhangsan"); jedis.hset("user", "age", "12"); String name = jedis.hget("user", "name"); String age = jedis.hget("user", "age"); System.out.println(name + "-" + age); jedis.close(); }// 使用連線池的jedis @Test public void testJedisPool() { JedisPool pool = new JedisPool("192.168.53.177", 6379); Jedis jedis = pool.getResource(); jedis.hset("cat","color","yellow"); System.out.println(jedis.hget("cat", "color")); } }
結果親測有效( 注意關閉centos防火牆)
2. 由此可見spring只需要配置bean, spring版本的:
最簡版 -當然這不科學:
<bean id="redis" class="redis.clients.jedis.Jedis" > <constructor-arg name="host" value="192.168.53.177" /> <constructor-arg name="port" value="6379" /> </bean>
連線池:
<bean id="jedisPool" class="redis.clients.jedis.JedisPool"> <!-- 連線池配置 --> <constructor-arg name="poolConfig" ref="poolConfig" /> <constructor-arg name="host" value="192.168.53.177" /> <constructor-arg name="port" value="6379" /> </bean> <bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig"> <!-- 最大連線數 --> <property name="maxTotal" value="30" /> <!-- 最大空閒連線數 --> <property name="maxIdle" value="10"/> <!-- 連線耗盡是否阻塞 --> <property name="blockWhenExhausted" value="true"/> </bean>
測試連線池:
@Controller public class FirstController { @Autowired JedisPool pool; @RequestMapping("/first") @ResponseBody public String first() { Jedis jedis = pool.getResource(); jedis.set("hobby", "sleep"); String result = jedis.get("hobby"); System.out.println(result); return "ok"; } }