zoukankan      html  css  js  c++  java
  • Jedis 连接池实例

    原文:http://blog.java1234.com/blog/articles/315.html
     
    package com.java1234.redis;
     
    import redis.clients.jedis.Jedis;
    import redis.clients.jedis.JedisPool;
    import redis.clients.jedis.JedisPoolConfig;
     
    /**
     * 测试类
     * @author user
     *
     */
    public class JedisTest {
     
        public static void main(String[] args) {
            JedisPoolConfig config=new JedisPoolConfig(); // 连接池的配置对象
            config.setMaxTotal(100); // 设置最大连接数
            config.setMaxIdle(10); // 设置最大空闲连接数
             
            JedisPool jedisPool=new JedisPool(config,"192.168.1.107",6379);
             
            Jedis jedis=null;
            try{
                jedis=jedisPool.getResource(); // 获取连接
                jedis.auth("123456"); // 设置密码
                jedis.set("name""java知识分享网"); // 设置值
                String value=jedis.get("name"); // 获取值
                System.out.println(value);
                 
            }catch(Exception e){
                e.printStackTrace();
            }finally{
                if(jedis!=null){
                    jedis.close();
                }
                if(jedisPool!=null){
                    jedisPool.close();
                }
            }
        }
    }

    运行:

    QQ鎴�浘20170708233224.jpg

  • 相关阅读:
    【crontab】误删crontab及其恢复
    New Concept English there (7)
    New Concept English there (6)
    New Concept English there (5)
    New Concept English there (4)
    New Concept English there (3)
    New Concept English there (2)Typing speed exercise
    New Concept English there (1)Typing speed exercise
    New Concept English Two 34 game over
    New Concept English Two 33 94
  • 原文地址:https://www.cnblogs.com/gyadmin/p/8251746.html
Copyright © 2011-2022 走看看