<?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;

}
}

redis如何在spring里面的bean配置的更多相关文章

  1. spring里面的ioc的理解?

    spring里面的ioc就是控制反转,其实现核心是DI(依赖注入),控制反转不向以前java代码里面,通过new关键字来实现创建对象,这样每段代码之间的耦合度就比较高,为了降低每个小模块之间的耦合度, ...

  2. Spring中的Bean配置方式

    1.IOC和DI概述 IOC(Inversion of Control):其思想是反转资源获取的方向. 传统的资源查找方式要求组件向容器发起请求查找资源. 作为回应, 容器适时的返回资源. 而应用了 ...

  3. Spring 中的 Bean 配置

    内容提要 •IOC & DI 概述 •配置 bean –配置形式:基于 XML 文件的方式:基于注解的方式 –Bean 的配置方式:通过全类名(反射).通过工厂方法(静态工厂方法 & ...

  4. Spring中的Bean配置

    IOC&DI概述 OPC(Inversion of Control):其思想是反转资源获取的方向.传统的资源查找方式要求组件向容器发起请求查找资源.作为回应,容器适时的返回资源.而应用了IOC ...

  5. 如何在 Apache 里修改 PHP 配置

    当使用 PHP 作为 Apache 模块时,也可以使用 Apache 配置文件(例如:httpd.conf) 和 .htaccess 文件中的指令来修改 PHP 的配置 设定,不过需要有 " ...

  6. nginx里面的rewrite配置

    哎,我需要静静,刚刚在去怎么优化dom层级,发现更新完代码,层级又蹭蹭蹭的往上涨,顿时没脾气了,还是把昨天的nginx配置总结下,增加点动力,昨天前天两天都在搞这个问题,也是搞的没脾气,网上查了很多资 ...

  7. spring里面的context:component-scan

    原文:http://jinnianshilongnian.iteye.com/blog/1762632 component-scan的作用的自动扫描,把扫描到加了注解Java文件都注册成bean &l ...

  8. 获取spring里的bean

    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring. ...

  9. 通过类名获取spring里的Bean

    import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactor ...

随机推荐

  1. 浏览器CA认证流程

    转载:https://blog.csdn.net/qq_22771739/article/details/86479411 首先说说证书的签发过程: 服务方 S 向第三方机构CA提交公钥.组织信息.个 ...

  2. 牛客-富豪凯匹配串(bitset)

    题目传送门 sol1:用bitset来维护,其实感觉挺暴力的,不怎么会用bitset,借着这道题学习一下. bitset暴力维护 #include "bits/stdc++.h" ...

  3. 信息熵、信息增益、信息增益率、gini、woe、iv、VIF

    整理一下这几个量的计算公式,便于记忆 采用信息增益率可以解决ID3算法中存在的问题,因此将采用信息增益率作为判定划分属性好坏的方法称为C4.5.需要注意的是,增益率准则对属性取值较少的时候会有偏好,为 ...

  4. kafka spark steam 写入elasticsearch的部分问题

    应用版本 elasticsearch 5.5 spark 2.2.0 hadoop 2.7 依赖包版本 docker cp /Users/cclient/.ivy2/cache/org.elastic ...

  5. python Ajax的使用

    转自:http://www.cnblogs.com/python-study/p/6060530.html 1.使用Ajax在后台传递参数的示例 要使用Ajax传递参数,需要使用jquery,使用jq ...

  6. Redis Client 官方下载地址

    下载地址:https://github.com/caoxinyu/RedisClient 界面 归途(LM)

  7. 求最长公共子序列-DP问题

    Longest common subsequence problem The longest common subsequence (LCS) problem is the problem of fi ...

  8. Linux搭建nginx+php/php-fpm+mysql环境

    百度内部php框架odp有单独的nginx+php/php-fpm环境,但为了更好的实践,自己搭建一套单独的. 1.首先安装nginx 两种方式: 1)yum源安装(使用root权限)yum inst ...

  9. win7/win8下vmware/VirtualBox虚拟网卡显示未识别网络的解决

    http://blog.csdn.net/zengxianying/article/details/44017227

  10. Python Web 基础向(四) 浅谈数据层

    数据层一般会给人带来一些困扰,在于其定位不准确.聚合Model的工作也可以放在逻辑层做,但会导致逻辑层变重,经常出现大段晦涩代码.因此我的建议是保留Model聚合层,尽管会导致工作量的略微增加,但却可 ...