org.springframework.data.redis.core.RedisTemplate.boundListOps()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(11.6k)|赞(0)|评价(0)|浏览(107)

本文整理了Java中org.springframework.data.redis.core.RedisTemplate.boundListOps方法的一些代码示例,展示了RedisTemplate.boundListOps的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RedisTemplate.boundListOps方法的具体详情如下:
包路径:org.springframework.data.redis.core.RedisTemplate
类名称:RedisTemplate
方法名:boundListOps

RedisTemplate.boundListOps介绍

暂无

代码示例

代码示例来源:origin: spring-projects/spring-integration

@Override
public MessageGroup addMessageToGroup(Object groupId, Message<?> message) {
  this.redisTemplate.boundListOps(groupId).leftPush(message);
  return null;
}

代码示例来源:origin: spring-projects/spring-integration

@Override
public Message<?> pollMessageFromGroup(Object groupId) {
  return this.redisTemplate.boundListOps(groupId).rightPop();
}

代码示例来源:origin: spring-projects/spring-integration

@Override
public void removeMessageGroup(Object groupId) {
  this.redisTemplate.boundListOps(groupId).trim(1, 0);
}

代码示例来源:origin: spring-projects/spring-integration

@Override
@ManagedAttribute
public int messageGroupSize(Object groupId) {
  Long size = this.redisTemplate.boundListOps(groupId).size();
  return size == null ? 0 : (int) size.longValue();
}

代码示例来源:origin: spring-projects/spring-integration

@Override
@SuppressWarnings("unchecked")
protected void handleMessageInternal(Message<?> message) throws Exception {
  Object value = message;
  if (this.extractPayload) {
    value = message.getPayload();
  }
  if (!(value instanceof byte[])) {
    if (value instanceof String && !this.serializerExplicitlySet) {
      value = this.stringSerializer.serialize((String) value);
    }
    else {
      value = ((RedisSerializer<Object>) this.serializer).serialize(value);
    }
  }
  String queueName = this.queueNameExpression.getValue(this.evaluationContext, message, String.class);
  // TODO: 5.2 assert both not null
  if (this.leftPush) {
    this.template.boundListOps(queueName).leftPush(value); // NOSONAR
  }
  else {
    this.template.boundListOps(queueName).rightPush(value); // NOSONAR
  }
}

代码示例来源:origin: spring-projects/spring-integration

@Override
public MessageGroup getMessageGroup(Object groupId) {
  Assert.isInstanceOf(String.class, groupId);
  List<Message<?>> allMessages = new LinkedList<Message<?>>();
  List<String> list = sortedKeys((String) groupId);
  for (String key : list) {
    List<Message<?>> messages = this.getRedisTemplate().boundListOps(key).range(0, -1);
    if (messages != null) {
      allMessages.addAll(messages);
    }
  }
  return getMessageGroupFactory().create(allMessages, groupId);
}

代码示例来源:origin: spring-projects/spring-integration

@Override
public MessageGroup getMessageGroup(Object groupId) {
  List<Message<?>> messages = this.redisTemplate.boundListOps(groupId).range(0, -1);
  return getMessageGroupFactory().create(messages, groupId);
}

代码示例来源:origin: spring-projects/spring-integration

public RedisQueueOutboundGateway(String queueName, RedisConnectionFactory connectionFactory) {
  Assert.hasText(queueName, "'queueName' is required");
  Assert.notNull(connectionFactory, "'connectionFactory' must not be null");
  this.template.setConnectionFactory(connectionFactory);
  this.template.setEnableDefaultSerializer(false);
  this.template.setKeySerializer(new StringRedisSerializer());
  this.template.afterPropertiesSet();
  this.boundListOps = this.template.boundListOps(queueName);
}

代码示例来源:origin: spring-projects/spring-integration

this.template.boundListOps(uuid).leftPush(value);
BoundListOperations<String, Object> boundListOperations = this.template.boundListOps(uuid + QUEUE_NAME_SUFFIX);
byte[] reply = (byte[]) boundListOperations.rightPop(this.receiveTimeout, TimeUnit.MILLISECONDS);
if (reply != null && reply.length > 0) {

代码示例来源:origin: spring-projects/spring-integration

@Override
@ManagedAttribute
public int messageGroupSize(Object groupId) {
  Assert.isInstanceOf(String.class, groupId);
  List<String> list = sortedKeys((String) groupId);
  int count = 0;
  for (String key : list) {
    Long size = getRedisTemplate().boundListOps(key).size();
    if (size != null) {
      count += size;
    }
  }
  return count;
}

代码示例来源:origin: spring-projects/spring-integration

/**
 * @param queueName         Must not be an empty String
 * @param connectionFactory Must not be null
 */
public RedisQueueMessageDrivenEndpoint(String queueName, RedisConnectionFactory connectionFactory) {
  Assert.hasText(queueName, "'queueName' is required");
  Assert.notNull(connectionFactory, "'connectionFactory' must not be null");
  RedisTemplate<String, byte[]> template = new RedisTemplate<String, byte[]>();
  template.setConnectionFactory(connectionFactory);
  template.setEnableDefaultSerializer(false);
  template.setKeySerializer(new StringRedisSerializer());
  template.afterPropertiesSet();
  this.boundListOperations = template.boundListOps(queueName);
}

代码示例来源:origin: spring-projects/spring-integration

/**
 * @param queueName Must not be an empty String
 * @param connectionFactory Must not be null
 */
public RedisQueueInboundGateway(String queueName, RedisConnectionFactory connectionFactory) {
  Assert.hasText(queueName, "'queueName' is required");
  Assert.notNull(connectionFactory, "'connectionFactory' must not be null");
  this.template = new RedisTemplate<String, byte[]>();
  this.template.setConnectionFactory(connectionFactory);
  this.template.setEnableDefaultSerializer(false);
  this.template.setKeySerializer(new StringRedisSerializer());
  this.template.afterPropertiesSet();
  this.boundListOperations = this.template.boundListOps(queueName);
}

代码示例来源:origin: spring-projects/spring-integration

@Test
@RedisAvailable
public void testInt3017IntegrationInbound() {
  String payload = new Date().toString();
  RedisTemplate<String, String> redisTemplate = new StringRedisTemplate();
  redisTemplate.setConnectionFactory(this.connectionFactory);
  redisTemplate.afterPropertiesSet();
  redisTemplate.boundListOps("si.test.Int3017IntegrationInbound")
      .leftPush("{\"payload\":\"" + payload + "\",\"headers\":{}}");
  Message<?> receive = this.fromChannel.receive(10000);
  assertNotNull(receive);
  assertEquals(payload, receive.getPayload());
}

代码示例来源:origin: spring-projects/spring-integration

@Test
@RedisAvailable
public void testInt3017IntegrationOutbound() throws Exception {
  final String queueName = "si.test.Int3017IntegrationOutbound";
  GenericMessage<Object> message = new GenericMessage<Object>(queueName);
  this.sendChannel.send(message);
  RedisTemplate<String, String> redisTemplate = new StringRedisTemplate();
  redisTemplate.setConnectionFactory(this.connectionFactory);
  redisTemplate.afterPropertiesSet();
  String result = redisTemplate.boundListOps(queueName).rightPop(5000, TimeUnit.MILLISECONDS);
  assertNotNull(result);
  InboundMessageMapper<String> mapper = new JsonInboundMessageMapper(String.class,
      new Jackson2JsonMessageParser());
  Message<?> resultMessage = mapper.toMessage(result);
  assertEquals(message.getPayload(), resultMessage.getPayload());
}

代码示例来源:origin: spring-projects/spring-integration

@Test
@RedisAvailable
public void testInt3015ExplicitSerializer() throws Exception {
  final String queueName = "si.test.testRedisQueueOutboundChannelAdapter2";
  final RedisQueueOutboundChannelAdapter handler = new RedisQueueOutboundChannelAdapter(queueName,
      this.connectionFactory);
  handler.setSerializer(new Jackson2JsonRedisSerializer<Object>(Object.class));
  RedisTemplate<String, ?> redisTemplate = new StringRedisTemplate();
  redisTemplate.setConnectionFactory(this.connectionFactory);
  redisTemplate.afterPropertiesSet();
  handler.handleMessage(new GenericMessage<Object>(Arrays.asList("foo", "bar", "baz")));
  Object result = redisTemplate.boundListOps(queueName).rightPop(5000, TimeUnit.MILLISECONDS);
  assertNotNull(result);
  assertEquals("[\"foo\",\"bar\",\"baz\"]", result);
  handler.handleMessage(new GenericMessage<Object>("test"));
  result = redisTemplate.boundListOps(queueName).rightPop(5000, TimeUnit.MILLISECONDS);
  assertNotNull(result);
  assertEquals("\"test\"", result);
}

代码示例来源:origin: spring-projects/spring-integration

redisTemplate.boundListOps(queueName).leftPush(payload);
redisTemplate.boundListOps(queueName).leftPush(payload2);

代码示例来源:origin: spring-projects/spring-integration

redisTemplate.boundListOps(queueName).rightPush(payload);
redisTemplate.boundListOps(queueName).rightPush(payload2);

代码示例来源:origin: spring-projects/spring-integration

@Test
@RedisAvailable
public void testInt3015Default() throws Exception {
  final String queueName = "si.test.testRedisQueueOutboundChannelAdapter";
  final RedisQueueOutboundChannelAdapter handler = new RedisQueueOutboundChannelAdapter(queueName,
      this.connectionFactory);
  String payload = "testing";
  handler.handleMessage(MessageBuilder.withPayload(payload).build());
  RedisTemplate<String, ?> redisTemplate = new StringRedisTemplate();
  redisTemplate.setConnectionFactory(this.connectionFactory);
  redisTemplate.afterPropertiesSet();
  Object result = redisTemplate.boundListOps(queueName).rightPop(5000, TimeUnit.MILLISECONDS);
  assertNotNull(result);
  assertEquals(payload, result);
  Date payload2 = new Date();
  handler.handleMessage(MessageBuilder.withPayload(payload2).build());
  RedisTemplate<String, ?> redisTemplate2 = new RedisTemplate<String, Object>();
  redisTemplate2.setConnectionFactory(this.connectionFactory);
  redisTemplate2.setEnableDefaultSerializer(false);
  redisTemplate2.setKeySerializer(new StringRedisSerializer());
  redisTemplate2.setValueSerializer(new JdkSerializationRedisSerializer());
  redisTemplate2.afterPropertiesSet();
  Object result2 = redisTemplate2.boundListOps(queueName).rightPop(5000, TimeUnit.MILLISECONDS);
  assertNotNull(result2);
  assertEquals(payload2, result2);
}

代码示例来源:origin: spring-projects/spring-integration

@Test
@RedisAvailable
public void testInt3932LeftPushFalse() throws Exception {
  final String queueName = "si.test.Int3932LeftPushFalse";
  final RedisQueueOutboundChannelAdapter handler = new RedisQueueOutboundChannelAdapter(queueName,
      this.connectionFactory);
  handler.setLeftPush(false);
  String payload = "testing";
  handler.handleMessage(MessageBuilder.withPayload(payload).build());
  Date payload2 = new Date();
  handler.handleMessage(MessageBuilder.withPayload(payload2).build());
  RedisTemplate<String, ?> redisTemplate = new StringRedisTemplate();
  redisTemplate.setConnectionFactory(this.connectionFactory);
  redisTemplate.afterPropertiesSet();
  Object result = redisTemplate.boundListOps(queueName).leftPop(5000, TimeUnit.MILLISECONDS);
  assertNotNull(result);
  assertEquals(payload, result);
  RedisTemplate<String, ?> redisTemplate2 = new RedisTemplate<String, Object>();
  redisTemplate2.setConnectionFactory(this.connectionFactory);
  redisTemplate2.setEnableDefaultSerializer(false);
  redisTemplate2.setKeySerializer(new StringRedisSerializer());
  redisTemplate2.setValueSerializer(new JdkSerializationRedisSerializer());
  redisTemplate2.afterPropertiesSet();
  Object result2 = redisTemplate2.boundListOps(queueName).leftPop(5000, TimeUnit.MILLISECONDS);
  assertNotNull(result2);
  assertEquals(payload2, result2);
}

代码示例来源:origin: spring-projects/spring-integration

@Test
@RedisAvailable
public void testInt3015ExtractPayloadFalse() throws Exception {
  final String queueName = "si.test.testRedisQueueOutboundChannelAdapter2";
  final RedisQueueOutboundChannelAdapter handler = new RedisQueueOutboundChannelAdapter(queueName,
      this.connectionFactory);
  handler.setExtractPayload(false);
  Message<String> message = MessageBuilder.withPayload("testing").build();
  handler.handleMessage(message);
  RedisTemplate<String, Object> redisTemplate = new RedisTemplate<String, Object>();
  redisTemplate.setConnectionFactory(this.connectionFactory);
  redisTemplate.setEnableDefaultSerializer(false);
  redisTemplate.setKeySerializer(new StringRedisSerializer());
  redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer());
  redisTemplate.afterPropertiesSet();
  Object result = redisTemplate.boundListOps(queueName).rightPop(5000, TimeUnit.MILLISECONDS);
  assertNotNull(result);
  assertEquals(message, result);
}

相关文章

微信公众号

最新文章

更多