redis服务命令
- redis-server --service-install redis.windows.conf --loglevel verbose // 安装redis服务
- redis-server.exe redis.windows.conf //启动redis服务
- redis-server --service-uninstall //卸载服务
- redis-server --service-stop //卸载服务
web项目需要引入的jar包
链接:https://pan.baidu.com/s/1zLnXh8M6PuSzqOk4Uf4m4w 提取码:hugo
项目xml相关配置
<!-- Jedis连接池配置参数 -->
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<!-- 控制一个pool最多有多少个状态为idle(空闲)的jedis实例 -->
<property name="maxIdle" value="100"></property>
<!-- 控制一个pool可分配多少个jedis实例 -->
<property name="maxTotal" value="200"></property>
<!-- 表示当borrow一个jedis实例时,最大的等待时间,如果超过等待时间,则直接抛出JedisConnectionException -->
<property name="maxWaitMillis" value="1000"></property>
<!-- 在borrow一个jedis实例时,是否提前进行validate操作;如果为true,则得到的jedis实例均是可用的 -->
<property name="testOnBorrow" value="true"></property>
</bean>
<!--redis连接工厂 -->
<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<!-- 连接池配置引用 -->
<property name="poolConfig" ref="jedisPoolConfig"></property>
<!-- 主机IP地址 -->
<property name="hostName" value="你的IP地址"></property>
<!-- 端口号 -->
<property name="port" value="6379"></property>
<!-- 访问密码 -->
<property name="password" value="你设置的访问密码" />
<!-- 是否使用池 -->
<property name="usePool" value="true"></property>
</bean>
<!-- 将session放入redis -->
<bean id="redisHttpSessionConfiguration" class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration">
<!-- session过期时间,单位是秒 -->
<property name="maxInactiveIntervalInSeconds" value="1800"/>
</bean>
web.xml 相关文件配置
<!-- spring session的过滤器配置,注意此过滤器必须放在其他过滤器之前 -->
<filter>
<filter-name>springSessionRepositoryFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSessionRepositoryFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>