
redis
自驱
ALOHA HEJA HE
展开
-
【golang】分布式限流器 redis lua + go 实现
2 lua脚本实现 注意score精度是52位有效;ns存储可以忽略这个精度?3. lua脚本单独存储。原创 2022-10-11 10:55:50 · 810 阅读 · 0 评论 -
【redis】3.0 lpush rpush 源码详解
1 命令表{"rpush",rpushCommand,-3,"wm",0,NULL,1,1,1,0,0}, {"lpush",lpushCommand,-3,"wm",0,NULL,1,1,1,0,0},2 放在前面ZIPLIST and LINKEDLIST/* 空白 ziplist 示例图area |<---- ziplist header ---->|<-- end -->|size 4 bytes 4 bytes原创 2022-01-29 17:29:23 · 1356 阅读 · 0 评论 -
【redis】3.0 incr decr 源码
1. cmd incr decr 命令// 命令Tablestruct redisCommand redisCommandTable[] = { {"get",getCommand,2,"r",0,NULL,1,1,1,0,0}, {"set",setCommand,-3,"wm",0,NULL,1,1,1,0,0}, ... {"incr",incrCommand,2,"wm",0,NULL,1,1,1,0,0}, {"decr",decrCommand,2原创 2022-01-13 10:40:20 · 271 阅读 · 0 评论 -
【redis】 redis 6.0 驱逐key Pool计算方式 如何完成采样? 阅读源码 evictionPoolPopulate(i, dict, db->dict, p
1.evictionPoolPopulate 算法 // src/evict.c 从左到右 idl time 递增/* This is an helper function for freeMemoryIfNeeded(), it is used in order * to populate the evictionPool with a few entries every time we want to * expire a key. Keys with idle time smaller...原创 2021-12-03 23:45:00 · 630 阅读 · 0 评论 -
【redis】6.0 源码阅读: Handle the maxmemory directive
processCommand方法调用链路:networking.c【readQueryFromClient-->processInputBuffer-->processCommandAndResetClient-->processCommand】 -->freeMemoryIfNeededAndSafe -->freeMemoryIfNeeded // evict.c -->计算需要释放内存量 -->根据配置的驱逐策略来生释放缓存: server..原创 2021-12-02 23:45:00 · 624 阅读 · 0 评论 -
【redis】从GET命令,深入redis 6.0 渐进式扩容
【redis】从GET命令,深入redis渐进式扩容// Get 命令定义struct redisCommand redisCommandTable[] = { {"module",moduleCommand,-2, "admin no-script", 0,NULL,0,0,0,0,0,0}, {"get",getCommand,2, "read-only fast @string", 0,NULL,1,1,1,0,0,0}, ...原创 2021-11-19 12:10:42 · 510 阅读 · 0 评论 -
【斯坦福大学】图形实验室 二进制文章集合
内容直达:thttp://graphics.stanford.edu/~seander/bithacks.html【斯坦福大学】官网https://www.stanford.edu/原创 2021-11-18 23:00:00 · 350 阅读 · 0 评论 -
【redis】redis 6.0 scanGenericCommand之SCAN 源码解读
1 算法介绍Pieter Noordhuis/* This command implements SCAN, HSCAN and SSCAN commands. * If object 'o' is passed, then it must be a Hash, Set or Zset object, otherwise * if 'o' is NULL the command will operate on the dictionary associated with * ..原创 2021-11-16 23:46:01 · 576 阅读 · 1 评论 -
redis string robj(int,raw,embstr)之 embstr 类型大小限制44字节由来
1 首先robj所占内存认知16Byte// 总共占用16Byte= 4bit + 4bit + 24bit(lru) + refcount 4Byte + *ptr 8Bytetypedef struct redisObject { unsigned type:4; // 4bit unsigned encoding:4; // 4bit unsigned lru:LRU_BITS; /* LRU time (relative to global ...原创 2021-10-28 11:51:16 · 520 阅读 · 1 评论 -
Redis6.0 sds string--初始化和扩容--详解
1 直接上源码(内部有注释)/* Modify an sds string in-place to make it empty (zero length). * However all the existing buffer is not discarded but set as free space * so that next append operations will not require allocations up to the * number of bytes previo.原创 2021-10-27 17:14:23 · 584 阅读 · 0 评论 -
redis sds 数据结构如何使用 C realloc函数来动态扩容
1 系统函数realloc测试#include <stdio.h>#include <stdlib.h>typedef char *sds;int main() { printf("Hello, World!\n"); char t[] = {'a','b','c','d'}; sds s = t+1; char bb = s[0]; char cc = s[1]; char dd = s[2]; cha.原创 2021-10-27 16:55:35 · 321 阅读 · 0 评论 -
win-redis docker install
原创 2021-10-27 10:08:22 · 111 阅读 · 0 评论 -
redis 3.0 server初始化PONG -- Mac 系统函数 memcpy 定义
#include <string.h> // /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/secure/_string.h#define memcpy(dest, ...) \ __builtin___memcpy_chk (dest, __VA_ARGS__, __darwin_obsz0 (dest))#endif参考: redis 3.0 server初始化src..原创 2021-10-26 12:08:13 · 293 阅读 · 0 评论 -
C语言读取redis lrange 实现
/* * Get the range of items in a list from 'start' to 'end'. * This function allocates memory. An array of pointers and all the strings pointed to by it * are dynamically allocated. redis_free_array_results() has to be called to free this * allocated..原创 2021-09-06 21:58:13 · 215 阅读 · 0 评论 -
redis zset score 精度的坑
1 score 的存储double 64的浮点存储格式Double-precision binary floating-point is a commonly used format on PCs, due to its wider range over single-precision floating point, in spite of its performance and bandwidth cost. It is commonly known simply asdouble. The .原创 2021-06-24 10:00:49 · 2018 阅读 · 0 评论 -
redis zset 排序分值(A维度正序+时间维度倒序)如何构建?
package mainimport ( "fmt" "time")const INT_MAX = int64(^uint32(0) >> 1)func main() { fmt.Println(INT_MAX) now := time.Now() secondes := now.Unix() fmt.Println("原时间 = ",secondes) offset := int64(29989) fmt.Pri.原创 2021-06-14 07:44:18 · 1317 阅读 · 0 评论 -
【redis】3.2.8rehash存在的隐患,最新5.0+版本的改进-源码分析
此文链接至美团原创 2021-01-29 08:56:29 · 344 阅读 · 0 评论 -
【redis】会撑爆内存吗?
redis.conf中的maxmemory选项,该选项是告诉Redis当使用了多少物理内存后就开始拒绝后续的写入请求,该参数能很好的保护好你的Redis不会因为使用了过多的物理内存而导致swap,最终严重影响性能甚至崩溃。...原创 2020-04-26 12:15:03 · 925 阅读 · 0 评论 -
【池】数值对象池 redis中的使用
数值对象池是什么?Redis内部采用了一个shared integer的方式来省去分配内存的开销,即在系统启动时先分配一个从1~n 那么多个数值对象放在一个池子中,如果存储的数据恰好是这个数值范围内的数据,则直接从池子里取出该对象,并且通过引用计数的方式来共享,这样在系统存储了大量数值下,也能一定程度上节省内存并且提高性能,这个参数值n的设置需要修改源代码中的一行宏定义REDIS_SHARED...原创 2020-04-26 12:13:35 · 367 阅读 · 0 评论 -
【REDIS SCAN】scan清理无效key,导致慢日志飙升
1 问题现场 private List<String> scanWithLimit(String pattern, int limit, int type) { Preconditions.checkArgument(StringUtils.isNotBlank(pattern)); List<String> list = Lis...原创 2020-03-29 16:24:44 · 975 阅读 · 0 评论 -
org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getNativ
java.lang.NullPointerException: null at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getNativeConnection(LettuceConnectionFactory.java:959) ~[spring-...原创 2018-12-13 15:06:08 · 11142 阅读 · 4 评论 -
"Callback cannot return a non-null value as it gets overwritten by the pipeline"
常用pipeline,这个异常理解姿态:因为:pipeline模式 返回结果是 List<Object> closePipeline = connection.closePipeline(); 会覆盖掉自定义的返回值,所以没有理由去返回一个非null的值,没有用处,所以禁止回调返回非null的值,必须返回null,参考https://docs.spring.io/spring-da...原创 2019-01-07 15:20:45 · 5253 阅读 · 0 评论 -
Redis使用FastJson序列化/FastJson2JsonRedisSerializer --坑
很多小伙伴序列化代码是这样配置的public class FastJson2JsonRedisSerializer<T> implements RedisSerializer<T> { public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8"); private Cl...原创 2019-01-19 23:14:46 · 14637 阅读 · 0 评论 -
springboot+Redis 使用Hessian序列化
import java.io.ByteArrayInputStream;import java.io.ByteArrayOutputStream;import java.io.IOException;import java.util.concurrent.TimeUnit;import org.springframework.data.redis.connection.RedisP...原创 2019-01-21 16:27:17 · 1348 阅读 · 1 评论 -
redis--事务提交后 server端是如何处理并发来的其他请求的?exec multi pipleline
答案:单线程按照指令顺序执行;即 server端执行事务时,其他指令是不能被执行的,注意:请求是可以进来的,只是指令排到事务指令集合的后面。参考redis server端源码;C写;epoll 事件模型;多路复用技术;3个处理模型【请求流程,处理流程,响应流程】测试代码:目的是模拟普通请求和事务型请求并发 @Autowired private RedisCacheUti...原创 2019-04-26 00:39:26 · 323 阅读 · 0 评论 -
【redis】 大key解决方案第一步
背景:redis作为缓存,经常困扰的一个问题就是大key,就是key值过大超过1M或者value过多超过1M个或者总的大小超过1MB。例如:lettuce客户端一直繁忙的处理大key引起的并发症。比如:系统中用了Set集合,每个item的大小是30个字符,即30字节大小,那么,10W条记录和1W条记录对应的Key大小情况如下:100000 * 30 字节 = 3,000,0...原创 2019-04-27 22:44:07 · 2597 阅读 · 0 评论 -
redis pipeline 事务到底怎么回事呢? 怎么执行的?
MULTI,EXEC,DISCARDandWATCHare the foundation of transactions in Redis.They allow the execution of a group of commands in a single step, with two important guarantees: All the commands in a tr...原创 2019-04-25 11:47:27 · 824 阅读 · 0 评论 -
【redis】 大key解决方案第二步
方案:对于量少的大key 可以考虑本地cache protected Cache<String, Set<String>> habitMemberCache = CacheBuilder.newBuilder().maximumSize(2000L).expireAfterWrite(1800L, TimeUnit.SECONDS).build();...原创 2019-05-07 17:18:41 · 641 阅读 · 0 评论 -
【故障】oom导致 redis超时 rec 队列打满,导致tomcat拒绝服务
1 现象描述:磁盘占用到了50% 累计 ;PRINT_GC="-XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:-PrintHeapAtGC -XX:-UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=10M -Xlogg...原创 2019-05-20 23:44:32 · 657 阅读 · 0 评论 -
【redis集群】阿里云redis集群 对lua脚本的支持程度
1 阿里云集群 对lua脚本的支持程度https://help.aliyun.com/document_detail/26356.htmlLua使用限制Lua脚本放开限制,标准版-双节点、标准版-单节点支持用户直接调用。集群版本条件性支持:a 所有key都应该由KEYS数组来传递,redis.call/pcall中调用的redis命令,key的位置必须是KEYS array(不能...原创 2019-05-21 23:24:17 · 2438 阅读 · 2 评论 -
【RedissonClient】tryLock() 为什么做到了服务崩溃,lock也不会一直被占有?
源码解释:org.redisson.RedissonLock#tryAcquireOnceAsync private RFuture<Boolean> tryAcquireOnceAsync(long leaseTime, TimeUnit unit, final long threadId) { if (leaseTime != -1) { ...原创 2019-09-21 08:57:17 · 8299 阅读 · 4 评论 -
【思维导图】-- 读《redis实战》
1 目录2 构造支持程序3 计数器&统计原创 2019-10-08 07:22:43 · 179 阅读 · 0 评论 -
【工具库】--redis 安装+使用示例+安全(181)
1 安装 //ubuntu 操作系统sudoapt−getupdatesudo apt-get update sudo apt-get install redis-server$redis-server$redis-cli redis 127.0.0.1:6379> ping PONGredis 127.0.0.1:6379> CONFIG GET * redis 127.0.0.1:原创 2017-04-24 19:26:57 · 212 阅读 · 0 评论