本文整理汇总了Java中org.springframework.data.redis.serializer.JdkSerializationRedisSerializer类的典型用法代码示例。如果您正苦于以下问题:Java JdkSerializationRedisSerializer类的具体用法?Java JdkSerializationRedisSerializer怎么用?Java JdkSerializationRedisSerializer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JdkSerializationRedisSerializer类属于org.springframework.data.redis.serializer包,在下文中一共展示了JdkSerializationRedisSerializer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getObject
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer; //导入依赖的package包/类
@Override
public Object getObject(Object key)
{
Object result = null;
JedisConnection connection = null;
try
{
connection = jedisConnectionFactory.getConnection();
RedisSerializer<Object> serializer = new JdkSerializationRedisSerializer();
result = serializer.deserialize(connection.get(serializer.serialize(key)));
}
catch (JedisConnectionException e)
{
e.printStackTrace();
}
finally
{
if (connection != null) {
connection.close();
}
}
return result;
}
示例2: putObject
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer; //导入依赖的package包/类
@Override
public void putObject(Object key, Object value)
{
JedisConnection connection = null;
try
{
connection = jedisConnectionFactory.getConnection();
RedisSerializer<Object> serializer = new JdkSerializationRedisSerializer();
connection.set(serializer.serialize(key), serializer.serialize(value));
}
catch (JedisConnectionException e)
{
e.printStackTrace();
}
finally
{
if (connection != null) {
connection.close();
}
}
}
示例3: removeObject
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer; //导入依赖的package包/类
@Override
public Object removeObject(Object key)
{
JedisConnection connection = null;
Object result = null;
try
{
connection = jedisConnectionFactory.getConnection();
RedisSerializer<Object> serializer = new JdkSerializationRedisSerializer();
result =connection.expire(serializer.serialize(key), 0);
}
catch (JedisConnectionException e)
{
e.printStackTrace();
}
finally
{
if (connection != null) {
connection.close();
}
}
return result;
}
示例4: testDefaultMsgSerializer
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer; //导入依赖的package包/类
@Test
public void testDefaultMsgSerializer() throws Exception {
RedisTemplate<String, Message<String>> template = new RedisTemplate<String, Message<String>>();
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new JdkSerializationRedisSerializer());
template.setConnectionFactory(connectionFactory);
template.afterPropertiesSet();
adapter.setExpectMessage(true);
adapter.afterPropertiesSet();
adapter.start();
Map<String, Object> headers = new HashMap<>();
headers.put("header1", "foo");
template.boundListOps(currentQueueName).rightPush(new GenericMessage<>("message2", headers));
@SuppressWarnings("unchecked")
Message<String> message = (Message<String>) messages.poll((int)(1000 * timeoutMultiplier), TimeUnit.MILLISECONDS);
assertEquals("message2", message.getPayload());
assertEquals("foo", message.getHeaders().get("header1"));
}
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-redis,代码行数:21,代码来源:RedisQueueInboundChannelAdapterTests.java
示例5: testDefaultMsgSerializer
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer; //导入依赖的package包/类
@Test
public void testDefaultMsgSerializer() throws Exception {
RedisTemplate<String, Message<?>> template = new RedisTemplate<String, Message<?>>();
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new JdkSerializationRedisSerializer());
template.setConnectionFactory(connectionFactory);
template.afterPropertiesSet();
adapter.setExtractPayload(false);
adapter.afterPropertiesSet();
Map<String, Object> headers = new HashMap<String, Object>();
headers.put("header1", "foo");
adapter.handleMessage(new GenericMessage<String>("message2", headers));
Message<?> message = template.boundListOps(QUEUE_NAME).rightPop();
assertEquals("message2", message.getPayload());
assertEquals("foo", message.getHeaders().get("header1"));
}
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-redis,代码行数:19,代码来源:RedisQueueOutboundChannelAdapterTests.java
示例6: DefaultPersistenceService
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer; //导入依赖的package包/类
@Autowired
public DefaultPersistenceService(@Qualifier("orderingTemplate") @NonNull final StringRedisTemplate orderingTemplate,
@Qualifier("valueTemplate") @NonNull final RedisTemplate<String, EmailSchedulingData> valueTemplate) {
this.orderingTemplate = orderingTemplate;
this.orderingTemplate.setEnableTransactionSupport(true);
this.valueTemplate = valueTemplate;
RedisSerializer<String> stringSerializer = new StringRedisSerializer();
JdkSerializationRedisSerializer jdkSerializationRedisSerializer = new JdkSerializationRedisSerializer();
this.valueTemplate.setKeySerializer(stringSerializer);
this.valueTemplate.setValueSerializer(jdkSerializationRedisSerializer);
this.valueTemplate.setHashKeySerializer(stringSerializer);
this.valueTemplate.setHashValueSerializer(stringSerializer);
this.valueTemplate.setEnableTransactionSupport(true);
this.valueTemplate.afterPropertiesSet();
}
示例7: createValueTemplate
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer; //导入依赖的package包/类
@Bean
@Qualifier("valueTemplate")
public RedisTemplate<String, EmailSchedulingData> createValueTemplate() throws IOException {
RedisTemplate<String, EmailSchedulingData> template = new RedisTemplate<>();
RedisSerializer<String> stringSerializer = new StringRedisSerializer();
JdkSerializationRedisSerializer jdkSerializationRedisSerializer = new JdkSerializationRedisSerializer();
template.setKeySerializer(stringSerializer);
template.setValueSerializer(jdkSerializationRedisSerializer);
template.setHashKeySerializer(stringSerializer);
template.setHashValueSerializer(stringSerializer);
template.setConnectionFactory(redisConnectionFactory);
template.setEnableTransactionSupport(true);
template.afterPropertiesSet();
return template;
}
示例8: newReactiveRedisOperationsSessionRepository
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer; //导入依赖的package包/类
@Test
@SuppressWarnings("unused")
public void newReactiveRedisOperationsSessionRepository() {
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory();
RedisSerializationContext<String, Object> serializationContext = RedisSerializationContext
.<String, Object>newSerializationContext(
new JdkSerializationRedisSerializer())
.build();
// tag::new-reactiveredisoperationssessionrepository[]
// ... create and configure connectionFactory and serializationContext ...
ReactiveRedisTemplate<String, Object> redisTemplate = new ReactiveRedisTemplate<>(
connectionFactory, serializationContext);
ReactiveSessionRepository<? extends Session> repository =
new ReactiveRedisOperationsSessionRepository(redisTemplate);
// end::new-reactiveredisoperationssessionrepository[]
}
示例9: onMessageCreated
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer; //导入依赖的package包/类
@Test
public void onMessageCreated() throws Exception {
MapSession session = this.cached;
byte[] pattern = "".getBytes("UTF-8");
String channel = "spring:session:event:created:" + session.getId();
JdkSerializationRedisSerializer defaultSerailizer = new JdkSerializationRedisSerializer();
this.redisRepository.setDefaultSerializer(defaultSerailizer);
byte[] body = defaultSerailizer.serialize(new HashMap());
DefaultMessage message = new DefaultMessage(channel.getBytes("UTF-8"), body);
this.redisRepository.setApplicationEventPublisher(this.publisher);
this.redisRepository.onMessage(message, pattern);
verify(this.publisher).publishEvent(this.event.capture());
assertThat(this.event.getValue().getSessionId()).isEqualTo(session.getId());
}
示例10: TicketRedisTemplate
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer; //导入依赖的package包/类
public TicketRedisTemplate() {
final RedisSerializer<String> string = new StringRedisSerializer();
final JdkSerializationRedisSerializer jdk = new JdkSerializationRedisSerializer();
setKeySerializer(string);
setValueSerializer(jdk);
setHashKeySerializer(string);
setHashValueSerializer(jdk);
}
示例11: initRedisTemplate
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer; //导入依赖的package包/类
/**
* 序列化设置
*/
private void initRedisTemplate(RedisTemplate<String, String> redisTemplate, RedisConnectionFactory factory) {
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
redisTemplate.setHashValueSerializer(new JdkSerializationRedisSerializer());
redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer());
redisTemplate.setConnectionFactory(factory);
}
示例12: redisTemplate
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer; //导入依赖的package包/类
@Bean("redisTemplate")
public RedisTemplate<String, Object> redisTemplate( RedisConnectionFactory connectionFactory ) {
RedisTemplate<String, Object> template = new RedisTemplate<>();
template.setConnectionFactory(connectionFactory);
template.setValueSerializer( new JdkSerializationRedisSerializer() );
template.setEnableTransactionSupport(true);
template.afterPropertiesSet();
return template;
}
示例13: keys
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer; //导入依赖的package包/类
@Override
public Set<String> keys(@Nonnull String group) {
checkNotNull(group, "empty group is not allowed");
if (redisTemplate.getKeySerializer() instanceof JdkSerializationRedisSerializer) {
log.warn("object key serialization(jdk serialization) strategy do not support keys command");
return Sets.newHashSet();
}
return redisTemplate.keys(GROUP_FIELD_PREFIX + group + GROUP_NAME_KEY_SPLIT + "*")
.stream()
.map(key ->
key.split(GROUP_FIELD_PREFIX + group + GROUP_NAME_KEY_SPLIT)[1]
).collect(Collectors.toSet());
}
示例14: createValueTemplate
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer; //导入依赖的package包/类
@Bean("valueTemplate")
public RedisTemplate<String, EmailSchedulingData> createValueTemplate() throws IOException {
RedisTemplate<String, EmailSchedulingData> template = new RedisTemplate<>();
RedisSerializer<String> stringSerializer = new StringRedisSerializer();
JdkSerializationRedisSerializer jdkSerializationRedisSerializer = new JdkSerializationRedisSerializer();
template.setKeySerializer(stringSerializer);
template.setValueSerializer(jdkSerializationRedisSerializer);
template.setHashKeySerializer(stringSerializer);
template.setHashValueSerializer(stringSerializer);
template.setConnectionFactory(connectionFactory);
template.setEnableTransactionSupport(true);
template.afterPropertiesSet();
return template;
}
示例15: createValueTemplate
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer; //导入依赖的package包/类
@Test
public void createValueTemplate() throws Exception {
//Act
RedisTemplate<String, EmailSchedulingData> template = emailRedisTemplateConfiguration.createValueTemplate();
//Assert
assertions.assertThat(template).isNotNull();
assertions.assertThat(template.getKeySerializer()).isInstanceOf(StringRedisSerializer.class);
assertions.assertThat(template.getHashKeySerializer()).isInstanceOf(StringRedisSerializer.class);
assertions.assertThat(template.getHashValueSerializer()).isInstanceOf(StringRedisSerializer.class);
assertions.assertThat(template.getValueSerializer()).isInstanceOf(JdkSerializationRedisSerializer.class);
}