Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xindoo
redis
提交
94754ccc
R
redis
项目概览
xindoo
/
redis
通知
2
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
redis
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
94754ccc
编写于
4月 01, 2009
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
non-lazy expired keys purging implemented
上级
98c541c5
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
51 addition
and
3 deletion
+51
-3
redis.c
redis.c
+51
-3
未找到文件。
redis.c
浏览文件 @
94754ccc
...
...
@@ -71,6 +71,7 @@
#define REDIS_CONFIGLINE_MAX 1024
#define REDIS_OBJFREELIST_MAX 1000000
/* Max number of objects to cache */
#define REDIS_MAX_SYNC_TIME 60
/* Slave can't take more to sync */
#define REDIS_EXPIRELOOKUPS_PER_CRON 100
/* try to expire 100 keys/second */
/* Hash table parameters */
#define REDIS_HT_MINFILL 10
/* Minimal hash table fill 10% */
...
...
@@ -285,6 +286,7 @@ static robj *tryObjectSharing(robj *o);
static
int
removeExpire
(
redisDb
*
db
,
robj
*
key
);
static
int
expireIfNeeded
(
redisDb
*
db
,
robj
*
key
);
static
int
deleteIfVolatile
(
redisDb
*
db
,
robj
*
key
);
static
int
deleteKey
(
redisDb
*
db
,
robj
*
key
);
static
void
authCommand
(
redisClient
*
c
);
static
void
pingCommand
(
redisClient
*
c
);
...
...
@@ -628,7 +630,7 @@ void closeTimedoutClients(void) {
}
int
serverCron
(
struct
aeEventLoop
*
eventLoop
,
long
long
id
,
void
*
clientData
)
{
int
j
,
size
,
used
,
loops
=
server
.
cronloops
++
;
int
j
,
loops
=
server
.
cronloops
++
;
REDIS_NOTUSED
(
eventLoop
);
REDIS_NOTUSED
(
id
);
REDIS_NOTUSED
(
clientData
);
...
...
@@ -639,10 +641,13 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) {
/* If the percentage of used slots in the HT reaches REDIS_HT_MINFILL
* we resize the hash table to save memory */
for
(
j
=
0
;
j
<
server
.
dbnum
;
j
++
)
{
int
size
,
used
,
vkeys
;
size
=
dictSlots
(
server
.
db
[
j
].
dict
);
used
=
dictSize
(
server
.
db
[
j
].
dict
);
vkeys
=
dictSize
(
server
.
db
[
j
].
expires
);
if
(
!
(
loops
%
5
)
&&
used
>
0
)
{
redisLog
(
REDIS_DEBUG
,
"DB %d: %d keys
in %d slots HT."
,
j
,
used
,
size
);
redisLog
(
REDIS_DEBUG
,
"DB %d: %d keys
(%d volatile) in %d slots HT."
,
j
,
used
,
vkeys
,
size
);
/* dictPrintStats(server.dict); */
}
if
(
size
&&
used
&&
size
>
REDIS_HT_MINSLOTS
&&
...
...
@@ -698,6 +703,30 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) {
}
}
}
/* Try to expire a few timed out keys */
for
(
j
=
0
;
j
<
server
.
dbnum
;
j
++
)
{
redisDb
*
db
=
server
.
db
+
j
;
int
num
=
dictSize
(
db
->
expires
);
if
(
num
)
{
time_t
now
=
time
(
NULL
);
if
(
num
>
REDIS_EXPIRELOOKUPS_PER_CRON
)
num
=
REDIS_EXPIRELOOKUPS_PER_CRON
;
while
(
num
--
)
{
dictEntry
*
de
;
time_t
t
;
if
((
de
=
dictGetRandomKey
(
db
->
expires
))
==
NULL
)
break
;
t
=
(
time_t
)
dictGetEntryVal
(
de
);
if
(
now
>
t
)
{
deleteKey
(
db
,
dictGetEntryKey
(
de
));
}
}
}
}
/* Check if we should connect to a MASTER */
if
(
server
.
replstate
==
REDIS_REPL_CONNECT
)
{
redisLog
(
REDIS_NOTICE
,
"Connecting to MASTER..."
);
...
...
@@ -1446,10 +1475,19 @@ static void freeHashObject(robj *o) {
static
void
incrRefCount
(
robj
*
o
)
{
o
->
refcount
++
;
#ifdef DEBUG_REFCOUNT
if
(
o
->
type
==
REDIS_STRING
)
printf
(
"Increment '%s'(%p), now is: %d
\n
"
,
o
->
ptr
,
o
,
o
->
refcount
);
#endif
}
static
void
decrRefCount
(
void
*
obj
)
{
robj
*
o
=
obj
;
#ifdef DEBUG_REFCOUNT
if
(
o
->
type
==
REDIS_STRING
)
printf
(
"Decrement '%s'(%p), now is: %d
\n
"
,
o
->
ptr
,
o
,
o
->
refcount
-
1
);
#endif
if
(
--
(
o
->
refcount
)
==
0
)
{
switch
(
o
->
type
)
{
case
REDIS_STRING
:
freeStringObject
(
o
);
break
;
...
...
@@ -1525,8 +1563,18 @@ static robj *lookupKeyWrite(redisDb *db, robj *key) {
}
static
int
deleteKey
(
redisDb
*
db
,
robj
*
key
)
{
int
retval
;
/* We need to protect key from destruction: after the first dictDelete()
* it may happen that 'key' is no longer valid if we don't increment
* it's count. This may happen when we get the object reference directly
* from the hash table with dictRandomKey() or dict iterators */
incrRefCount
(
key
);
if
(
dictSize
(
db
->
expires
))
dictDelete
(
db
->
expires
,
key
);
return
dictDelete
(
db
->
dict
,
key
)
==
DICT_OK
;
retval
=
dictDelete
(
db
->
dict
,
key
);
decrRefCount
(
key
);
return
retval
==
DICT_OK
;
}
/*============================ DB saving/loading ============================ */
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录