Skip to content

Instantly share code, notes, and snippets.

@chrisedrego
chrisedrego / redisinsight-manifest.yaml
Created January 22, 2021 19:58
RedisInsight Manifest for kubernetes deployment & services
apiVersion: apps/v1
kind: Deployment
metadata:
name: redisinsight
labels:
app: redisinsight
spec:
replicas: 1
selector:
matchLabels:
@zjnxyz
zjnxyz / 唯一邀请码生成方法
Created June 9, 2018 03:33
唯一邀请码生成方法,通过算法实现,唯一第三方组件来判断邀请码是否唯一!!!
/**
* 随机字符串
*/
private static final char[] CHARS = new char[] {'F', 'L', 'G', 'W', '5', 'X', 'C', '3',
'9', 'Z', 'M', '6', '7', 'Y', 'R', 'T', '2', 'H', 'S', '8', 'D', 'V', 'E', 'J', '4', 'K',
'Q', 'P', 'U', 'A', 'N', 'B'};
private final static int CHARS_LENGTH = 32;
/**
* 邀请码长度

Scaling your API with rate limiters

The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.

In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.

Request rate limiter

This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.