spring-session之3 redis配置参数配置

spring-session之3 redis配置参数配置

前文,我们 spring-session之2 依葫芦画瓢做个小项目, 做了一个非常简单的小例子,现在我们需要修改redis相关参数,总不能老是使用 localhost:6379 吧, 怎么办? 以及 spring-session还有哪些参数可以修改?

好,今天的目标是:

  1. 修改spring-session redis ip以及端口参数
  2. 了解spring-session redis 还有什么其他参数

1. 修改ip和端口号

为了演示方便, 这里把默认的本地地址(localhost)换成内网地址

先查询下 ipconfig 内网地址

是 10.88.54.169

再修改 spring-session.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
        xmlns:p="http://www.springframework.org/schema/p"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

        <context:annotation-config />

        <!-- RedisHttpSessionConfiguration -->
        <bean class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration" />

        <!--JedisConnectionFactory -->
        <bean class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
            <property name="hostName" value="10.88.54.169" />
            <property name="port" value="6379" />
        </bean>
    </beans>

重启应用

项目启动成功

并且成功链接redis

2.JedisConnectionFactory 还有什么其他属性?

通常要看 一个bean 有哪些参数可以设置,看他有什么 set 方法

参数表格一览:

参数 类型 说明 默认
convertPipelineAndTxResults boolean Specifies if pipelined results should be converted to the expected data type. If false, results of JedisConnection.closePipeline() and JedisConnection.exec() will be of the type returned by the Jedis driver true
database int Sets the index of the database used by this connection factory. 0
hostName String redis 地址 localhost
password String password used for authenticating with the Redis server.
poolConfig JedisPoolConfig Sets the pool configuration for this factory new JedisPoolConfig()
port int redis 连接端口号 6379
shardInfo JedisShardInfo Sets the shard info for this factory.
timeout int redis 连接超时时间 2000
usePool boolean Turns on or off the use of connection pooling true

--to be continued

猜你喜欢

转载自feitianbenyue.iteye.com/blog/2327122