Spring-session 3 redis configuration parameter configuration

Spring-session 3 redis configuration parameter configuration

In the previous article, we  spring-session之2 依葫芦画瓢做个小项目made a very simple example. Now we need to modify the parameters related to redis. We can't always use  localhost:6379 it. What should we do?  spring-sessionAnd what other parameters can be modified?

Well, today's goals are:

  1. Modify spring-session redis ip and port parameters
  2. Learn spring-session what other parameters redis has

1. Modify ip and port number

For the convenience of demonstration, here the default local address (localhost) is replaced with the intranet address

Check  ipconfig the intranet address first

Yes 10.88.54.169

Modify again 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>

restart the app

Project started successfully

and successfully link redis

2. What other properties does JedisConnectionFactory have?

Usually it depends on what parameters a bean can set, and what set method it has

Parameter table at a glance:

parameter type description default
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

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326681297&siteId=291194637