- 博客(19)
- 收藏
- 关注
原创 Golang net/http包 client浅尝(一)
tcp链接client 包 一次完整请求client使用发起流程DosendRoundTripclient 包 一次完整请求client使用http.Client{ Transport: &http.Transport{ DialContext: (&net.Dialer{ Timeout: 30 * time.Second, //连接超时时间 ...
2019-05-12 15:53:42
1753
原创 Golang Timer源码阅读
数据结构type timer struct { tb *timersBucket // the bucket the timer lives in i int // heap index // Timer wakes up at when, and then at when+period, ... (period > 0 only) // each time...
2019-05-05 17:48:34
672
原创 Golang RWMutex 源码阅读
数据结构type RWMutex struct { w Mutex writerSem uint32 readerSem uint32 readerCount int32 readerWait int32 }w:互斥锁,多个写 goroutine之间竞争writerSem: 加写锁的信号量readerSem: 加读锁的信号量readerC...
2019-05-05 16:17:52
308
原创 redis数据结构之字典
redis数据结构之字典typedef struct dict { dictType *type;//字典类型 void *privdata;//字典类型特定函数的可选参数 dictht ht[2];//两个哈希表 long rehashidx; /* rehashing not in progress if rehashidx == -1 */ u...
2018-05-27 20:47:22
211
原创 redis数据结构之SDS
redis数据结构之SDSSDS 数据结构关于sds数据结构的定义在sds.h里面,sds根据string的长度来选择使用不同的struct,后面会介绍。typedef char *sds;/* Note: sdshdr5 is never used, we just access the flags byte directly. * However is here to...
2018-05-13 16:20:22
368
原创 redis 数据结构之跳跃表
数据结构跳跃表typedef struct zskiplist { struct zskiplistNode *header,*tail; unsigned long length; int level;} zskiplist;length 节点数量 level 表的最大层 跳跃表节点typedef struct zskiplistNode { ...
2018-02-24 19:03:28
308
原创 Nginx做代理的一次实践
背景所在项目Go服务之前部署在测试机器上,最近再把Go的配置迁移到etcd,但是因为etcd没有对应的测试环境,而公司里面网段是隔离的,导致了原本的Go服务再接入etcd之后跑不起来。让Go服务正常启动,其他依赖方,比如前端、网关少做修改方案Go服务部署到docker上,docker上的域名都是特定后缀结尾,这样会涉及到cookie等一些问题,所以考虑通过测试机的Nginx做代理。问题htt
2017-12-10 11:56:10
2220
原创 iris-session梳理
入口api := iris.New() api.Adapt(gm.NewSession())session的构造func NewSession() sessions.Sessions {db := redis.New(rs.Config{Network: rs.DefaultRedisNetwork,Addr: config.Instance().Redis.Address,Password
2017-12-10 11:35:56
2499
原创 Laravel 类加载,依赖注入&门面
Laravel类加载对于很多新手来说,比如我,刚开始不是很习惯于Laravel这样的类加载。对于第三方拓展,Laravel的加载方式:为这个类提供一个provider,继承ServiceProvider重写register方法,singleton或者bind两种方式boot是当前类有依赖其他通过register注册,但是不确定先后顺序的时候使用$defer为true表示延迟加载,默认在App
2017-04-03 17:22:31
1741
原创 yii2.0源码实现csrf验证
在yii\helpers\Html beginForm创建表单的时候,加入了csrf_token,name=_csrf-backend,type=hidden。这部分代码并不是很麻烦,这里就不再介绍了。下面主要介绍的是yii是怎么进行csrf验证的。class Request{ /** * csrf token mask的长度 */ const CSR
2016-10-08 15:35:43
1378
原创 源码分析foreach效率比for循环高
首先看看php源码变量值存储:typedef union _zvalue_value { long lval; /* long value */ double dval; /* double value */ struct { char *val; int len;
2016-09-20 15:56:55
1518
原创 yii2.0验证规则源码分析&php正则使用
之前两天在极客头条上看了一篇帖子,最严谨的校验email地址的正则表达式 ,最近接手的最多的就是yii2.0框架,所以很好奇想看看yii2.0是怎么实现验证规则。首先,一般在自定义的继承model类中,会有个rules()方法: public function rules() { /*echo ""; $e=new \Exception
2016-09-14 13:28:57
1755
转载 缓存使用总结
缓存是提高系统性能的利器,我们开发中常用的就是本地缓存和分布式缓存,对于单机的、数据量不大的数据,可以用HashMap自己实现一个简单的缓存,也可以用Guava cache来实现。对于分布式缓存,现在业界常用的都是基于redis, memcached,还有阿里的tair来做的。下面总结一下使用分布式缓存的时候要考虑的问题。更新策略LRU/FIFO等,对数据一致性要求不高;超
2016-09-11 13:07:07
2238
原创 php使用websocket编写的简易客服系统源码分析
一、websocket协议简介WebSocket是为解决客户端与服务端实时通信而产生的技术。其本质是先通过HTTP/HTTPS协议进行握手后创建一个用于交换数据的TCP连接,此后服务端与客户端通过此TCP连接进行实时通信。二、php使用的一些websocket函数resource socket_create ( int $domain , int $type , int $
2016-09-09 11:39:00
5872
转载 Redis 内存淘汰机制
转自 http://blog.jobbole.com/105335/摘要Redis是一款优秀的、开源的内存数据库,我在阅读Redis源码实现的过程中,时时刻刻能感受到Redis作者为更好地使用内存而费尽各种心思,例如最明显的是对于同一种数据结构在不同应用场景下提供了基于不同底层编码的实现(如压缩列表、跳跃表等)。今天我们暂时放下对Redis不同数据结构的
2016-09-06 09:08:53
4781
原创 yii2.0主从数据库实现源码分析-----(二)
这篇主要是介绍当主或者从服务器挂掉之后,yii的处理connection.php $cache = is_string($this->serverStatusCache) ? Yii::$app->get($this->serverStatusCache, false) : $this->serverStatusCache;//获取配置文件中的cache
2016-09-02 10:59:07
819
原创 composer安装使用,依赖管理源码分析
centos上安装使用:curl -sS https://getcomposer.org/installer | php (-- --install-dir=bin)指定安装目录安装依赖:1.新建一个composer.json文件{ "require": { "monolog/monolog": "1.2.*" }}php c
2016-09-01 09:33:48
802
原创 yii2.0主从数据库实现源码分析
主从数据库,主库写,从库读,主库挂掉了,不影响任何读操作,从库挂掉了,读写都在主库操作。The Connection component supports load balancing and failover between slaves. When performing a read query for the first time, theConnection component
2016-08-31 12:50:54
1519
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人