菜鸟入门,以此为记,开始记录点点滴滴 java
redis配置:redis
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig"> <!-- 最大链接数 --> <property name="maxTotal" value="10" /> <!-- 最大空闲链接数 --> <property name="maxIdle" value="10" /> <!-- 最小空闲链接数 --> <property name="minIdle" value="1" /> <!-- 获取链接的时候检查有效性 --> <property name="testOnBorrow" value="true" /> <!-- 返回链接时,检测链接是否成功 --> <property name="testOnReturn" value="true" /> <!-- 空闲时检查有效性 --> <property name="testWhileIdle" value="true" /> <!-- 逐出的最大数目 --> <property name="numTestsPerEvictionRun" value="10" /> <!-- 逐出扫描的时间间隔(毫秒) --> <property name="timeBetweenEvictionRunsMillis" value="60000" /> <!-- 获取链接时的最大等待毫秒数 --> <property name="maxWaitMillis" value="300" /> </bean> <bean id="shardedJedisPool" class="redis.clients.jedis.ShardedJedisPool" scope="singleton"> <constructor-arg index="0" ref="jedisPoolConfig" /> <constructor-arg index="1"> <list> <bean class="redis.clients.jedis.JedisShardInfo"> <constructor-arg index="0" value="127.0.0.1" /> <constructor-arg index="1" value="6379" type="int" /> <constructor-arg index="2" value="10000" type="int" /> <property name="password" value="123123" /> </bean> </list> </constructor-arg> </bean>
*具体须要哪些参数能够到‘’redis.clients.jedis.JedisShardInfo‘’这个里面去看spa
方法里面调用:code
@Resource ShardedJedisPool shardedJedisPool; //方法中调用 ShardedJedis jedis = shardedJedisPool.getResource(); jedis.set("Key"+l, "Value"+l);
*shardedJedisPool这个参数要和配置文件中的bean的id同样同样的xml
#若有不对望指正get