这是我第一个使用 spring-data-redis 的应用程序,我认为我已经很好地理解了这些概念(过去我多次将 JdbcTemplate 与 RDBMS-es 一起使用)。这是正在发生的事情......
我已经使用 JedisConnectionFactory 设置了 RedisTemplate,并且能够成功地 ping Redis 服务器。然而,我无法从服务器获得最简单的数据响应,而且恐怕我遗漏了一些基本的东西,到目前为止我还无法从文档中推断出这些东西。
这是我的 bean.xml 文件的 Redis 部分:
<!-- Redis DAO stuff -->
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate" p:connection-factory-ref="jedisConnectionFactory"/>
<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" p:host-name="${redis.url}" p:port="${redis.port}" p:database="0" />
这是我的 RedisDAO 类中的相关代码部分:
@Autowired
private RedisTemplate<String, Object> template;
public String getTestVal() {
logger.debug("getTestVal() function called++++++++++++++++++++");
template.getConnectionFactory().getConnection().select(0);
logger.debug("22222222222222");
String pingResult = template.getConnectionFactory().getConnection().ping();
logger.debug("333333333333333");
logger.debug("REDIS PING RESULT: " + pingResult);
logger.debug("444444444444444");
logger.debug("HasKey Result: " + template.hasKey("akey"));
logger.debug("555555555555555");
//NAC;P3_TZ_380002878
Object testVal = template.opsForValue().get("akey");
logger.debug("TestVal returned from REdis: " + testVal);
return null;
}
日志文件的相关输出如下:
13:48:21.505 [http-nio-8080-exec-1] DEBUG com.arrow.pricing.dao.RedisDAO - getTestVal() function called++++++++++++++++++++
13:48:21.678 [http-nio-8080-exec-1] DEBUG com.arrow.pricing.dao.RedisDAO - 22222222222222
13:48:21.801 [http-nio-8080-exec-1] DEBUG com.arrow.pricing.dao.RedisDAO - 333333333333333
13:48:21.801 [http-nio-8080-exec-1] DEBUG com.arrow.pricing.dao.RedisDAO - REDIS PING RESULT: PONG
13:48:21.801 [http-nio-8080-exec-1] DEBUG com.arrow.pricing.dao.RedisDAO - 444444444444444
13:48:21.808 [http-nio-8080-exec-1] DEBUG o.s.d.r.core.RedisConnectionUtils - Opening RedisConnection
13:48:21.936 [http-nio-8080-exec-1] DEBUG o.s.d.r.core.RedisConnectionUtils - Closing Redis Connection
13:48:21.937 [http-nio-8080-exec-1] DEBUG com.arrow.pricing.dao.RedisDAO - HasKey Result: false
13:48:21.937 [http-nio-8080-exec-1] DEBUG com.arrow.pricing.dao.RedisDAO - 555555555555555
13:48:21.940 [http-nio-8080-exec-1] DEBUG o.s.d.r.core.RedisConnectionUtils - Opening RedisConnection
13:48:22.009 [http-nio-8080-exec-1] DEBUG o.s.d.r.core.RedisConnectionUtils - Closing Redis Connection
13:48:22.009 [http-nio-8080-exec-1] DEBUG com.arrow.pricing.dao.RedisDAO - TestVal returned from REdis: null
请注意从 Redis 返回的 TestVal 如何为 null,但是如果我针对该服务器的 0(零)数据库使用 redis-cli,我会得到以下响应:
127.0.0.1:6379> get akey
"yo mama"
“哟妈妈”是我期望返回的值。
public String getTestVal() {
template.setDefaultSerializer(new StringRedisSerializer());
template.afterPropertiesSet();
logger.debug("getTestVal() function called++++++++++++++++++++");
template.getConnectionFactory().getConnection().select(0);
logger.debug("22222222222222");
String pingResult = template.getConnectionFactory().getConnection().ping();
logger.debug("333333333333333");
logger.debug("REDIS PING RESULT: " + pingResult);
logger.debug("444444444444444");
logger.debug("HasKey Result: " + template.hasKey("akey"));
logger.debug("555555555555555");
Object testVal = template.opsForValue().get("akey");
logger.debug("TestVal returned from REdis: " + testVal);
return null;
}
注意:添加 StringRedisSerializer 作为 RedisTemplate 的默认序列化程序。感谢您的努力。
最佳答案
RedisOperations 使用 serializers至 translate Java objects转化为 Redis 数据结构值。序列化器默认为 JdkSerializationRedisSerializer。 JDK 序列化程序将您的 String 对象转换为与 ASCII 或 UTF-8 不兼容的 Java 序列化表示形式。查看文档,您可能对 StringRedisSerializer 感兴趣。序列化器需要在RedisTemplate中设置:
@Bean
RedisTemplate<String, String> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
RedisTemplate<String, String> redisTemplate = new RedisTemplate<>();
redisTemplate.setDefaultSerializer(new StringRedisSerializer());
redisTemplate.setConnectionFactory(redisConnectionFactory);
redisTemplate.afterPropertiesSet();
return redisTemplate;
}
关于spring-data-redis ping 有效, key 在那里,没有返回数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35783004/
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
我正在使用Ruby2.1.1和Rails4.1.0.rc1。当执行railsc时,它被锁定了。使用Ctrl-C停止,我得到以下错误日志:~/.rvm/gems/ruby-2.1.1/gems/spring-1.1.2/lib/spring/client/run.rb:47:in`gets':Interruptfrom~/.rvm/gems/ruby-2.1.1/gems/spring-1.1.2/lib/spring/client/run.rb:47:in`verify_server_version'from~/.rvm/gems/ruby-2.1.1/gems/spring-1.1.
这是一道面试题,我没有答对,但还是很好奇怎么解。你有N个人的大家庭,分别是1,2,3,...,N岁。你想给你的大家庭拍张照片。所有的家庭成员都排成一排。“我是家里的friend,建议家庭成员安排如下:”1岁的家庭成员坐在这一排的最左边。每两个坐在一起的家庭成员的年龄相差不得超过2岁。输入:整数N,1≤N≤55。输出:摄影师可以拍摄的照片数量。示例->输入:4,输出:4符合条件的数组:[1,2,3,4][1,2,4,3][1,3,2,4][1,3,4,2]另一个例子:输入:5输出:6符合条件的数组:[1,2,3,4,5][1,2,3,5,4][1,2,4,3,5][1,2,4,5,3][
有时我需要处理键/值数据。我不喜欢使用数组,因为它们在大小上没有限制(很容易不小心添加超过2个项目,而且您最终需要稍后验证大小)。此外,0和1的索引变成了魔数(MagicNumber),并且在传达含义方面做得很差(“当我说0时,我的意思是head...”)。散列也不合适,因为可能会不小心添加额外的条目。我写了下面的类来解决这个问题:classPairattr_accessor:head,:taildefinitialize(h,t)@head,@tail=h,tendend它工作得很好并且解决了问题,但我很想知道:Ruby标准库是否已经带有这样一个类? 最佳
“输出”是一个序列化的OpenStruct。定义标题try(:output).try(:data).try(:title)结束什么会更好?:) 最佳答案 或者只是这样:deftitleoutput.data.titlerescuenilend 关于ruby-on-rails-更好的替代方法try(:output).try(:data).try(:name)?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.c
我正在尝试使用Curbgem执行以下POST以解析云curl-XPOST\-H"X-Parse-Application-Id:PARSE_APP_ID"\-H"X-Parse-REST-API-Key:PARSE_API_KEY"\-H"Content-Type:image/jpeg"\--data-binary'@myPicture.jpg'\https://api.parse.com/1/files/pic.jpg用这个:curl=Curl::Easy.new("https://api.parse.com/1/files/lion.jpg")curl.multipart_form_
无论您是想搭建桌面端、WEB端或者移动端APP应用,HOOPSPlatform组件都可以为您提供弹性的3D集成架构,同时,由工业领域3D技术专家组成的HOOPS技术团队也能为您提供技术支持服务。如果您的客户期望有一种在多个平台(桌面/WEB/APP,而且某些客户端是“瘦”客户端)快速、方便地将数据接入到3D应用系统的解决方案,并且当访问数据时,在各个平台上的性能和用户体验保持一致,HOOPSPlatform将帮助您完成。利用HOOPSPlatform,您可以开发在任何环境下的3D基础应用架构。HOOPSPlatform可以帮您打造3D创新型产品,HOOPSSDK包含的技术有:快速且准确的CAD
本教程将在Unity3D中混合Optitrack与数据手套的数据流,在人体运动的基础上,添加双手手指部分的运动。双手手背的角度仍由Optitrack提供,数据手套提供双手手指的角度。 01 客户端软件分别安装MotiveBody与MotionVenus并校准人体与数据手套。MotiveBodyMotionVenus数据手套使用、校准流程参照:https://gitee.com/foheart_1/foheart-h1-data-summary.git02 数据转发打开MotiveBody软件的Streaming,开始向Unity3D广播数据;MotionVenus中设置->选项选择Unit
文章目录一、概述简介原理模块二、配置Mysql使用版本环境要求1.操作系统2.mysql要求三、配置canal-server离线下载在线下载上传解压修改配置单机配置集群配置分库分表配置1.修改全局配置2.实例配置垂直分库水平分库3.修改group-instance.xml4.启动监听四、配置canal-adapter1修改启动配置2配置映射文件3启动ES数据同步查询所有订阅同步数据同步开关启动4.验证五、配置canal-admin一、概述简介canal是Alibaba旗下的一款开源项目,Java开发。基于数据库增量日志解析,提供增量数据订阅&消费。Git地址:https://github.co
我正在尝试在Rails上安装ruby,到目前为止一切都已安装,但是当我尝试使用rakedb:create创建数据库时,我收到一个奇怪的错误:dyld:lazysymbolbindingfailed:Symbolnotfound:_mysql_get_client_infoReferencedfrom:/Library/Ruby/Gems/1.8/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundleExpectedin:flatnamespacedyld:Symbolnotfound:_mysql_get_client_infoReferencedf