當前位置: 首頁>>代碼示例>>Java>>正文


Java RedisConnection類代碼示例

本文整理匯總了Java中org.springframework.data.redis.connection.RedisConnection的典型用法代碼示例。如果您正苦於以下問題:Java RedisConnection類的具體用法?Java RedisConnection怎麽用?Java RedisConnection使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


RedisConnection類屬於org.springframework.data.redis.connection包,在下文中一共展示了RedisConnection類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: updateAll

import org.springframework.data.redis.connection.RedisConnection; //導入依賴的package包/類
@Override
public void updateAll() {
    
    try {
        final List<Viapp> list = appDao.getAllApp();
        logger.info("BeginNewAddAppToRedis...");
        long start = System.currentTimeMillis();
        redisTemplate.execute(new RedisCallback<Object>() {  
            @Override  
            public Object doInRedis(RedisConnection connection)  
                    throws DataAccessException {
                connection.flushDb();
                //connection.multi();
                commonRedis.saveCommonRedis(list,connection);
               // connection.exec();
                return null;  
            }  
        });  
        logger.info("redis init finish cost:{}ms!", System.currentTimeMillis() - start);
        
    }catch(Exception e){
        e.printStackTrace();
    }
}
 
開發者ID:zhaoxi1988,項目名稱:sjk,代碼行數:25,代碼來源:DataObserableImpl.java

示例2: doReadSession

import org.springframework.data.redis.connection.RedisConnection; //導入依賴的package包/類
protected Session doReadSession(Serializable sessionId) {
    byte[] sessionKey = buildRedisSessionKey(sessionId);
    RedisConnection redisConnection = getRedisConnection();
    try {
        byte[] value = redisConnection.get(sessionKey);
        if (value == null) {
            return null;
        }
        Session session = SerializeUtil.deserialize(value, SimpleSession.class);
        return session;
    } finally {
        redisConnection.close();
    }
}
 
開發者ID:iBase4J,項目名稱:iBase4J-Common,代碼行數:15,代碼來源:RedisSessionDAO.java

示例3: put

import org.springframework.data.redis.connection.RedisConnection; //導入依賴的package包/類
@Override
public void put(Object key, Object value) {
    final String keyf = (String) key;
    final Object valuef = value;
    final long liveTime = 86400;

    redisTemplate.execute(new RedisCallback<Long>() {
        public Long doInRedis(RedisConnection connection) throws DataAccessException {
            byte[] keyb = keyf.getBytes();
            byte[] valueb = toByteArray(valuef);
            connection.set(keyb, valueb);
            if (liveTime > 0) {
                connection.expire(keyb, liveTime);
            }
            return 1L;
        }
    });
}
 
開發者ID:Zephery,項目名稱:newblog,代碼行數:19,代碼來源:RedisCache.java

示例4: evict

import org.springframework.data.redis.connection.RedisConnection; //導入依賴的package包/類
@Override
public void evict(Object key) {
    final String keyf = (String) key;
    redisTemplate.execute(new RedisCallback<Long>() {
        public Long doInRedis(RedisConnection connection) throws DataAccessException {
            return connection.del(keyf.getBytes());
        }
    });
}
 
開發者ID:Zephery,項目名稱:newblog,代碼行數:10,代碼來源:RedisCache.java

示例5: getConnection

import org.springframework.data.redis.connection.RedisConnection; //導入依賴的package包/類
@Override
public RedisConnection getConnection() {

    initDbType();

    RedisConnection redisConnection = loadConnection();
    if(redisConnection==null) {
        redisConnection =  initLCNConnection(redisConnectionFactory.getConnection());
        if(redisConnection==null){
            throw new RuntimeException("connection was overload");
        }
        return redisConnection;
    }else {
        return redisConnection;
    }
}
 
開發者ID:1991wangliang,項目名稱:tx-lcn,代碼行數:17,代碼來源:LCNJedisFactoryProxy.java

示例6: tryLock

import org.springframework.data.redis.connection.RedisConnection; //導入依賴的package包/類
public Boolean tryLock(){
	String uuid = UUID.randomUUID().toString();
	Boolean success = (Boolean) redisTemplate.execute((RedisConnection connection) -> {
		Jedis jedis = (Jedis)connection.getNativeConnection();
		String res = jedis.set(lockKey, uuid, NX, PX, maxLockTime);
		if (res != null && res.equals("OK")) {
			return true;
		}else{
			return false;
		}
	});
	if(success){
		this.lockValue = uuid;
		return true;
	}else{
		return false;
	}
}
 
開發者ID:profullstack,項目名稱:spring-seed,代碼行數:19,代碼來源:SimpleRedisDlmLock.java

示例7: releaseLock

import org.springframework.data.redis.connection.RedisConnection; //導入依賴的package包/類
public Boolean releaseLock(){
	Boolean success = (Boolean) redisTemplate.execute((RedisConnection connection) -> {
		Jedis jedis = (Jedis)connection.getNativeConnection();
		Long res = (Long)jedis.eval(SCRIPT_CHECK_THEN_DELETE, Collections.singletonList(lockKey), Collections.singletonList(lockValue));
		if (res != null && res.equals(1L)) {
			return true;
		}else{
			return false;
		}
	});
	if(success){
		return true;
	}else{
		return false;
	}
}
 
開發者ID:profullstack,項目名稱:spring-seed,代碼行數:17,代碼來源:SimpleRedisDlmLock.java

示例8: testCallback

import org.springframework.data.redis.connection.RedisConnection; //導入依賴的package包/類
@Test
public void testCallback() {

    final Properties[] result = {null};

    redisTemplate.execute(new RedisCallback<Object>() {
        @Override
        public Object doInRedis(RedisConnection connection) throws DataAccessException {
            Properties properties = connection.info();
            System.out.println(properties);

            properties = connection.info("CPU");
            System.out.println(properties);

            result[0] = properties;

            return null;
        }
    });

    System.out.println(result[0]);
}
 
開發者ID:luoxn28,項目名稱:redis-info,代碼行數:23,代碼來源:TestRedis.java

示例9: testCallback2

import org.springframework.data.redis.connection.RedisConnection; //導入依賴的package包/類
@Test
public void testCallback2() {
    final Properties[] result = {null};

    redisTemplate.execute(new RedisCallback<Object>() {
        @Override
        public Object doInRedis(RedisConnection connection) throws DataAccessException {
            Properties properties = connection.info("keyspace");
            System.out.println(properties);

            Enumeration<String> nameList = (Enumeration<String>) properties.propertyNames();
            while (nameList.hasMoreElements()) {
                System.out.println(nameList.nextElement());
            }

            result[0] = properties;
            return null;
        }
    });
}
 
開發者ID:luoxn28,項目名稱:redis-info,代碼行數:21,代碼來源:TestRedis.java

示例10: testCallback3

import org.springframework.data.redis.connection.RedisConnection; //導入依賴的package包/類
@Test
public void testCallback3() {
    final Properties[] result = {null};

    redisTemplate.execute(new RedisCallback<Object>() {
        @Override
        public Object doInRedis(RedisConnection connection) throws DataAccessException {
            Properties properties = connection.info();
            System.out.println(properties);

            Enumeration<String> nameList = (Enumeration<String>) properties.propertyNames();
            while (nameList.hasMoreElements()) {
                System.out.println(nameList.nextElement());
            }

            result[0] = properties;
            return null;
        }
    });
}
 
開發者ID:luoxn28,項目名稱:redis-info,代碼行數:21,代碼來源:TestRedis.java

示例11: get

import org.springframework.data.redis.connection.RedisConnection; //導入依賴的package包/類
@Override
public <T> T get(final String key, final Class clazz) {
    T result = redisTemplate.execute(new RedisCallback<T>() {
        public T doInRedis(RedisConnection connection)
                throws DataAccessException {
            RedisSerializer<String> serializer = getRedisSerializer();
            byte[] keyStr = serializer.serialize(key);
            byte[] value = connection.get(keyStr);
            if (value == null) {
                return null;
            }
            String valueStr = serializer.deserialize(value);
            return (T) JSON.parseObject(valueStr, clazz);
        }
    });
    return result;
}
 
開發者ID:bill1012,項目名稱:AdminEAP,代碼行數:18,代碼來源:RedisDaoImpl.java

示例12: getQueued

import org.springframework.data.redis.connection.RedisConnection; //導入依賴的package包/類
@Override
public List<Execution> getQueued(String queue) {
   return redis.execute((RedisConnection connection) -> {
      // Get all ids from queue.
      List<byte[]> idsBytes = connection.lRange(key(QUEUE, queue), 0, -1);
      if (isEmpty(idsBytes)) {
         return emptyList();
      }

      // Lookup all executions for all ids at once.
      List<byte[]> executionsBytes = connection.hMGet(key(JOBS), idsBytes.toArray(new byte[idsBytes.size()][]));
      if (isEmpty(executionsBytes)) {
         return emptyList();
      }
      Assert.isTrue(executionsBytes.size() == idsBytes.size(),
            "Precondition violated: Redis response has the expected length.");

      return executionsBytes.stream()
            .map(this::parseExecution)
            .filter(Objects::nonNull)
            .collect(toList());
   });
}
 
開發者ID:shopping24,項目名稱:redjob,代碼行數:24,代碼來源:FifoDaoImpl.java

示例13: redisIsUp

import org.springframework.data.redis.connection.RedisConnection; //導入依賴的package包/類
@Test
public void redisIsUp() throws Exception {
	Properties info = new Properties();
	info.put("redis_version", "2.8.9");
	RedisConnection redisConnection = mock(RedisConnection.class);
	RedisConnectionFactory redisConnectionFactory = mock(
			RedisConnectionFactory.class);
	given(redisConnectionFactory.getConnection()).willReturn(redisConnection);
	given(redisConnection.info()).willReturn(info);
	RedisHealthIndicator healthIndicator = new RedisHealthIndicator(
			redisConnectionFactory);
	Health health = healthIndicator.health();
	assertThat(health.getStatus()).isEqualTo(Status.UP);
	assertThat(health.getDetails().get("version")).isEqualTo("2.8.9");
	verify(redisConnectionFactory).getConnection();
	verify(redisConnection).info();
}
 
開發者ID:philwebb,項目名稱:spring-boot-concourse,代碼行數:18,代碼來源:RedisHealthIndicatorTests.java

示例14: hGetString

import org.springframework.data.redis.connection.RedisConnection; //導入依賴的package包/類
public static String hGetString(final String key, final String field, final Long seconds) {
    String result = (String) redisTemplate.execute(new RedisCallback<String>() {
        @Override
        public String doInRedis(RedisConnection connection) throws DataAccessException {
            try {
                byte[] byteKey = key.getBytes("utf-8");
                byte[] value = connection.hGet(byteKey, field.getBytes("utf-8"));
                if (value == null) {
                    return null;
                }
                if (seconds != null) {
                    connection.expire(byteKey, seconds);
                }
                return new String(value, "utf-8");
            } catch (UnsupportedEncodingException e) {
                throw new RuntimeException("不支持的編碼類型utf-8", e);
            }
        }
    }, true, false);
    return result;
}
 
開發者ID:yangshuai0711,項目名稱:dingding-app-server,代碼行數:22,代碼來源:RedisUtil.java

示例15: hMGet

import org.springframework.data.redis.connection.RedisConnection; //導入依賴的package包/類
@Override
public List<byte[]> hMGet(final String redisKey, final List<String> mapKeys) {
	return redisTemplate.execute(new RedisCallback<List<byte[]>>() {

		@Override
		public List<byte[]> doInRedis(RedisConnection connection) throws DataAccessException {
			byte[][] keys = new byte[mapKeys.size()][];
			
			for (int i = 0; i < mapKeys.size(); i++) {
				keys[i] = mapKeys.get(i).getBytes();
			}
			
			return connection.hMGet(redisKey.getBytes(), keys);
		}
	});
}
 
開發者ID:javahongxi,項目名稱:whatsmars,代碼行數:17,代碼來源:RedisMapServiceImpl.java


注:本文中的org.springframework.data.redis.connection.RedisConnection類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。