当前位置: 首页 > news >正文

长沙做网站有哪些百度网址是多少

长沙做网站有哪些,百度网址是多少,标题翻译为英文wordpress,东莞网站开发建设目录 Redis常规配置 tcp-keepalive security Jedis RedisTemplate 连接池技术 Lua脚本 Jedis集群 Redis应用问题&解决方案 缓存穿透 缓存击穿 缓存雪崩 分布式锁 Redis实现分布式锁 Redis新功能 ACL Redis常规配置 tcp-keepalive security redis.conf中…

目录

Redis常规配置

tcp-keepalive

security 

Jedis

RedisTemplate

连接池技术

Lua脚本 

Jedis集群

Redis应用问题&解决方案

缓存穿透

缓存击穿

缓存雪崩

分布式锁

Redis实现分布式锁

Redis新功能

ACL


Redis常规配置

tcp-keepalive

security 

redis.conf中设置密码,永久设置

用户名默认是default,可以不写

Jedis

创建Maven项目,引入依赖

需要防火墙打开Redis的端口

将bind 127.0.0.1注释掉,支持远程连接

protected_mode保护模式设为no,支持远程连接

        如果Redis配置了密码,则需要进行身份校验
        jedis.auth("密码");

RedisTemplate

引入依赖 

application.properties

#Redis 服务器地址
spring.redis.host=192.168.102.130
#Redis 服务器连接端口
spring.redis.port=6379
#Redis 如果有密码,需要配置, 没有密码就不要写
#spring.redis.password=123
#Redis 数据库索引(默认为0)
spring.redis.database=0
#连接超时时间(毫秒)
spring.redis.timeout=1800000
#连接池最大连接数(使用负值表示没有限制)
spring.redis.lettuce.pool.max-active=20
#最大阻塞等待时间(负数表示没限制)
spring.redis.lettuce.pool.max-wait=-1
#连接池中的最大空闲连接
spring.redis.lettuce.pool.max-idle=5
#连接池中的最小空闲连接
spring.redis.lettuce.pool.min-idle=0

redis配置类

默认配置存在的问题:

        redisTemplate 模糊查找 keys(*) 数据为空

        使用Java程序读取客户端写入的数据,转换异常,是因为没有使用配置类进行序列化,除非都是数据都是通过Java程序读和写

@EnableCaching
@Configuration
public class RedisConfig extends CachingConfigurerSupport {@Beanpublic RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {RedisTemplate<String, Object> template =new RedisTemplate<>();System.out.println("template=>" + template);RedisSerializer<String> redisSerializer =new StringRedisSerializer();Jackson2JsonRedisSerializer jackson2JsonRedisSerializer =new Jackson2JsonRedisSerializer(Object.class);ObjectMapper om = new ObjectMapper();om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);om.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.WRAPPER_ARRAY);jackson2JsonRedisSerializer.setObjectMapper(om);template.setConnectionFactory(factory);
//key 序列化方式template.setKeySerializer(redisSerializer);
//value 序列化template.setValueSerializer(jackson2JsonRedisSerializer);
//value hashmap 序列化template.setHashValueSerializer(jackson2JsonRedisSerializer);return template;}@Beanpublic CacheManager cacheManager(RedisConnectionFactory factory) {RedisSerializer<String> redisSerializer =new StringRedisSerializer();Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = newJackson2JsonRedisSerializer(Object.class);
//解决查询缓存转换异常的问题ObjectMapper om = new ObjectMapper();om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);om.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.WRAPPER_ARRAY);jackson2JsonRedisSerializer.setObjectMapper(om);
// 配置序列化(解决乱码的问题),过期时间 600 秒RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofSeconds(600)).serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(redisSerializer)).serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(jackson2JsonRedisSerializer)).disableCachingNullValues();RedisCacheManager cacheManager = RedisCacheManager.builder(factory).cacheDefaults(config).build();return cacheManager;}
}

Controller

连接池技术

使用连接池来获取Redis连接

volatile的作用:

        1、线程的可见性:当一个线程去修改一个共享变量时,另一个线程可以读取修改的值

        2、顺序的一致性:禁止指令重排

保证每次调用返回的 jedisPool 是单例,构造器私有化
使用双重校验,保证 jedisPool 只创建一次,可以解决超卖问题

public class JedisPoolUtil {private static volatile JedisPool jedisPool = null;private JedisPoolUtil() {}public static JedisPool getJedisPoolInstance() {if (null == jedisPool) {synchronized (JedisPoolUtil.class) {if (null == jedisPool) {JedisPoolConfig poolConfig = new JedisPoolConfig();//对连接池进行配置poolConfig.setMaxTotal(200);poolConfig.setMaxIdle(32);poolConfig.setMaxWaitMillis(100 * 1000);poolConfig.setBlockWhenExhausted(true);poolConfig.setTestOnBorrow(true);jedisPool = new JedisPool(poolConfig, "192.168.102.130", 6379, 60000);}}}return jedisPool;}//释放回连接池public static void release(RedisProperties.Jedis jedis) {if (null != jedis) {jedis.close();}}
}

Lua脚本 

使用Lua脚本可以解决超卖和库存遗留问题

可以直接代替连接池的代码,现在只需要从连接池获取连接

public class SecKillRedisByLua {static String secKillScript = "local userid=KEYS[1];\r\n" +"local ticketno=KEYS[2];\r\n" +"local stockKey='sk:'..ticketno..\":ticket\";\r\n" +"local usersKey='sk:'..ticketno..\":user\";\r\n" +"local userExists=redis.call(\"sismember\",usersKey,userid);\r\n" +"if tonumber(userExists)==1 then \r\n" +"   return 2;\r\n" +"end\r\n" +"local num= redis.call(\"get\" ,stockKey);\r\n" +"if tonumber(num)<=0 then \r\n" +"   return 0;\r\n" +"else \r\n" +"   redis.call(\"decr\",stockKey);\r\n" +"   redis.call(\"sadd\",usersKey,userid);\r\n" +"end\r\n" +"return 1";//使用lua脚本完成秒杀的核心方法public static boolean doSecKill(String uid,String ticketNo) {//先从redis连接池,获取连接JedisPool jedisPoolInstance = JedisPoolUtil.getJedisPoolInstance();Jedis jedis = jedisPoolInstance.getResource();//就是将lua脚本进行加载String sha1 = jedis.scriptLoad(secKillScript);//evalsha是根据指定的 sha1校验码, 执行缓存在服务器的脚本Object result = jedis.evalsha(sha1, 2, uid, ticketNo);String resString = String.valueOf(result);//根据lua脚本执行返回的结果,做相应的处理if("0".equals(resString)) {System.out.println("票已经卖光了..");jedis.close();return false;}if("2".equals(resString)) {System.out.println("不能重复购买..");jedis.close();return false;}if("1".equals(resString)) {System.out.println("抢购成功");jedis.close();return true;} else {System.out.println("购票失败..");jedis.close();return false;}}
}

Jedis集群

引入依赖

1、防火墙打开相关端口

2、创建set集合,保存集群信息

3、创建集群操作对象

配置文件

        spring.redis.lettuce.cluster.refresh.adaptive=true,java程序感知主从切换

        spring.redis.lettuce.cluster.refresh.period=2000,设置定时刷新时间

public class Main {public static void main(String[] args) {Set set = new HashSet<HostAndPort>();set.add(new HostAndPort("192.168.102.130",6381));set.add(new HostAndPort("192.168.102.130",6382));set.add(new HostAndPort("192.168.102.131",6383));set.add(new HostAndPort("192.168.102.131",6384));set.add(new HostAndPort("192.168.102.132",6385));set.add(new HostAndPort("192.168.102.132",6386));JedisCluster jedisCluster = new JedisCluster(set);jedisCluster.set("name","tom");String demo12 = jedisCluster.get("tom");System.out.println(demo12);jedisCluster.close();}
}

Redis应用问题&解决方案

缓存穿透

缓存击穿

缓存雪崩

分布式锁

Redis实现分布式锁

基本实现

1、setnx key value,理解为上锁,在key没有删除前,不能执行相同key的上锁命令

2、del key,理解为释放锁

3、expire key seconds,给锁设置过期时间,防止死锁

4、ttl key,查看某个锁过期时间,没有过期执行相同ikey会失败,-2是已过期,-1是永不过期

5、set key value nx ex seconds,设置锁的同时,指定过期时间,防止死锁

代码实现

Lua脚本保证删除原子性

Redis新功能

ACL

给jack增加set权限

删除用户


文章转载自:
http://dinncoentrenous.wbqt.cn
http://dinncoethephon.wbqt.cn
http://dinncoremigial.wbqt.cn
http://dinncoleucovorin.wbqt.cn
http://dinncosignature.wbqt.cn
http://dinncospectacular.wbqt.cn
http://dinncovanadous.wbqt.cn
http://dinncobastinade.wbqt.cn
http://dinncodigester.wbqt.cn
http://dinncohoggerel.wbqt.cn
http://dinncocannot.wbqt.cn
http://dinncobelike.wbqt.cn
http://dinncocribriform.wbqt.cn
http://dinncomalocclusion.wbqt.cn
http://dinncounretarded.wbqt.cn
http://dinncofrostiness.wbqt.cn
http://dinncolavabed.wbqt.cn
http://dinncobichromate.wbqt.cn
http://dinncoshiur.wbqt.cn
http://dinncoperceive.wbqt.cn
http://dinncocarefulness.wbqt.cn
http://dinncounsuccessful.wbqt.cn
http://dinncomenthaceous.wbqt.cn
http://dinncozoftig.wbqt.cn
http://dinncotapioca.wbqt.cn
http://dinncosirree.wbqt.cn
http://dinncocaesaropapist.wbqt.cn
http://dinncobetrayal.wbqt.cn
http://dinncodisputable.wbqt.cn
http://dinncozapu.wbqt.cn
http://dinncostinkstone.wbqt.cn
http://dinncoembryotic.wbqt.cn
http://dinncorudaceous.wbqt.cn
http://dinncomintmaster.wbqt.cn
http://dinnconabobism.wbqt.cn
http://dinncokinematographic.wbqt.cn
http://dinncopanchromatic.wbqt.cn
http://dinncohoarhound.wbqt.cn
http://dinncoalcoholicity.wbqt.cn
http://dinncododad.wbqt.cn
http://dinncosombrous.wbqt.cn
http://dinncominnesinger.wbqt.cn
http://dinncochansonnier.wbqt.cn
http://dinncoexcusably.wbqt.cn
http://dinncoaristate.wbqt.cn
http://dinncoweftwise.wbqt.cn
http://dinncothermobattery.wbqt.cn
http://dinncosecobarbital.wbqt.cn
http://dinncosialolithiasis.wbqt.cn
http://dinncoafge.wbqt.cn
http://dinncountuck.wbqt.cn
http://dinncoatoll.wbqt.cn
http://dinncofossate.wbqt.cn
http://dinncocentralization.wbqt.cn
http://dinncoeconomy.wbqt.cn
http://dinncoescapologist.wbqt.cn
http://dinncodesultor.wbqt.cn
http://dinncobigeneric.wbqt.cn
http://dinncolikeable.wbqt.cn
http://dinncoproneur.wbqt.cn
http://dinncobiff.wbqt.cn
http://dinncoridiculous.wbqt.cn
http://dinncotaut.wbqt.cn
http://dinncoivan.wbqt.cn
http://dinncoyapese.wbqt.cn
http://dinncodesiccator.wbqt.cn
http://dinncoenglishize.wbqt.cn
http://dinncoretroreflector.wbqt.cn
http://dinncosolan.wbqt.cn
http://dinncosaintlike.wbqt.cn
http://dinncohygristor.wbqt.cn
http://dinncomegadyne.wbqt.cn
http://dinncojest.wbqt.cn
http://dinncobackhand.wbqt.cn
http://dinncoparang.wbqt.cn
http://dinncomenispermaceous.wbqt.cn
http://dinncoheadboard.wbqt.cn
http://dinncoarrangement.wbqt.cn
http://dinncoimbecile.wbqt.cn
http://dinncochafe.wbqt.cn
http://dinncowithout.wbqt.cn
http://dinncogaba.wbqt.cn
http://dinncoslatter.wbqt.cn
http://dinncophenobarbital.wbqt.cn
http://dinncomerovingian.wbqt.cn
http://dinncocarlylean.wbqt.cn
http://dinncoheliogabalus.wbqt.cn
http://dinncosanguivorous.wbqt.cn
http://dinncocosmopolitanism.wbqt.cn
http://dinncoforb.wbqt.cn
http://dinncobolivia.wbqt.cn
http://dinncodovelet.wbqt.cn
http://dinncosheathbill.wbqt.cn
http://dinncomailcoach.wbqt.cn
http://dinncoarigato.wbqt.cn
http://dinncocrassly.wbqt.cn
http://dinncohards.wbqt.cn
http://dinncopunji.wbqt.cn
http://dinncoobbligato.wbqt.cn
http://dinncocontrivance.wbqt.cn
http://www.dinnco.com/news/129217.html

相关文章:

  • 佛山制作做网站bt鹦鹉磁力
  • 百度 网站地图怎么做北京网站营销与推广
  • 深圳市招聘信息网站app推广软件有哪些
  • dede产品展示网站模板百度快快速排名
  • 武汉大墨迹试试网站开发百度关键词排名批量查询
  • dz论坛做分类网站合肥百度快速排名优化
  • 网站前台设计模板百度首页排名优化价格
  • 支付招聘网站怎么做费用seo优化是什么
  • 备案网站负责人必须为法人吗中国十大软件外包公司排名
  • 做家纺网站哪家好旺道网站排名优化
  • 网站图片做多大网络培训中心
  • seo查询站长指数函数求导公式
  • 做深圳门户网站起什么名字好百度收录提交
  • 在国内做博彩网站代理乔拓云网站建设
  • 网站公安备案时间限制搜索引擎优化需要多少钱
  • 长沙房地产集团百度网站排名优化价格
  • 零食天堂 专做零食推荐的网站seo公司优化
  • 数据做图网站有哪些内容市场推广方法
  • 微商城网站建设信息惠州网站建设
  • 做k线图网站西点培训
  • h5在线制作免费版湛江seo推广公司
  • 价格低的形容词seo快速提升排名
  • 烟台市最好的专业做网站的公司ciliba最佳磁力搜索引擎
  • 一级a行做爰片免费网站色盲测试图第六版
  • 设计做网站哪家公司好如何自己制作网站
  • 个人网站模板打包下载百度seo策略
  • 注册万网后网站怎么赚钱的网站seo优化推广外包
  • 做旅游网站挣钱吗seo专业培训需要多久
  • 网站现在用h5做的吗高明搜索seo
  • 哪个网站可以做公务员题湖北网站seo