org.springframework.data.redis.connection.DataType Java Examples

The following examples show how to use org.springframework.data.redis.connection.DataType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RedisServiceImpl.java    From yshopmall with Apache License 2.0 6 votes vote down vote up
@Override
public Page<RedisVo> findByKey(String key, Pageable pageable){
    List<RedisVo> redisVos = new ArrayList<>();
    if(!"*".equals(key)){
        key = "*" + key + "*";
    }
    for (Object s : redisTemplate.keys(key)) {
        // 过滤掉权限的缓存
        if (s.toString().indexOf("role::loadPermissionByUser") != -1
                || s.toString().indexOf("user::loadUserByUsername") != -1
                || s.toString().indexOf("wechat") != -1
                || s.toString().indexOf("wxpay") != -1
                || s.toString().indexOf(ShopKeyUtils.getSiteUrl()) != -1) {
            continue;
        }
        DataType dataType = redisTemplate.type(s.toString());
        if(!dataType.code().equals("string")) continue;
        RedisVo redisVo = new RedisVo(s.toString(),redisTemplate.opsForValue().get(s.toString()).toString());
        redisVos.add(redisVo);
    }
    Page<RedisVo> page = new PageImpl<RedisVo>(
            PageUtil.toPage(pageable.getPageNumber(),pageable.getPageSize(),redisVos),
            pageable,
            redisVos.size());
    return page;
}
 
Example #2
Source File: ConvertUtil.java    From redis-admin with Apache License 2.0 6 votes vote down vote up
public static void convertByteToString(RedisConnection connection, Set<byte[]> keysSet, List<RKey> tempList) {
	StringRedisSerializer stringSerializer = new StringRedisSerializer(Charset.forName("UTF8"));
	for(byte[] byteArray: keysSet) {
		String converted = stringSerializer.deserialize(byteArray);
		DataType dateType = null;
		switch(RedisApplication.showType) {
		case show:
			dateType = connection.type(byteArray);
			break;
		case hide:
			dateType = DataType.NONE;
			break;
		default:
			dateType = connection.type(byteArray);
			break;
		}
		
		RKey rkey = new RKey(converted, dateType); 
		tempList.add(rkey);
	}
}
 
Example #3
Source File: RedissonReactiveKeyCommands.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public Flux<CommandResponse<KeyCommand, DataType>> type(Publisher<KeyCommand> keys) {
    return execute(keys, key -> {

        Assert.notNull(key.getKey(), "Key must not be null!");

        byte[] keyBuf = toByteArray(key.getKey());
        Mono<DataType> m = read(keyBuf, StringCodec.INSTANCE, TYPE, keyBuf);
        return m.map(v -> new CommandResponse<>(key, v));
    });
}
 
Example #4
Source File: RedissonReactiveKeyCommands.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public Flux<CommandResponse<KeyCommand, DataType>> type(Publisher<KeyCommand> keys) {
    return execute(keys, key -> {

        Assert.notNull(key.getKey(), "Key must not be null!");

        byte[] keyBuf = toByteArray(key.getKey());
        Mono<DataType> m = read(keyBuf, StringCodec.INSTANCE, TYPE, keyBuf);
        return m.map(v -> new CommandResponse<>(key, v));
    });
}
 
Example #5
Source File: RedissonReactiveKeyCommands.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public Flux<CommandResponse<KeyCommand, DataType>> type(Publisher<KeyCommand> keys) {
    return execute(keys, key -> {

        Assert.notNull(key.getKey(), "Key must not be null!");

        byte[] keyBuf = toByteArray(key.getKey());
        Mono<DataType> m = read(keyBuf, StringCodec.INSTANCE, TYPE, keyBuf);
        return m.map(v -> new CommandResponse<>(key, v));
    });
}
 
Example #6
Source File: RoutesConfig.java    From spring-5-examples with MIT License 5 votes vote down vote up
@Bean
public RouterFunction<ServerResponse> routes(final TaskRepository taskRepository,
                                             final ActivityRepository activityRepository,
                                             final ReactiveRedisConnection connection) {

  val keyCommands = connection.keyCommands();

  return

      route(

          DELETE("/"),
          request -> ok().body(
              Mono.fromCallable(() -> {
                activityRepository.deleteAll();
                taskRepository.deleteAll();
                return "done.";
              }), String.class))

      .andRoute(

          GET("/tasks"),
          request -> ok().body(Flux.fromIterable(taskRepository.findAll()), Task.class))

      .andRoute(

          GET("/activities"),
          request -> ok().body(Flux.fromIterable(activityRepository.findAll()), Activity.class))

      .andRoute(

          GET("/**"),
          request -> ok().body(Mono.just(format("command type %s",
                                                keyCommands.randomKey()
                                                           .flatMap(keyCommands::type)
                                                           .map(DataType::code)
                                                           .subscribe())), String.class))
      ;
}
 
Example #7
Source File: RedissonReactiveKeyCommands.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public Flux<CommandResponse<KeyCommand, DataType>> type(Publisher<KeyCommand> keys) {
    return execute(keys, key -> {

        Assert.notNull(key.getKey(), "Key must not be null!");

        byte[] keyBuf = toByteArray(key.getKey());
        Mono<DataType> m = read(keyBuf, StringCodec.INSTANCE, TYPE, keyBuf);
        return m.map(v -> new CommandResponse<>(key, v));
    });
}
 
Example #8
Source File: RedisServiceImpl.java    From redis-admin with Apache License 2.0 5 votes vote down vote up
private String getDataType(String serverName, int dbIndex, String key) {
	RedisTemplate redisTemplate = RedisApplication.redisTemplatesMap.get(serverName);
	RedisConnection connection = RedisConnectionUtils.getConnection(redisTemplate.getConnectionFactory());
	connection.select(dbIndex);
	DataType dataType = connection.type(key.getBytes());
	connection.close();
	return dataType.name().toUpperCase();
}
 
Example #9
Source File: RedisServiceImpl.java    From redis-admin with Apache License 2.0 5 votes vote down vote up
private Object getKV(String serverName, int dbIndex, String key) {
	RedisTemplate redisTemplate = RedisApplication.redisTemplatesMap.get(serverName);
	RedisConnection connection = RedisConnectionUtils.getConnection(redisTemplate.getConnectionFactory());
	connection.select(dbIndex);
	DataType dataType = connection.type(key.getBytes());
	connection.close();
	Object values = null;
	switch(dataType) {
	case STRING:
		values = redisDao.getSTRING(serverName, dbIndex, key);
		break;
	case LIST:
		values = redisDao.getLIST(serverName, dbIndex, key);
		break;
	case SET:
		values = redisDao.getSET(serverName, dbIndex, key);
		break;
	case ZSET:
		values = redisDao.getZSET(serverName, dbIndex, key);
		break;
	case HASH:
		values = redisDao.getHASH(serverName, dbIndex, key);
		break;
	case NONE:
		//never be here
		values = null;
	}
	return values;
}
 
Example #10
Source File: DataTypeConvertor.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Override
public DataType convert(Object obj) {
    String val = obj.toString();
    return DataType.fromCode(val);
}
 
Example #11
Source File: DataTypeConvertor.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Override
public DataType convert(Object obj) {
    String val = obj.toString();
    return DataType.fromCode(val);
}
 
Example #12
Source File: RedissonReactiveKeyCommands.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Override
public DataType convert(Object obj) {
    return DataType.fromCode(obj.toString());
}
 
Example #13
Source File: DataTypeConvertor.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Override
public DataType convert(Object obj) {
    String val = obj.toString();
    return DataType.fromCode(val);
}
 
Example #14
Source File: RedissonConnection.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Override
public DataType type(byte[] key) {
    return read(key, StringCodec.INSTANCE, TYPE, key);
}
 
Example #15
Source File: RedissonReactiveKeyCommands.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Override
public DataType convert(Object obj) {
    return DataType.fromCode(obj.toString());
}
 
Example #16
Source File: DefaultBoundHashOperations.java    From redis-admin with Apache License 2.0 4 votes vote down vote up
public DataType getType() {
	return DataType.HASH;
}
 
Example #17
Source File: RedissonConnection.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Override
public DataType type(byte[] key) {
    return read(key, StringCodec.INSTANCE, TYPE, key);
}
 
Example #18
Source File: DataTypeConvertor.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Override
public DataType convert(Object obj) {
    String val = obj.toString();
    return DataType.fromCode(val);
}
 
Example #19
Source File: RedissonReactiveKeyCommands.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Override
public DataType convert(Object obj) {
    return DataType.fromCode(obj.toString());
}
 
Example #20
Source File: DataTypeConvertor.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Override
public DataType convert(Object obj) {
    String val = obj.toString();
    return DataType.fromCode(val);
}
 
Example #21
Source File: DataTypeConvertor.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Override
public DataType convert(Object obj) {
    String val = obj.toString();
    return DataType.fromCode(val);
}
 
Example #22
Source File: RedissonConnection.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Override
public DataType type(byte[] key) {
    return read(key, StringCodec.INSTANCE, TYPE, key);
}
 
Example #23
Source File: DataTypeConvertor.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Override
public DataType convert(Object obj) {
    String val = obj.toString();
    return DataType.fromCode(val);
}
 
Example #24
Source File: DefaultBoundZSetOperations.java    From redis-admin with Apache License 2.0 4 votes vote down vote up
public DataType getType() {
	return DataType.ZSET;
}
 
Example #25
Source File: KeyCommandTest.java    From ehousechina with Apache License 2.0 4 votes vote down vote up
/**
 * 返回 key 所储存的值的类型。
 */
@Test
public void testType() {
	DataType type=template.type(SimpleData.LISI.getKey());
	log.info(">> {}",type);
}
 
Example #26
Source File: TracingRedisConnection.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
public DataType type(byte[] key) {
  return helper.doInScope(RedisCommand.TYPE, key, () -> connection.type(key));
}
 
Example #27
Source File: TracingRedisConnection.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
public DataType type(byte[] key) {
  return helper.doInScope(RedisCommand.TYPE, key, () -> connection.type(key));
}
 
Example #28
Source File: RKey.java    From redis-admin with Apache License 2.0 4 votes vote down vote up
public RKey(String key, DataType dateType) {
	this.key = key;
	this.type = dateType;
}
 
Example #29
Source File: RKey.java    From redis-admin with Apache License 2.0 4 votes vote down vote up
public DataType getType() {
	return type;
}
 
Example #30
Source File: RKey.java    From redis-admin with Apache License 2.0 4 votes vote down vote up
public void setType(DataType type) {
	this.type = type;
}