<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
     http://www.springframework.org/schema/beans/spring-beans.xsd">
    <!--redis连接池配置 -->
    <!--redis 配置 开始 -->
    <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
        <!-- 最大活动数目 -->
        <property name="maxActive" value="300" />
        <!-- 最大空数 -->
        <property name="maxIdle" value="100" />
        <!-- 最大等待时间 -->
        <property name="maxWait" value="1000" />
        <!-- true -->
        <property name="testOnBorrow" value="true" />
    </bean>
    <bean id="jedisPool" class="redis.clients.jedis.JedisPool"
        destroy-method="destroy">
        <constructor-arg ref="jedisPoolConfig" />
        <constructor-arg value="127.0.0.1" />
        <constructor-arg value="6379" />
        <constructor-arg value="3000" />
        <!-- pass -->
        <constructor-arg value="1234" />
        <constructor-arg value="0" />
    </bean>
    <!-- RedisApi -->
    <bean id="redisApi" class="cn.geekss.redis.RedisApi">
        <property name="jedisPool" ref="jedisPool"></property>
    </bean>
    <!-- 配置tokenservice -->
    <bean id="tokenService" class="cn.geekss.auth.TokenServiceImpl">
        <property name="redisApi" ref="redisApi"></property>
    </bean>
</beans>

RedisApi类文件

package cn.geekss.redis;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

/**
 *
 * @author ljn
 * @date 2017-10-20
 * @vesion 1.0
 * @detail api 类
 */
public class RedisApi {

protected JedisPool jedisPool;

public JedisPool getJedisPool() {
        return jedisPool;
    }

public void setJedisPool(JedisPool jedisPool) {
        this.jedisPool = jedisPool;
    }

/**
     * 赋值
     *
     * @param key
     * @param value
     * @return
     */
    public boolean set(String key, String value) {
        Jedis jedis = jedisPool.getResource();
        try {
            jedis.set(key, value);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }

return false;
    }

/**
     * 設置有效期時間
     *
     * @param key
     * @param seconds
     * @param value
     * @return
     */
    public boolean set(String key, int seconds, String value) {
        Jedis jedis = jedisPool.getResource();
        try {
            jedis.setex(key, seconds, value);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }

return false;
    }

/**
     * 判断指定key是否存在
     *
     * @return
     */
    public boolean exists(String key) {
        try {
            Jedis jedis = jedisPool.getResource();
            return jedis.exists(key);
        } catch (Exception e) {
            // TODO: handle exception
        }
        return false;

}

/**
     * 获取数据
     *
     * @param key
     * @return
     */
    public String get(String key) {
        Jedis jedis = jedisPool.getResource();

try {
            return jedis.get(key);
        } catch (Exception e) {
            // TODO: handle exception
        }
        return null;

}

/*
     * 删除指定key
     */
    public boolean del(String key) {
        try {
            Jedis jedis = jedisPool.getResource();

jedis.del(key);
            return true;
        } catch (Exception e) {
            // TODO: handle exception
        }
        return false;

}
}

最新文章

  1. [kuangbin带你飞]专题六 最小生成树
  2. 【Unity3D游戏开发】之Sprite Packer使用方法 (九)[转]
  3. Google Play支付校验
  4. 【最大点独立集】【poj1419】【Graph Coloring】
  5. hdu 4638 Group 莫队算法
  6. 海美迪Q系列视频文明书
  7. GameUnity 2.0 文档(二) 纸片人系统
  8. 10 Python+Selenium键盘事件
  9. 利用USearch去除嵌合体(chimeras)
  10. (Angular Material)用Autocomplete打造带层级分类的DropDown
  11. XXL-JOB原理--定时任务框架简介(一)
  12. [git] 文件操作
  13. cordova打包webapp
  14. Robotium_断言方法assert、is、search
  15. JS funtion()中URL不跳转后台action问题
  16. 【Lua】LuaForWindows_v5.1.4-46安装失败解决方案
  17. Linux经常使用命令-权限管理命令-其它权限管理命令
  18. Kindeditor放置两个调用readonly错误
  19. openGL之着色器程序的使用
  20. C++学习——C++复合类型

热门文章

  1. QLIKVIEW添加数据库连接
  2. Leetcode13_罗马数字转整数
  3. 第一课 安装wamp环境
  4. 网页中常见返回HTTP状态码含义
  5. Mr.Yu
  6. ionic2踩坑之文本域自适应高度(自定义指令,适用angular2)
  7. python开发之Pandas
  8. 吴裕雄--天生自然 R语言开发学习:基本统计分析(续三)
  9. java 实体类中日期格式转换
  10. container/injection简介以及发展历史