当前位置: 首页>>代码示例>>Java>>正文


Java StringRedisTemplate类代码示例

本文整理汇总了Java中org.springframework.data.redis.core.StringRedisTemplate的典型用法代码示例。如果您正苦于以下问题:Java StringRedisTemplate类的具体用法?Java StringRedisTemplate怎么用?Java StringRedisTemplate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


StringRedisTemplate类属于org.springframework.data.redis.core包,在下文中一共展示了StringRedisTemplate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getMqttClient

import org.springframework.data.redis.core.StringRedisTemplate; //导入依赖的package包/类
/**
 * get MqttClient by clientKey
 * @param clientKey
 * @return
 * @throws MqttException
 */
public static MqttClient getMqttClient(String serverURI, String clientId,StringRedisTemplate redisTemplate) 
                throws MqttException{
	 String clientKey=serverURI.concat(clientId);
     if(clientMap.get(clientKey)==null){
         lock.lock();
             if(clientMap.get(clientKey)==null){
            	 MqttClientPersistence persistence = new MemoryPersistence();
            	
                 MqttClient client = new MqttClient(serverURI, clientId, persistence);
                 MqttConnectOptions connOpts = new MqttConnectOptions();
                 
                 MqttCallback callback = new IMMqttCallBack(client,redisTemplate);
                 client.setCallback(callback);
                 
                 connOpts.setCleanSession(true);
                 client.connect(connOpts);
                 clientMap.put(clientKey, client);
             }
          lock.unlock();
     }
      return clientMap.get(clientKey);
}
 
开发者ID:projectsrepos,项目名称:jim,代码行数:29,代码来源:MqttClientFactory.java

示例2: redisTemplate

import org.springframework.data.redis.core.StringRedisTemplate; //导入依赖的package包/类
/**
 * RedisTemplate配置
 * @param factory
 * @return
 */
@Bean
@SuppressWarnings({"rawtypes", "unchecked"})
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {
    StringRedisTemplate template = new StringRedisTemplate(factory);
    //定义value的序列化方式
    Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
    ObjectMapper om = new ObjectMapper();
    om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
    om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
    jackson2JsonRedisSerializer.setObjectMapper(om);
    
    template.setValueSerializer(jackson2JsonRedisSerializer);
    template.setHashValueSerializer(jackson2JsonRedisSerializer);
    template.afterPropertiesSet();
    return template;
}
 
开发者ID:SnailFastGo,项目名称:springboot_op,代码行数:22,代码来源:RedisConfiguration.java

示例3: redisTemplate

import org.springframework.data.redis.core.StringRedisTemplate; //导入依赖的package包/类
@Bean("redisTemplate")  //新家的这个注解 10-26 12:06
@SuppressWarnings({ "rawtypes", "unchecked" })
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory redisFactory){
	StringRedisTemplate template = new StringRedisTemplate(redisFactory);
	Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new 
			Jackson2JsonRedisSerializer(Object.class);
	
	ObjectMapper om = new ObjectMapper();
	om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
	om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
	jackson2JsonRedisSerializer.setObjectMapper(om);
	
	template.setValueSerializer(jackson2JsonRedisSerializer);
	template.afterPropertiesSet();
	return template;
}
 
开发者ID:duanyaxin,项目名称:springboot-smart,代码行数:17,代码来源:RedisConfiguration.java

示例4: LoaderService

import org.springframework.data.redis.core.StringRedisTemplate; //导入依赖的package包/类
@Autowired
public LoaderService(final RequestExecutorService requestExecutorService,
                     final MonitorService monitorService,
                     StringRedisTemplate template,
                     @Value("${build.version}") String buildVersion,
                     @Value("${build.timestamp}") String buildTimestamp) {
    this.requestExecutorService = requestExecutorService;
    this.monitorService = monitorService;
    this.template = template;
    this.buildVersion = buildVersion;
    this.buildTimestamp = buildTimestamp;
    this.myself = new Loader();
    myself.setName(SystemInfo.hostname());
    myself.setStatus(Status.IDLE);
    myself.setVersion(buildVersion + " (" + buildTimestamp + ")");
}
 
开发者ID:globocom,项目名称:groot,代码行数:17,代码来源:LoaderService.java

示例5: main

import org.springframework.data.redis.core.StringRedisTemplate; //导入依赖的package包/类
public static void main(String[] args) throws InterruptedException {
	ApplicationContext context = SpringApplication.run(RedisAndLockApplication.class, args);
	StringRedisTemplate stringRedisTemplate = context.getBean(StringRedisTemplate.class);

	RedisLock lock = new RedisLock(stringRedisTemplate, "test_002");
	// Lock lock = new ReentrantLock();
	final Printer outer = new Printer(lock);
	Thread t1 = new Thread(() -> outer.output("One : I am first String !!"));
	Thread t2 = new Thread(() -> outer.output("Two : I am second String !!"));
	Thread t3 = new Thread(() -> outer.output("Three : I am third String !!"));
	t1.start();
	t2.start();
	t3.start();
	t1.join();
	t2.join();
	t3.join();
	System.exit(0);
}
 
开发者ID:wyp0596,项目名称:elegant-springboot,代码行数:19,代码来源:RedisAndLockApplication.java

示例6: RedisMessageChannelBinder

import org.springframework.data.redis.core.StringRedisTemplate; //导入依赖的package包/类
public RedisMessageChannelBinder(RedisConnectionFactory connectionFactory, String... headersToMap) {
	Assert.notNull(connectionFactory, "connectionFactory must not be null");
	this.connectionFactory = connectionFactory;
	StringRedisTemplate template = new StringRedisTemplate(connectionFactory);
	template.afterPropertiesSet();
	this.redisOperations = template;
	if (headersToMap != null && headersToMap.length > 0) {
		String[] combinedHeadersToMap =
				Arrays.copyOfRange(BinderHeaders.STANDARD_HEADERS, 0, BinderHeaders.STANDARD_HEADERS.length
						+ headersToMap.length);
		System.arraycopy(headersToMap, 0, combinedHeadersToMap, BinderHeaders.STANDARD_HEADERS.length,
				headersToMap.length);
		this.headersToMap = combinedHeadersToMap;
	}
	else {
		this.headersToMap = BinderHeaders.STANDARD_HEADERS;
	}
	this.errorAdapter = new RedisQueueOutboundChannelAdapter(
			parser.parseExpression("headers['" + ERROR_HEADER + "']"), connectionFactory);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-redis,代码行数:21,代码来源:RedisMessageChannelBinder.java

示例7: RedisTestBinder

import org.springframework.data.redis.core.StringRedisTemplate; //导入依赖的package包/类
public RedisTestBinder(RedisConnectionFactory connectionFactory) {
	RedisMessageChannelBinder binder = new RedisMessageChannelBinder(connectionFactory);
	GenericApplicationContext context = new GenericApplicationContext();
	context.getBeanFactory().registerSingleton(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME,
			new DefaultMessageBuilderFactory());
	DefaultHeaderChannelRegistry channelRegistry = new DefaultHeaderChannelRegistry();
	channelRegistry.setReaperDelay(Long.MAX_VALUE);
	ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
	taskScheduler.afterPropertiesSet();
	channelRegistry.setTaskScheduler(taskScheduler);
	context.getBeanFactory().registerSingleton(
			IntegrationContextUtils.INTEGRATION_HEADER_CHANNEL_REGISTRY_BEAN_NAME,
			channelRegistry);
	context.refresh();
	binder.setApplicationContext(context);
	binder.setCodec(new PojoCodec());
	setBinder(binder);
	template = new StringRedisTemplate(connectionFactory);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-redis,代码行数:20,代码来源:RedisTestBinder.java

示例8: testWithKey

import org.springframework.data.redis.core.StringRedisTemplate; //导入依赖的package包/类
@Test
public void testWithKey() throws Exception{
	//Setup
	String key = "foo";
	StringRedisTemplate redisTemplate = createStringRedisTemplate(redisConnectionFactory);
	redisTemplate.delete(key);

	RedisList<String> redisList = new DefaultRedisList<String>(key, redisTemplate);
	List<String> list = new ArrayList<String>();
	list.add("Manny");
	list.add("Moe");
	list.add("Jack");

	//Execute
	Message<List<String>> message = new GenericMessage<List<String>>(list);
	sink.input().send(message);

	//Assert
	assertEquals(3, redisList.size());
	assertEquals("Manny", redisList.get(0));
	assertEquals("Moe", redisList.get(1));
	assertEquals("Jack", redisList.get(2));

	//Cleanup
	redisTemplate.delete(key);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-app-starters,代码行数:27,代码来源:RedisSinkApplicationTests.java

示例9: DefaultPersistenceService

import org.springframework.data.redis.core.StringRedisTemplate; //导入依赖的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();
}
 
开发者ID:ozimov,项目名称:spring-boot-email-tools,代码行数:17,代码来源:DefaultPersistenceService.java

示例10: main

import org.springframework.data.redis.core.StringRedisTemplate; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();

    // invoke the CONFIG
    /*
     * application context then starts the message listener container, and
     * the message listener container bean starts listening for messages
     */
    ctx.register(RedisConfig.class);
    ctx.refresh();

    /*
     * retrieves the StringRedisTemplate bean from the application context
     * and uses it to send a "Hello from Redis!" message on the "chat" topic
     */
    StringRedisTemplate template = ctx.getBean(StringRedisTemplate.class);
    CountDownLatch latch = ctx.getBean(CountDownLatch.class);

    LOGGER.info("* Sending message...");
    template.convertAndSend("chat", "Hello from Redis!");

    latch.await();
    System.exit(0);

}
 
开发者ID:huangye177,项目名称:spring4probe,代码行数:27,代码来源:RedisApp.java

示例11: getStringRedisTemplate

import org.springframework.data.redis.core.StringRedisTemplate; //导入依赖的package包/类
@Bean
public RedisTemplate getStringRedisTemplate() {
    StringRedisTemplate clusterTemplate = new StringRedisTemplate();
    clusterTemplate.setConnectionFactory(jedisConnectionFactory());
    clusterTemplate.setKeySerializer(new StringRedisSerializer());
    clusterTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
    return clusterTemplate;
}
 
开发者ID:yu199195,项目名称:happylifeplat-transaction,代码行数:9,代码来源:RedisClusterConfig.java

示例12: redisTemplate

import org.springframework.data.redis.core.StringRedisTemplate; //导入依赖的package包/类
@SuppressWarnings({"unchecked","rawtypes"})
@Bean  
   public RedisTemplate<String, String> redisTemplate(  
           RedisConnectionFactory factory) {  
       StringRedisTemplate template = new StringRedisTemplate(factory);  
	Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);  
       ObjectMapper om = new ObjectMapper();  
       om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);  
       om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);  
       jackson2JsonRedisSerializer.setObjectMapper(om);  
       template.setValueSerializer(jackson2JsonRedisSerializer);  
       template.afterPropertiesSet();  
       return template;  
   }
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:15,代码来源:RedisConfig.java

示例13: post

import org.springframework.data.redis.core.StringRedisTemplate; //导入依赖的package包/类
@Override
public void post(String username, String message) {
	JedisPool jedisPool = JedisFactory.getPool();
	try (Jedis jedis = jedisPool.getResource()) {
		long tweetId = jedis.incr("id");

		String key = username + ":tweet:" + tweetId;
		System.out.println("key der nachricht:" + key);

		jedis.hset(key, "message", message);
		Calendar cal = Calendar.getInstance();
		java.util.Date time = cal.getTime();
		DateFormat formatter = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss");

		jedis.hset(key, "date", formatter.format(time));

		jedis.lpush("global", key);
		jedis.lpush(username + ":personal", key);

		Set<String> werEinemFolgt = jedis.smembers(username + ":follower");
		for (Iterator<String> iterator = werEinemFolgt.iterator(); iterator.hasNext();) {
			String iter = iterator.next();
			System.out.println("Iterator: " + iter);
			jedis.lpush(iter + ":follower:tweet", key);
			System.out.println("name von dem Typen auf wesen liste man schreibt: " + iter);
		}
		ApplicationContext ctx = TrumpetWebApplication.getCtx();
		StringRedisTemplate template = ctx.getBean(StringRedisTemplate.class);
		CountDownLatch latch = ctx.getBean(CountDownLatch.class);
		template.convertAndSend("chat", "Neue Nachricht von: " + username);

	} catch (Exception e) {
		System.out.println("Mock catch block post");
		e.printStackTrace();
	}
}
 
开发者ID:SystemOfAProg,项目名称:VS2Labor,代码行数:37,代码来源:MockRedisService.java

示例14: redisTemplate

import org.springframework.data.redis.core.StringRedisTemplate; //导入依赖的package包/类
@Bean
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {
    StringRedisTemplate template = new StringRedisTemplate(factory);
    Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
    ObjectMapper om = new ObjectMapper();
    om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
    om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
    jackson2JsonRedisSerializer.setObjectMapper(om);
    template.setValueSerializer(jackson2JsonRedisSerializer);
    template.afterPropertiesSet();
    return template;
}
 
开发者ID:ChinaLHR,项目名称:JavaQuarkBBS,代码行数:13,代码来源:RedisConfig.java

示例15: TokenAuthenticationServiceImpl

import org.springframework.data.redis.core.StringRedisTemplate; //导入依赖的package包/类
public TokenAuthenticationServiceImpl(UserRepository userRepository,
                                      StringRedisTemplate stringRedisTemplate) {
    this.userRepository = userRepository;
    this.stringRedisTemplate = stringRedisTemplate;
    // TODO: parse this as a property
    tokenHandler = new TokenHandler(DatatypeConverter.parseBase64Binary("9SyECk96oDsTmXfogIfgdjhdsgvagHJLKNLvfdsfR8cbXTvoPjX+Pq/T/b1PqpHX0lYm0oCBjXWICA=="));
}
 
开发者ID:yuexine,项目名称:loafer,代码行数:8,代码来源:TokenAuthenticationServiceImpl.java


注:本文中的org.springframework.data.redis.core.StringRedisTemplate类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。