| | |
| | | |
| | | import com.ltkj.common.core.controller.BaseController; |
| | | import com.ltkj.common.core.domain.AjaxResult; |
| | | import com.ltkj.common.core.redis.RedisCache; |
| | | import com.ltkj.common.enums.DataSourceType; |
| | | import com.ltkj.framework.datasource.DynamicDataSourceContextHolder; |
| | | import com.ltkj.hosp.service.*; |
| | |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.checkerframework.checker.units.qual.A; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.ConvertingCursor; |
| | | import org.springframework.data.redis.core.Cursor; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.data.redis.core.ScanOptions; |
| | | import org.springframework.data.redis.serializer.RedisSerializer; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import static com.ltkj.framework.datasource.DynamicDataSourceContextHolder.log; |
| | | import static org.apache.poi.hemf.record.emfplus.HemfPlusRecordType.save; |
| | | |
| | | |
| | |
| | | private LtkjHybgdService ltkjHybgdService; |
| | | @Resource |
| | | private LtkjHysqdService ltkjHysqdService; |
| | | @Autowired |
| | | public RedisTemplate<Object,Object> redisTemplate; |
| | | @Resource |
| | | private RedisCache redisCache; |
| | | |
| | | @GetMapping("/getRedisValue") |
| | | @ApiOperation(value = "测试redis模糊查询") |
| | | public AjaxResult getRedisValue(@RequestParam String aa) { |
| | | long start = System.currentTimeMillis(); |
| | | //需要匹配的key |
| | | ScanOptions options = ScanOptions.scanOptions() |
| | | //这里指定每次扫描key的数量(很多博客瞎说要指定Integer.MAX_VALUE,这样的话跟 keys有什么区别?) |
| | | .count(10000) |
| | | .match(aa+"*").build(); |
| | | RedisSerializer<String> redisSerializer = (RedisSerializer<String>) redisTemplate.getKeySerializer(); |
| | | Cursor cursor = redisTemplate.executeWithStickyConnection(redisConnection -> new ConvertingCursor<>(redisConnection.scan(options), redisSerializer::deserialize)); |
| | | List<Object> result = new ArrayList<>(); |
| | | while(cursor.hasNext()){ |
| | | String s = cursor.next().toString(); |
| | | redisCache.deleteObject(s); |
| | | } |
| | | //切记这里一定要关闭,否则会耗尽连接数。报Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisException: Could not get a |
| | | cursor.close(); |
| | | // System.out.println(result); |
| | | log.info("scan扫描共耗时:{} ms key数量:{}",System.currentTimeMillis()-start,result.size()); |
| | | Map<String,Object>map=new HashMap<>(); |
| | | map.put("result",result); |
| | | map.put("scan扫描共耗时:{} ms key数量:{}",System.currentTimeMillis()-start+result.size()); |
| | | return AjaxResult.success(map); |
| | | } |
| | | |
| | | |
| | | @GetMapping("/getMiddleDetail") |