Skip to content

Instantly share code, notes, and snippets.

@chenyhd
chenyhd / benchmark_result.txt
Last active September 19, 2021 15:22
Condition: 100K/1M keys already exist in the DB, compare the search performance of "key" and "scan"
GOROOT=/usr/local/go #gosetup
GOPATH=/home/henry/go #gosetup
/usr/local/go/bin/go test -c -o /tmp/GoLand/___gobench_redis_test_go.test /code/go/test1/redis_test.go #gosetup
/tmp/GoLand/___gobench_redis_test_go.test -test.v -test.paniconexit0 -test.bench ^\QBenchmark100KKeys\E|\QBenchmark100KScan\E|\QBenchmark1MKeys\E|\QBenchmark1MScan\E$ -test.run ^$
goos: linux
goarch: amd64
cpu: Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz
Benchmark100KKeys
redis_test.go:95: Prepare 100K keys for keys command
100K keys size: dbsize: 100000
@chenyhd
chenyhd / CustomNullSerializer
Created December 1, 2019 12:00
Jackson return empty instead of null
package xx.xx;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.ser.DefaultSerializerProvider;
import com.fasterxml.jackson.databind.ser.SerializerFactory;
import java.io.IOException;
import java.util.List;
@chenyhd
chenyhd / CaffeineCacheController
Created June 9, 2019 15:01
Use Caffeine cache in controller
@GetMapping("create")
@Cacheable(value = CacheNames.Write.HALF_MINUTE, key = "#p0", cacheManager = "writeCacheHalfMinute")
public String test1(@RequestParam String user) throws InterruptedException {
log.error(user);
Thread.sleep(3000);
return "1111111111";
}
@chenyhd
chenyhd / CacheConfiguration
Created June 9, 2019 14:58
Spring boot with caffeine cache
@Bean
public CaffeineCacheManager writeCacheHalfMinute() {
CaffeineCacheManager caffeineCacheManager = new CaffeineCacheManager(CacheNames.Write.HALF_MINUTE);
caffeineCacheManager.setCaffeine(Caffeine.newBuilder()
.expireAfterWrite(30, TimeUnit.SECONDS)
.maximumSize(100));
return caffeineCacheManager;
}
@chenyhd
chenyhd / CloudEnvironment.java
Created August 14, 2018 06:13
非Springboot项目从config-server读取配置文件
public class CloudEnvironment extends StandardServletEnvironment {
static Logger logger = LoggerFactory.getLogger(CloudEnvironment.class);
@Override
protected void customizePropertySources(MutablePropertySources propertySources) {
super.customizePropertySources(propertySources);
try {
//用来添加应用名到environment中
propertySources.addLast(initResourcePropertySourceLocator("cloud-config-context.properties"));