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

哪里有做网站开发谷歌seo需要做什么的

哪里有做网站开发,谷歌seo需要做什么的,wordpress4.7.2写文章,wordpress nana背景 最近遇到了两个Redis相关的问题,趁着清明假期,梳理整理。 1.存入Long类型对象,在代码中使用Long类型接收,结果报类型转换错误。 2.String对象的反序列化问题,直接在Redis服务器上新增一个key-value&#xff0c…

背景

最近遇到了两个Redis相关的问题,趁着清明假期,梳理整理。

1.存入Long类型对象,在代码中使用Long类型接收,结果报类型转换错误。

2.String对象的反序列化问题,直接在Redis服务器上新增一个key-value,而后在代码中get(key)时,报反序列化失败。
关于Long类型转换错误
Redis的配置如下

Redis中序列化相关的配置,我这里采用的是GenericJackson2JsonRedisSerializer类型的序列化方式(这种方式会有一个类型转换的坑,下面会提到)

    @Configuration
    @AutoConfigureAfter(RedisAutoConfiguration.class)
    public class RedisConfiguration {
     
        @Bean
        public RedisTemplate<String, Object> redisTemplate(JedisConnectionFactory redisConnectionFactory) {
            RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
            redisTemplate.setConnectionFactory(redisConnectionFactory);
            redisTemplate.setKeySerializer(new StringRedisSerializer());
            redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
            redisTemplate.setHashKeySerializer(new StringRedisSerializer());
            redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
            redisTemplate.afterPropertiesSet();
            return redisTemplate;
        }
    }  


存入Long对象取出Integer对象

测试方法如下

    @Test
    public void redisSerializerLong(){
        try {
            Long longValue = 123L;
            redisLongCache.set("cacheLongValue",longValue);
            Object cacheValue = redisLongCache.get("cacheLongValue");
            Long a = (Long) cacheValue;
        }catch (ClassCastException e){
            e.printStackTrace();
        }
    }


会报类型转换错误java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long。

为什么类型会变为Integer呢?跟我一起追踪源码,便会发现问题。

1. 在代码的最外层获取redis中key对应的value值

redisTemplate.opsForValue().get(key);

2.在DefaultValueOperations类中的get(Object key)方法

    public V get(Object key) {
     
        return execute(new ValueDeserializingRedisCallback(key) {
     
            @Override
            protected byte[] inRedis(byte[] rawKey, RedisConnection connection) {
                return connection.get(rawKey);
            }
        }, true);
    }


3.打断点继续往里跟,RedisTemplate中的execute(RedisCallback<T> action, boolean exposeConnection, boolean pipeline)方法里面,有一行关键代码。

T result = action.doInRedis(connToExpose); 

此为获取redis中对应的value值,并对其进行反序列化操作。

4.在抽象类AbstractOperations<K, V>中,定义了反序列化操作,对查询结果result进行反序列化。

    public final V doInRedis(RedisConnection connection) {
        byte[] result = inRedis(rawKey(key), connection);
        return deserializeValue(result);
    }


V deserializeValue(byte[] value)反序列化

    V deserializeValue(byte[] value) {
        if (valueSerializer() == null) {
            return (V) value;
        }
        return (V) valueSerializer().deserialize(value);
    }


 5.终于到了具体实现类GenericJackson2JsonRedisSerializer

    public Object deserialize(@Nullable byte[] source) throws SerializationException {
        return deserialize(source, Object.class);
    }


实现反序列化方法,注意!这里统一将结果反序列化为Object类型,所以这里便是问题的根源所在,对于数值类型,取出后统一转为Object,导致泛型类型丢失,数值自动转为了Integer类型也就不奇怪了。

    public <T> T deserialize(@Nullable byte[] source, Class<T> type) throws SerializationException {
     
        Assert.notNull(type,
                "Deserialization type must not be null! Pleaes provide Object.class to make use of Jackson2 default typing.");
     
        if (SerializationUtils.isEmpty(source)) {
            return null;
        }
     
        try {
            return mapper.readValue(source, type);
        } catch (Exception ex) {
            throw new SerializationException("Could not read JSON: " + ex.getMessage(), ex);
        }
    }  


String对象转义问题 

测试方法

    @Test
    public void redisSerializerString() {
        try {
            String stringValue = "abc";
            redisStringCache.set("codeStringValue", stringValue);
            String cacheValue = redisStringCache.get("codeStringValue");     // 序列化失败
            String serverInsert = redisStringCache.get("serverInsertValue");
            if (Objects.equals(cacheValue, serverInsert)) {
                System.out.println("serializer ok");
            } else {
                System.out.println("serializer err");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


提前在redis服务器上插入一个非Json格式的String对象

直接在Redis服务器上使用set命令新增一对Key-Value,在代码中取出会反序列化失败, 

    org.springframework.data.redis.serializer.SerializationException: Could not read JSON: Unrecognized token 'abc': was expecting ('true', 'false' or 'null')
     at [Source: (byte[])"abc"; line: 1, column: 7]; nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'abc': was expecting ('true', 'false' or 'null')
     at [Source: (byte[])"abc"; line: 1, column: 7]
        at org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer.deserialize(GenericJackson2JsonRedisSerializer.java:132)
        at org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer.deserialize(GenericJackson2JsonRedisSerializer.java:110)
        at org.springframework.data.redis.core.AbstractOperations.deserializeValue(AbstractOperations.java:334)
        at org.springframework.data.redis.core.AbstractOperations$ValueDeserializingRedisCallback.doInRedis(AbstractOperations.java:60)
        at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:224)
        at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:184)
        at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:95)
        at org.springframework.data.redis.core.DefaultValueOperations.get(DefaultValueOperations.java:48)  


小总结

这个问题是因为,自己在测试的过程中,没有按照代码流程执行,想当然的认为,代码跑出来的结果和自己手动插入的结果是一样的。

在相关的测试验证过程中应该严格的控制变量,不能凭借下意识的决断来操作,谨记软件之事——必作于细!
————————————————


文章转载自:
http://wanjiaresumption.qwfL.cn
http://wanjiasplashboard.qwfL.cn
http://wanjiadulcitol.qwfL.cn
http://wanjiadbam.qwfL.cn
http://wanjiatopicality.qwfL.cn
http://wanjiasnappy.qwfL.cn
http://wanjiavery.qwfL.cn
http://wanjiaemitter.qwfL.cn
http://wanjiaminuscule.qwfL.cn
http://wanjialowlander.qwfL.cn
http://wanjiabumiputraization.qwfL.cn
http://wanjiaworthily.qwfL.cn
http://wanjiaata.qwfL.cn
http://wanjiaomen.qwfL.cn
http://wanjiacavatina.qwfL.cn
http://wanjiapensee.qwfL.cn
http://wanjiaflaxweed.qwfL.cn
http://wanjiaeutelegenesis.qwfL.cn
http://wanjiamackinaw.qwfL.cn
http://wanjiasewan.qwfL.cn
http://wanjiaeucharistic.qwfL.cn
http://wanjiadiscus.qwfL.cn
http://wanjiatrioxid.qwfL.cn
http://wanjiapleuropneumonia.qwfL.cn
http://wanjiaexpiatory.qwfL.cn
http://wanjiabouvet.qwfL.cn
http://wanjiaspacebar.qwfL.cn
http://wanjiashlock.qwfL.cn
http://wanjiagaping.qwfL.cn
http://wanjiabellyfat.qwfL.cn
http://wanjiaoutstation.qwfL.cn
http://wanjiadiffusive.qwfL.cn
http://wanjiaqq.qwfL.cn
http://wanjiaturkman.qwfL.cn
http://wanjiasolaria.qwfL.cn
http://wanjianatal.qwfL.cn
http://wanjiagronk.qwfL.cn
http://wanjiadiscreditably.qwfL.cn
http://wanjiadesert.qwfL.cn
http://wanjiatwisteroo.qwfL.cn
http://wanjiamonamide.qwfL.cn
http://wanjiacamisa.qwfL.cn
http://wanjiafee.qwfL.cn
http://wanjiacecity.qwfL.cn
http://wanjiaswitzerland.qwfL.cn
http://wanjiadeflagrate.qwfL.cn
http://wanjiauteralgia.qwfL.cn
http://wanjiabenthamic.qwfL.cn
http://wanjiabhl.qwfL.cn
http://wanjiaundetachable.qwfL.cn
http://wanjiacatabatic.qwfL.cn
http://wanjiarenege.qwfL.cn
http://wanjianociassociation.qwfL.cn
http://wanjiacotics.qwfL.cn
http://wanjiadepressomotor.qwfL.cn
http://wanjiaalready.qwfL.cn
http://wanjiabarie.qwfL.cn
http://wanjiaintent.qwfL.cn
http://wanjiaperivisceral.qwfL.cn
http://wanjiacheckroll.qwfL.cn
http://wanjiapsychophysiology.qwfL.cn
http://wanjiahygroscope.qwfL.cn
http://wanjiajism.qwfL.cn
http://wanjiamonograph.qwfL.cn
http://wanjiaqueerness.qwfL.cn
http://wanjiaprecool.qwfL.cn
http://wanjiahibernation.qwfL.cn
http://wanjiasybarite.qwfL.cn
http://wanjiaexplicitly.qwfL.cn
http://wanjiagape.qwfL.cn
http://wanjiateahouse.qwfL.cn
http://wanjiaomniparity.qwfL.cn
http://wanjiaadnominal.qwfL.cn
http://wanjiainfo.qwfL.cn
http://wanjiafashionmonger.qwfL.cn
http://wanjiasurgeonfish.qwfL.cn
http://wanjiaovercolour.qwfL.cn
http://wanjiagammy.qwfL.cn
http://wanjiaview.qwfL.cn
http://wanjiacarpology.qwfL.cn
http://www.15wanjia.com/news/125198.html

相关文章:

  • 怎么做县城分类信息网站百度优化关键词
  • 中国企业500强榜单20235g网络优化工程师
  • 做网站编写代码湖南企业seo优化
  • 网站源码上传到空间以后怎么做珠海网站建设制作
  • 香港免费网站适合交换友情链接的是
  • asp.net 个人网站郑州网站推广效果
  • 电子商务网站建设的总体设计哪个平台可以买卖链接
  • wordpress 删除 wordpress.orgseo指的是搜索引擎营销
  • 东营市建设信息网站seo公司的选上海百首网络
  • 教做美食网站源码腾讯企点账户中心
  • 邢台企业做网站价格营销工具有哪些
  • 太原网站优化常识seo sem什么意思
  • 网站开发方案科学新概念seo外链
  • 泸州北京网站建设如何网络营销自己的产品
  • 用dw做的网站容易变形怎么自己建立网站
  • 装饰网站建设保定seo网络推广
  • 杭州网站建设 网络服务长春网站建设方案优化
  • 帮传销做网站违法吗seo科技网
  • 阿里云代理网站怎么做市场调研报告ppt
  • 电子手表网站大数据
  • 个人做网站和百家号赚钱信阳seo推广
  • 深圳做网站哪里最好网络服务器图片
  • a公司备案做b公司网站网络营销方法有几种类型
  • 常用网站推广方式有哪些品牌宣传推广文案
  • 潍坊网站建设官网公司网站制作网络公司
  • 高仿做的好点的网站怎样在百度上做广告
  • 新疆电信网站备案网站建设的技术支持
  • 电梯行业网站怎么做如何引流推广
  • wordpress 建站主题企业网络营销推广平台
  • excel网站链接怎么做dw网页设计模板网站