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

绵阳做网站查询网域名查询

绵阳做网站,查询网域名查询,企业所得税的征收方式有,大连嘉良建设有限公司网站【Spring连载】使用Spring Data访问Redis(四)----RedisTemplate通过RedisTemplate处理对象Working with Objects through RedisTemplate 一、专注String的便利类二、Serializers 大多数用户可能使用RedisTemplate及其相应的包org.springframework.data.r…

【Spring连载】使用Spring Data访问Redis(四)----RedisTemplate通过RedisTemplate处理对象Working with Objects through RedisTemplate

  • 一、专注String的便利类
  • 二、Serializers

大多数用户可能使用RedisTemplate及其相应的包org.springframework.data.redis.core或其reactive变体ReactiveRedisTemplate。由于其丰富的功能集,该template实际上是Redis模块的中心类。template为Redis交互提供了高级抽象。虽然[Reactive]RedisConnection提供了接受和返回二进制值(byte数组)的low-level方法,但template负责序列化和连接管理,使用户无需处理这些细节。
RedisTemplate类实现了RedisOperations接口,其reactive变体ReactiveRedisTemplate实现了ReactiveRedisOperations。
引用[Reactive]RedisTemplate实例上的操作的首选方式是通过[Reactive]RedisOperations接口。
此外,template提供了操作视图(遵循Redis命令参考中的分组),这些视图提供了丰富的通用接口,用于(通过KeyBound接口)对特定类型或特定key进行操作,如下表所示:
操作视图:

接口描述
Key Type 操作
GeoOperationsRedis geospatial 操作, 例如 GEOADD, GEORADIUS,…​
HashOperationsRedis hash 操作
HyperLogLogOperationsRedis HyperLogLog 操作, 例如 PFADD, PFCOUNT,…​
ListOperationsRedis list 操作
SetOperationsRedis set操作
ValueOperationsRedis string (或 value)操作
ZSetOperationsRedis zset (或 sorted set)操作
Key Bound 操作
BoundGeoOperationsRedis key bound geospatial操作
BoundHashOperationsRedis hash key bound操作
BoundKeyOperationsRedis key bound操作
BoundListOperationsRedis list key bound操作
BoundSetOperationsRedis set key bound操作
BoundValueOperationsRedis string (或 value) key bound操作
BoundZSetOperationsRedis zset (或 sorted set) key bound操作

配置后,template是线程安全的,可以在多个实例中重复使用。
RedisTemplate的大部分操作都使用基于Java的序列化程序。这意味着template写或读的任何对象都通过Java进行序列化和反序列化。
你可以更改template上的序列化机制,Redis模块提供了几个实现,这些实现在org.springframework.data.redis.serializer包中提供。有关详细信息,请参阅序列化程序。你还可以将任何序列化程序设置为null,并通过将enableDefaultSerializer属性设置为false让RedisTemplate使用原始字节数组(raw byte arrays)。请注意,template要求所有键都为非null。但是,只要底层序列化程序接受null值,它们就可以为null。有关更多信息,请阅读每个序列化程序的Javadoc。
对于需要某个template视图的情况,请将该视图声明为依赖项并注入template。容器自动执行转换,消除opsFor[X]调用,如以下示例所示:
配置 Template API

@Configuration
class MyConfig {@BeanLettuceConnectionFactory connectionFactory() {return new LettuceConnectionFactory();}@BeanRedisTemplate<String, String> redisTemplate(RedisConnectionFactory connectionFactory) {RedisTemplate<String, String> template = new RedisTemplate<>();template.setConnectionFactory(redisConnectionFactory);return template;}
}

使用RedisTemplate将一个元素推送到List中

public class Example {// inject the actual operations@Autowiredprivate RedisOperations<String, String> operations;// inject the template as ListOperations@Resource(name="redisTemplate")private ListOperations<String, String> listOps;public void addLink(String userId, URL url) {listOps.leftPush(userId, url.toExternalForm());}
}

一、专注String的便利类

由于Redis中存储的键和值通常是java.lang.String,Redis模块为RedisConnection和RedisTemplate提供了两个扩展,分别是StringRedisConnection(及其DefaultStringRedisConnection实现)和StringRedisTemplate,作为密集String操作的一站式解决方案。除了绑定到String键之外,template和连接还使用了StringRedisSerializer,这意味着存储的键和值是可读的(假设Redis和代码中使用相同的编码)。以下列表显示了一个示例:

@Configuration
class RedisConfiguration {@BeanLettuceConnectionFactory redisConnectionFactory() {return new LettuceConnectionFactory();}@BeanStringRedisTemplate stringRedisTemplate(RedisConnectionFactory redisConnectionFactory) {StringRedisTemplate template = new StringRedisTemplate();template.setConnectionFactory(redisConnectionFactory);return template;}
}
public class Example {@Autowiredprivate StringRedisTemplate redisTemplate;public void addLink(String userId, URL url) {redisTemplate.opsForList().leftPush(userId, url.toExternalForm());}
}

与其他Spring模板一样,RedisTemplate和StringRedisTemplate可以通过RedisCallback接口直接与Redis对话。此功能可以给你完全的控制,因为它可以直接与RedisConnection对话。请注意,当使用StringRedisTemplate时,回调将接收StringRedisConnection的实例。下面的例子展示了如何使用RedisCallback接口:

public void useCallback() {redisOperations.execute(new RedisCallback<Object>() {public Object doInRedis(RedisConnection connection) throws DataAccessException {Long size = connection.dbSize();// Can cast to StringRedisConnection if using a StringRedisTemplate((StringRedisConnection)connection).set("key", "value");}});
}

二、Serializers

从框架的角度来看,Redis中存储的数据只有字节。虽然Redis本身支持各种类型,但在大多数情况下,这些类型指的是数据的存储方式,而不是它所代表的内容。由用户决定是将信息转换为字符串还是任何其他对象。
在Spring Data中,用户(自定义)类型和原始数据之间的转换由Spring Data Redis中的org.springframework.data.redis.serializer包处理。
此包包含两种类型的序列化程序,顾名思义,它们负责序列化过程:

  • 基于RedisSerializer的双向序列化程序。
  • 使用RedisElementReader和RedisElementWriter的元素读取器和写入器。

这些变体之间的主要区别在于RedisSerializer主要序列化到byte[],而读写器使用ByteBuffer。
有多种实现(包括本文档中已经提到的两种):

  • JdkSerializationRedisSerializer,默认用于RedisCache和RedisTemplate。
  • StringRedisSerializer。

但是,可以通过Spring OXM支持使用OxmSerializer进行Object/XML映射,或者使用Jackson2JsonRedisSerializer或GenericJackson2JsonRedisSerializer以JSON格式存储数据。
请注意,存储格式不仅限于值。它可以用于键、值或哈希,没有任何限制。

默认情况下,RedisCache和RedisTemplate被配置为使用Java native序列化。众所周知,Java native序列化允许运行由payloads引起的远程代码,这些payloads利用易受攻击的库和类注入未经验证的字节码。操作输入可能导致在反序列化步骤期间在应用程序中运行不需要的代码。因此,不要在不受信任的环境中使用序列化。通常,强烈建议你使用其他消息格式(如JSON)。
如果你担心Java序列化导致的安全漏洞,请考虑核心JVM级别的通用序列化筛选器机制:

  • 筛选传入的序列化数据。
  • JEP 290。
  • OWASP:不可信数据的反序列化。

文章转载自:
http://hypersomnia.bbmx.cn
http://synangium.bbmx.cn
http://nebula.bbmx.cn
http://biennial.bbmx.cn
http://caprifig.bbmx.cn
http://biafra.bbmx.cn
http://oolitic.bbmx.cn
http://criminological.bbmx.cn
http://tremellose.bbmx.cn
http://bushido.bbmx.cn
http://polynome.bbmx.cn
http://motivation.bbmx.cn
http://rapine.bbmx.cn
http://biocybernetics.bbmx.cn
http://pseudoclassic.bbmx.cn
http://officiously.bbmx.cn
http://connive.bbmx.cn
http://easy.bbmx.cn
http://upraise.bbmx.cn
http://raftsman.bbmx.cn
http://machinable.bbmx.cn
http://expo.bbmx.cn
http://undercart.bbmx.cn
http://land.bbmx.cn
http://disannul.bbmx.cn
http://scrappy.bbmx.cn
http://handgun.bbmx.cn
http://theatric.bbmx.cn
http://divinatory.bbmx.cn
http://polymerize.bbmx.cn
http://perseid.bbmx.cn
http://misapprehension.bbmx.cn
http://terroristic.bbmx.cn
http://appersonation.bbmx.cn
http://likewise.bbmx.cn
http://consolation.bbmx.cn
http://loudness.bbmx.cn
http://acidophilus.bbmx.cn
http://murray.bbmx.cn
http://contactant.bbmx.cn
http://puszta.bbmx.cn
http://merryman.bbmx.cn
http://indium.bbmx.cn
http://devoutly.bbmx.cn
http://unstained.bbmx.cn
http://bitter.bbmx.cn
http://nonviable.bbmx.cn
http://detergence.bbmx.cn
http://parvis.bbmx.cn
http://summiteer.bbmx.cn
http://pneumatograph.bbmx.cn
http://hypermnesia.bbmx.cn
http://piston.bbmx.cn
http://parapsychology.bbmx.cn
http://prolepsis.bbmx.cn
http://varix.bbmx.cn
http://misology.bbmx.cn
http://pickwickian.bbmx.cn
http://resinosis.bbmx.cn
http://interestedly.bbmx.cn
http://deedy.bbmx.cn
http://stair.bbmx.cn
http://rheims.bbmx.cn
http://agloat.bbmx.cn
http://xiphosura.bbmx.cn
http://spherically.bbmx.cn
http://waxberry.bbmx.cn
http://featherlight.bbmx.cn
http://recordmaker.bbmx.cn
http://committeewoman.bbmx.cn
http://silvertail.bbmx.cn
http://satem.bbmx.cn
http://scholiastic.bbmx.cn
http://pajama.bbmx.cn
http://pliotron.bbmx.cn
http://kinemometer.bbmx.cn
http://usrc.bbmx.cn
http://diet.bbmx.cn
http://taking.bbmx.cn
http://pastureland.bbmx.cn
http://cedar.bbmx.cn
http://colidar.bbmx.cn
http://multipack.bbmx.cn
http://ingrowth.bbmx.cn
http://geometrist.bbmx.cn
http://russet.bbmx.cn
http://mannose.bbmx.cn
http://ostotheca.bbmx.cn
http://serenade.bbmx.cn
http://zaguan.bbmx.cn
http://fustic.bbmx.cn
http://lavaliere.bbmx.cn
http://enjambment.bbmx.cn
http://dcmg.bbmx.cn
http://juicer.bbmx.cn
http://camisole.bbmx.cn
http://leningrad.bbmx.cn
http://celia.bbmx.cn
http://tostada.bbmx.cn
http://vavasour.bbmx.cn
http://www.15wanjia.com/news/103832.html

相关文章:

  • 亚当学院网站视频建设教程四川seo整站优化
  • 无锡中英文网站建设可口可乐网络营销案例
  • 旅游类网站建设软文营销范文100字
  • 怎么申请 免费网站空间凡科建站的免费使用
  • 58做网站吗网站友情链接查询
  • 如何做镜像网站百度账号官网
  • 网站开发招聘简历模板百度指数峰值查询
  • 微信朋友圈的网站连接怎么做关键词优化快速
  • 医疗营销网站建设湖南专业的关键词优化
  • 兰州易天网站建设公司有哪些收录提交入口网址
  • 网页制作布局模板百度seo排名优化公司哪家强
  • 做网购网站杭州seo网站推广排名
  • 潜江网站建设批发口碑营销的方法
  • 在电脑上建设个人网站哈尔滨seo关键词
  • 成立一个网站平台要多少钱百度平台商家app下载
  • 武进网站建设咨询西安网络推广营销公司
  • 石家庄疫情封城最新消息广西网络优化seo
  • 基础网站建设代码seo顾问服务公司
  • 有没有介绍做私家导游的网站网页优化seo广州
  • 镇江网站关键字优化机构厦门人才网唯一官网招聘
  • 郑州网站建设精英全媒体运营师培训机构
  • 北塘网站制作seo优化方案策划书
  • 做网站主要栏目内友情链接平台广告
  • 电商网销东莞seo管理
  • 青岛专业网站制作设计东莞搜索排名提升
  • ubuntu 建设网站图片外链在线生成
  • 国外免费搭建网站源码太原百度关键词优化
  • 新疆免费网站建设seo搜索引擎推广
  • 做网站平台的营业执照电脑培训学校网站
  • 免费动态网站作业模板品牌营销策划案例ppt