Redis入门:一致性

旁路缓存策略 (Cache Aside)

假设你要把数据库 💾 里的一个值(比如商品库存)从 10 改成 9。为了防止 Redis 🧠 里存的还是 10(脏数据),我们需要操作 Redis。

小范围随机数生成大范围采样

随机数生成器的扩展

题目:

已知一个函数 rand3(),能够等概率地生成整数 1, 2, 3。 现有一个包含 $N$ 个样本的数组 samples($N > 3$)。 请利用 rand3() 实现一个函数,能够等概率地(即概率为 $1/N$)从这批样本中抽取一个元素。

Go interface

我们知道 Golang 中有两种方法:值方法和指针方法

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
type person struct{}

func (p *person) Speaker() {
	fmt.Println("Hello.")
}

type fox struct{}

func (f fox) Speaker() {
	fmt.Println("firefox.")
}

官方对函数的调用规则说明为: A method call x.m() is valid if the method set of (the type of) x contains m and the argument list can be assigned to the parameter list of m. If x is addressable and &x’s method set contains m, x.m() is shorthand for (&x).m().

Go的IO入门:Reader与Writer

将数据在不同地方倒腾是 golang 最常见的应用模式了,IO 相关的话题是如何写好 golang 避不开的话题。接下来,本文将对 golang 生态中的 IO 模块进行介绍。

Go的Context包解析

context包提供了以下功能:传递 Key-Value 值、取消信号、超时时间。由于 context 可以被安全的传递给任意数量的 goroutine,context 常被用于控制并发操作。