Jun

Results 58 issues of Jun

kube-apiserver 作为 k8s 中一个重要的组件存在。 ```go // cmd/kube-apiserver/app/server.go // NewAPIServerCommand creates a *cobra.Command object with default parameters func NewAPIServerCommand() *cobra.Command { s := options.NewServerRunOptions() cmd := &cobra.Command{ Use: "kube-apiserver", Long: `The...

WIP
Kubernetes

Redis server 是一个基于 reactor 模式的事件驱动程序。 事件驱动,简单理解就是有一个事件循环监听事件,当事件发生时会触发相应的处理。另外常见的编程范式有(单线程)同步以及多线/进程编程。 那什么是 reactor 模式? > The Reactor design pattern handles service requests that are delivered concurrently to an application by one or more clients. Each...

Redis
Database

压缩列表(ziplist)是 Redis 中列表对象、哈希对象和有序集合对象的底层实现之一。 为了节约内存而存在,由一块连续内存空间来表示: ![image](https://user-images.githubusercontent.com/8097526/52934563-ce8afb00-3391-11e9-9db5-e229aea3f83f.png) - zlbytes(4 byte): 整个压缩列表占用字节数 - zltail(4 byte): 压缩列表尾节点到压缩列表起始地址的偏移量 - zllen(2 byte): 压缩列表中的节点个数 - entry(? byte): 压缩列表节点 - zlend(1 byte): 压缩列表结束标志,0xFF 压缩列表元数据(zlbytes、zltail 和 zllen)大小为 10 byte:...

Redis
Database

## 字符串 Redis 中的字符串用内置的简单动态字符串(Simple Dynamic String,SDS)来表示。 在 3.2 之前的版本用结构体 sdshdr 表示 SDS。 ```c // 3.2.0/src/sds.h typedef char *sds; struct sdshdr { unsigned int len; unsigned int free; char buf[]; };...

Redis
Database

Redis 中的每个对象都由一个 redisObject 结构来表示: ```c // 5.0.3/src/server.h typedef struct redisObject { unsigned type:4; unsigned encoding:4; unsigned lru:LRU_BITS; /* LRU time (relative to global lru_clock) or * LFU data (least significant...

Redis
Database

Redis 中用一个 redisServer 对象来维护 redis 服务器的配置和状态: ```c // 5.0.3/src/server.c struct redisServer server; /* Server global state */ ``` 启动过程: ```c // 5.0.3/src/server.c int main(int argc, char **argv) { ... //...

Redis
Database

```python if 1 > 2: pass elif 1 < 3: pass else: pass ``` 对应的字节码: ```python 1 0 LOAD_CONST 0 (1) 2 LOAD_CONST 1 (2) 4 COMPARE_OP 4 (>) 6...

Python
CPython

表达式(expression)是值、变量和运算符的组合。 值自身也被认为是一个表达式,变量也是,因此下面都是合法的表达式: ```python >>> 42 42 >>> n Traceback (most recent call last): File "", line 1, in NameError: name 'n' is not defined >>> 17 + 25 42 ```...

Python
CPython

```python >>> co = compile('a, b, c = 1, 2, 3', '', 'single') >>> co.co_names ('a', 'b', 'c') >>> co.co_consts (1, 2, 3, None, (1, 2, 3)) ``` 可以看得出来,等式右边的`1, 2,...

Python
CPython

这篇文章主要是来剖析以下的代码片段的执行: ```python a = 0 b = '' c = [] d = {} ``` 利用`compile`获得`PyCodeObject`对象: ```python >>> co = compile(open('demo.py').read(), '', 'exec') >>> co.co_names ('a', 'b', 'c', 'd') >>>...

Python
CPython