Redis(六)— Redis过期策略、内存淘汰机制、消息及事物
- 2019 年 10 月 3 日
- 筆記
1???
?1???Redis??????????????????????????????
-
-
- ???????????30??6000???????????????????????????????? expire????pexpire????????? Redis???— Redis??????
- ???????????unix?????????????????????????????????expreat???????pexpireat????????
- ???????????????????????unix?????????????unix???????????????????????
-
?2????????Redis??????????????????
?3?Redis??????????????????????
?4???????????????????Redis??????????
2?????
??????Redis???— Redis????RDB?AOF?????????Reids??????????????????????????????????????????????????
?1??????????????????????????????????????????
-
-
- ????????????????????????????
- ????CPU?????????????????????????????????CPU???
-
?2??????????????????????????????????????
-
-
- ????CPU??????????????????????????
- ????????????????????????????????????????????
-
?3?????????????????????????????????
-
- ????????????????????????CPU??????????????????????
- ??????????????????????????????????????
Redis??????????????????
?????????????
?1?RDB????
?????RDB????????????????????????????????????????????
?????????????????????????
?2?AOF????AOF??????????????????????????AOF?????DEL???
?3?AOF???AOF??????????????????
?4??????????????????????????????????DEL?????????????????????
3???????
?Redis???????????????????????????????????????????????
????????????????
?1?noeviction??????????? ???????
?2?allkeys-lru?LRU????????????????key?
?3?allkeys-random?????????????key???????key???
?4?volatile-lru??????LRU????????????????key???????????key?
?5?volatile-random????????????????????????key????????key???
?6?volatile-ttl???????????????????????key????????????key???
Redis??????LRU?????????LRU??????keys??LRU???????key?????3?key???3?key???LRU?????3????????redis?????????maxmeory-samples???
?????????????????????????????
4???
??????????Redis???????????????????????????????????session?????????????sesssion??redis??????????????session???????????????J2Cache???J2Cache?????????????????????????????????????????????????????????????????????????????????
Redis????????publish?subscribe?psubscribe??????????????????????????????????????????????????????????????
?????????????????????????????????
???????????
???1???????
Redis?????????????????????????redis?????????????key-value??????????????????????????????????????????????
-
-
- ??????????????????????????????????????????????????
- ????????????????????????
-
?2???????
?Redis?????????????????????????????????????????????????????????????????????????????????????pubsubPattern??????client??????????pattern????????????????
-
-
- ??????????????????????pubsubPattern???????????????????????????
- ?????????????????????????????????pubsubPattern???
-
???????????????????????????????????????
?????????????? ?Redis???— Redis?????
5???
Redis??multi?exec?watch????????????????????????????????
Redis???ACID???
?1?????Atomicity??????????????????????
?2?????Consistency????????????????????????????????????????
?3?????Isolation??????????????????????????????redis?????????????
?4?????Durability??????????????????????????????????????????????????
?????
???MULTI??????EXEC????????????????????????????????????????????????????????multiState??????
1 typedef struct multiState { 2 // ?????FIFO?? 3 multiCmd *commands; 4 // ??????? 5 int count; 6 } multiState; 7 8 9 typedef struct multiCmd { 10 // ?? 11 robj **argv; 12 // ???? 13 int argc; 14 // ???? 15 struct redisCommand *cmd; 16 } multiCmd;
-
- ??????????????????????????????
- ???????multiCmd??????????????????????????
- ???????????????????????????????????????????????
- watch???????????????????????????????????????????????watch???multi???????
6???
-
- Redis???????????????????????????
- ??????????????????????????????????????
- ????????????????????
- ???????????????????????REDIS_DIRTY_CAS?????????????????????????????????????????
???
?Redis??????????????Redis????
????????redis??????????????????????????????????