您现在的位置是:主页 > news > 为赌博网站做宣传/网址查询ip地址

为赌博网站做宣传/网址查询ip地址

admin2025/6/18 11:23:52news

简介为赌博网站做宣传,网址查询ip地址,邢台wap网站建设价格,wordpress文章页实现图片幻灯展现一、添加依赖 请注意你的spring版本与spring-data-redis依赖的版本是否一致&#xff0c;若spring-data-redis内依赖的spring版本比你项目使用的spring版本高&#xff0c;则会出现各种异常信息&#xff08;踩坑&#xff09;。 <dependency><groupId>redis.clients…

为赌博网站做宣传,网址查询ip地址,邢台wap网站建设价格,wordpress文章页实现图片幻灯展现一、添加依赖 请注意你的spring版本与spring-data-redis依赖的版本是否一致&#xff0c;若spring-data-redis内依赖的spring版本比你项目使用的spring版本高&#xff0c;则会出现各种异常信息&#xff08;踩坑&#xff09;。 <dependency><groupId>redis.clients…

一、添加依赖

请注意你的spring版本与spring-data-redis依赖的版本是否一致,若spring-data-redis内依赖的spring版本比你项目使用的spring版本高,则会出现各种异常信息(踩坑)。

<dependency><groupId>redis.clients</groupId><artifactId>jedis</artifactId><version>2.9.0</version>
</dependency>
<dependency><groupId>org.springframework.data</groupId><artifactId>spring-data-redis</artifactId><version>2.1.20.RELEASE</version>
</dependency>

二、配置applicationContext.xml

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"><property name="locations"><list><!-- 这里支持多种寻址方式:classpath和file --><value>classpath:jdbc.properties</value><value>classpath:redis.properties</value><!-- 推荐使用file的方式引入,这样可以将配置和代码分离 --></list></property>
</bean><!-- 配置JedisPoolConfig实例 -->
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig"><property name="maxIdle" value="${redis.maxIdle}"/><property name="maxTotal" value="${redis.maxActive}"/><property name="maxWaitMillis" value="${redis.maxWait}"/><property name="testOnBorrow" value="${redis.testOnBorrow}"/>
</bean>
<!-- 配置JedisConnectionFactory -->
<!-- spring data redis -->
<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"><property name="usePool" value="true"></property><property name="hostName" value="${redis.host}"/><property name="port" value="${redis.port}"/><property name="password" value="${redis.password}"/><property name="timeout" value="${redis.timeout}"/><property name="database" value="${redis.default.db}"></property><constructor-arg index="0" ref="jedisPoolConfig"/>
</bean>
<!-- 配置RedisTemplate -->
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate"><property name="connectionFactory" ref="jedisConnectionFactory"/><property name="enableTransactionSupport" value="true"></property><!--序列化配置--><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.StringRedisSerializer"/></property>
</bean>

三、配置redis.properties

# Redis settings
redis.host=127.0.0.1
redis.port=6379
redis.password=
redis.timeout=360000
redis.default.db=0
redis.maxIdle=300
redis.maxActive=600
redis.maxWait=1000
redis.testOnBorrow=true

四、RedisCacheConfig

import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;import java.lang.reflect.Method;/*** @ClassName: RedisCacheConfig* @Author: liangsw* @Description:* @Date: 2021/6/10 13:23* @Version: 1.0*/
@Configuration
@EnableCaching
public class RedisCacheConfig extends CachingConfigurerSupport {private volatile JedisConnectionFactory mJedisConnectionFactory;private volatile RedisTemplate<String, String> mRedisTemplate;private volatile RedisCacheManager mRedisCacheManager;public RedisCacheConfig() {super();}public RedisCacheConfig(JedisConnectionFactory mJedisConnectionFactory, RedisTemplate<String, String> mRedisTemplate, RedisCacheManager mRedisCacheManager) {super();this.mJedisConnectionFactory = mJedisConnectionFactory;this.mRedisTemplate = mRedisTemplate;this.mRedisCacheManager = mRedisCacheManager;}public JedisConnectionFactory redisConnectionFactory() {return mJedisConnectionFactory;}public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory cf) {return mRedisTemplate;}public CacheManager cacheManager(RedisTemplate<?, ?> redisTemplate) {return mRedisCacheManager;}@Beanpublic KeyGenerator customKeyGenerator() {return new KeyGenerator() {@Overridepublic Object generate(Object o, Method method, Object... objects) {StringBuilder sb = new StringBuilder();sb.append(o.getClass().getName());sb.append(method.getName());for (Object obj : objects) {sb.append(obj.toString());}return sb.toString();}};}
}

五、redis工具类

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.*;
import org.springframework.stereotype.Component;import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;/*** @ClassName:RedisUtils* @Description:Redis工具类*/
@Component
public class RedisUtils {@Resource@Qualifier("redisTemplate")private RedisTemplate redisTemplate;private static double size = Math.pow(2, 32);/*** 写入缓存** @param key* @param offset 位 8Bit=1Byte* @return*/public boolean setBit(String key, long offset, boolean isShow) {boolean result = false;try {ValueOperations<Serializable, Object> operations = redisTemplate.opsForValue();operations.setBit(key, offset, isShow);result = true;} catch (Exception e) {e.printStackTrace();}return result;}/*** 写入缓存** @param key* @param offset* @return*/public boolean getBit(String key, long offset) {boolean result = false;try {ValueOperations<Serializable, Object> operations = redisTemplate.opsForValue();result = operations.getBit(key, offset);} catch (Exception e) {e.printStackTrace();}return result;}/*** 写入缓存** @param key* @param value* @return*/public boolean set(final String key, Object value) {boolean result = false;try {ValueOperations<Serializable, Object> operations = redisTemplate.opsForValue();operations.set(key, value);result = true;} catch (Exception e) {e.printStackTrace();}return result;}/*** 写入缓存设置时效时间** @param key* @param value* @return*/public boolean set(final String key, Object value, Long expireTime) {boolean result = false;try {ValueOperations<Serializable, Object> operations = redisTemplate.opsForValue();operations.set(key, value);redisTemplate.expire(key, expireTime, TimeUnit.SECONDS);result = true;} catch (Exception e) {e.printStackTrace();}return result;}/*** 批量删除对应的value** @param keys*/public void remove(final String... keys) {for (String key : keys) {remove(key);}}/*** 删除对应的value** @param key*/public void remove(final String key) {if (exists(key)) {redisTemplate.delete(key);}}/*** 判断缓存中是否有对应的value** @param key* @return*/public boolean exists(final String key) {return redisTemplate.hasKey(key);}/*** 读取缓存** @param key* @return*/public Object get(final String key) {Object result = null;ValueOperations<Serializable, Object> operations = redisTemplate.opsForValue();result = operations.get(key);return result;}/*** 哈希 添加** @param key* @param hashKey* @param value*/public void hmSet(String key, Object hashKey, Object value) {HashOperations<String, Object, Object> hash = redisTemplate.opsForHash();hash.put(key, hashKey, value);}/*** 哈希获取数据** @param key* @param hashKey* @return*/public Object hmGet(String key, Object hashKey) {HashOperations<String, Object, Object> hash = redisTemplate.opsForHash();return hash.get(key, hashKey);}/*** 列表添加** @param k* @param v*/public void lPush(String k, Object v) {ListOperations<String, Object> list = redisTemplate.opsForList();list.rightPush(k, v);}/*** 列表获取** @param k* @param l* @param l1* @return*/public List<Object> lRange(String k, long l, long l1) {ListOperations<String, Object> list = redisTemplate.opsForList();return list.range(k, l, l1);}/*** 集合添加** @param key* @param value*/public void add(String key, Object value) {SetOperations<String, Object> set = redisTemplate.opsForSet();set.add(key, value);}/*** 集合获取** @param key* @return*/public Set<Object> setMembers(String key) {SetOperations<String, Object> set = redisTemplate.opsForSet();return set.members(key);}/*** 有序集合添加** @param key* @param value* @param scoure*/public void zAdd(String key, Object value, double scoure) {ZSetOperations<String, Object> zset = redisTemplate.opsForZSet();zset.add(key, value, scoure);}/*** 有序集合获取** @param key* @param scoure* @param scoure1* @return*/public Set<Object> rangeByScore(String key, double scoure, double scoure1) {ZSetOperations<String, Object> zset = redisTemplate.opsForZSet();redisTemplate.opsForValue();return zset.rangeByScore(key, scoure, scoure1);}//第一次加载的时候将数据加载到redis中public void saveDataToRedis(String name) {double index = Math.abs(name.hashCode() % size);long indexLong = new Double(index).longValue();boolean availableUsers = setBit("availableUsers", indexLong, true);}//第一次加载的时候将数据加载到redis中public boolean getDataToRedis(String name) {double index = Math.abs(name.hashCode() % size);long indexLong = new Double(index).longValue();return getBit("availableUsers", indexLong);}/*** 有序集合获取排名** @param key   集合名称* @param value 值*/public Long zRank(String key, Object value) {ZSetOperations<String, Object> zset = redisTemplate.opsForZSet();return zset.rank(key, value);}/*** 有序集合获取排名** @param key*/public Set<ZSetOperations.TypedTuple<Object>> zRankWithScore(String key, long start, long end) {ZSetOperations<String, Object> zset = redisTemplate.opsForZSet();Set<ZSetOperations.TypedTuple<Object>> ret = zset.rangeWithScores(key, start, end);return ret;}/*** 有序集合添加** @param key* @param value*/public Double zSetScore(String key, Object value) {ZSetOperations<String, Object> zset = redisTemplate.opsForZSet();return zset.score(key, value);}/*** 有序集合添加分数** @param key* @param value* @param scoure*/public void incrementScore(String key, Object value, double scoure) {ZSetOperations<String, Object> zset = redisTemplate.opsForZSet();zset.incrementScore(key, value, scoure);}/*** 有序集合获取排名** @param key*/public Set<ZSetOperations.TypedTuple<Object>> reverseZRankWithScore(String key, long start, long end) {ZSetOperations<String, Object> zset = redisTemplate.opsForZSet();Set<ZSetOperations.TypedTuple<Object>> ret = zset.reverseRangeByScoreWithScores(key, start, end);return ret;}/*** 有序集合获取排名** @param key*/public Set<ZSetOperations.TypedTuple<Object>> reverseZRankWithRank(String key, long start, long end) {ZSetOperations<String, Object> zset = redisTemplate.opsForZSet();Set<ZSetOperations.TypedTuple<Object>> ret = zset.reverseRangeWithScores(key, start, end);return ret;}
}

六、Spring项目启动时加载缓存信息

import com.fsd.zhcs.resources.citydata.CityDataService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;import javax.annotation.Resource;
import java.util.List;
import java.util.Map;/*** @ClassName: InitRedisCacheRunner* @Author: liangsw* @Description:* @Date: 2021/6/10 11:19* @Version: 1.0*/
@Component
@Order(value = 2)
public class InitRedisCacheRunner implements ApplicationListener<ContextRefreshedEvent> {protected final Logger logger = LoggerFactory.getLogger(getClass());@ResourceRedisUtils redisUtils;@ResourceCityDataService cityDataService;@Overridepublic void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {logger.info("InitRedisCacheRunner加载缓存信息start>>>>>>>");redisUtils.set("myName","liangsw");List<Map<String, String>> buildings = cityDataService.getBuildings();redisUtils.lPush("getBuildings", buildings);logger.info("InitRedisCacheRunner加载缓存信息End<<<<<<<<");}
}