如何在Redis中存储Spring会话

时间:2019-07-04 11:56:12

标签: java spring redis

我是Redis的新手。我想将Spring session存储在Redis中。

我用xml配置创建spring应用程序。我添加了redis和jedis id的

<bean id="jedisConnectionFactoryclass="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
             IP address
    <property name="hostName" value="http://127.0.0.1"/>
             Password
    <property name="password" value=""/>
             Port number
    <property name="port" value="6379"/>
             Timeout time Default 2000
    <property name="timeout" value="100000"/>
             Connection pool configuration reference

             usePool: Whether to use connection pool
    <property name="usePool" value="true"/>
 </bean>

<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
    <property name="connectionFactory" ref="jedisConnectionFactory"/>
    <property name="keySerializer">
        <bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
    </property>
    <property name="valueSerializer">
        <bean class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer"/>
    </property>
    <property name="hashKeySerializer">
        <bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
    </property>
    <property name="hashValueSerializer">
        <bean class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer"/>
    </property>
             Open transaction
    <property name="enableTransactionSupport" value="true"></property>
</bean>

<dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-redis</artifactId>
        <version>1.7.2.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>redis.clients</groupId>
        <artifactId>jedis</artifactId>
        <version>2.6.2</version>
    </dependency> 
    <dependency>
        <groupId>org.springframework.session</groupId>
        <artifactId>spring-session</artifactId>
        <version>1.3.3.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.session</groupId>
        <artifactId>spring-session-data-redis</artifactId>
        <version>1.3.5.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>io.lettuce</groupId>
        <artifactId>lettuce-core</artifactId>
        <version>5.1.1.RELEASE</version>
    </dependency>

以上依赖项已添加到pom中。 redis-cli监视器中没有任何显示。 我安装了redis -cli一台服务器196.123.0.14

0 个答案:

没有答案