Skip to content

Instantly share code, notes, and snippets.

View guozi's full-sized avatar
🎯
Focusing

guozi_1989 guozi

🎯
Focusing
View GitHub Profile
@guozi
guozi / App.java
Created September 25, 2017 07:11 — forked from thomasdarimont/App.java
Spring Boot Redis custom json serializer example.
package demo;
import java.io.Serializable;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisOperations;
@guozi
guozi / AnnotatedBeanLocator.java
Created August 8, 2018 10:39 — forked from digulla/AnnotatedBeanLocator.java
Locate beans in an ApplicationContext by annotation on the method which defines the bean.
import java.lang.annotation.Annotation;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.type.StandardMethodMetadata;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
@guozi
guozi / MyListenerProcessor.java
Created August 9, 2018 02:56
BeanPostProcessor Demo
public class MyListenerProcessor implements BeanPostProcessor {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
return bean;
}
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
Method[] methods = ReflectionUtils.getAllDeclaredMethods(bean.getClass());
if (methods != null) {
@guozi
guozi / ExpirationListener.java
Created August 22, 2018 05:36 — forked from jdonee/ExpirationListener.java
Spring Boot 2 + Spring Session 2 + Shiro 1.4 + Redis(Lettuce) Config
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.stereotype.Component;
import lombok.extern.slf4j.Slf4j;
/**
* Session过期监听
* @author Frank Zeng
*
@guozi
guozi / CustomerController.java
Created September 13, 2018 08:40
Spring Data Jpa 分页查询
/**
* 分页
* 应用查询提示@QueryHints,这里是在查询的适合增加了一个comment
* 查询结果是lastName和firstName都是bauer这个值的数据
*/
@RequestMapping("/pageable")
public void pageable(){
//Pageable是接口,PageRequest是接口实现
//PageRequest的对象构造函数有多个,page是页数,初始值是0,size是查询结果的条数,后两个参数参考Sort对象的构造方法
Pageable pageable = new PageRequest(0,3, Sort.Direction.DESC,"id");
@guozi
guozi / BookQueryService.java
Created September 13, 2018 08:48
Spring Boot + Spring Data Jpa
public interface BookQueryService {
Page<Book> findBookNoCriteria(Integer page,Integer size);
Page<Book> findBookCriteria(Integer page,Integer size,BookQuery bookQuery);
}
@guozi
guozi / ThreadPoolTaskExecutorWithMdcPropagation.java
Created September 20, 2018 06:17 — forked from pismy/ThreadPoolTaskExecutorWithMdcPropagation.java
SLF4J Tool: ThreadPoolExecutor that propagates MDC from calling thread to executor thread
import java.util.Map;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Callable;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@guozi
guozi / HttpRequestHandlerWithMdcPropagation.java
Created September 20, 2018 07:23 — forked from pismy/HttpRequestHandlerWithMdcPropagation.java
SLF4J & Apache Http tool: propagates MDC context over client Http requests (suitable for micro-services architecture)
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.message.BasicHeader;
import org.apache.http.protocol.HttpContext;
@guozi
guozi / FreeMarkerUtil.java
Last active September 30, 2018 02:35
FreeMarkerUtil
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ui.freemarker.FreeMarkerTemplateUtils;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;

Best Practices for Azure Redis

Below are a set of best practices that I recommend for most customers. This information is based on my experience helping hundreds of Azure Redis customers investigate various issues.

Configuration and Concepts

  1. Use Standard or Premium Tier for Production systems. The Basic Tier is a single node system with no data replication and no SLA. Also, use at least a C1 cache. C0 caches are really meant for simple dev/test scenarios since they have a shared CPU core, very little memory, are prone to "noisy neighbor", etc.
  2. Remember that Redis is an In-Memory data store. Read this article so that you are aware of scenarios where data loss can occur.
  3. Configure your client library to use a "connect timeout" of at least 10 to 15 seconds, giving the system time to connect even under higher CPU conditions. If your client or server tend to be under high load