Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xindoo
redis
提交
f6475c72
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,发现更多精彩内容 >>
提交
f6475c72
编写于
6月 12, 2010
作者:
A
antirez
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'expire' of
git://github.com/pietern/redis
上级
ac9b8cfe
829137b9
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
24 addition
and
28 deletion
+24
-28
redis.c
redis.c
+24
-28
未找到文件。
redis.c
浏览文件 @
f6475c72
...
...
@@ -1258,7 +1258,7 @@ static dictType keyptrDictType = {
NULL
,
/* key dup */
NULL
,
/* val dup */
dictSdsKeyCompare
,
/* key compare */
dictSdsDestructor
,
/* key destructor */
NULL
,
/* key destructor */
NULL
/* val destructor */
};
...
...
@@ -3532,12 +3532,10 @@ static robj *dbRandomKey(redisDb *db) {
/* Delete a key, value, and associated expiration entry if any, from the DB */
static
int
dbDelete
(
redisDb
*
db
,
robj
*
key
)
{
int
retval
;
if
(
dictSize
(
db
->
expires
))
dictDelete
(
db
->
expires
,
key
->
ptr
);
retval
=
dictDelete
(
db
->
dict
,
key
->
ptr
);
return
retval
==
DICT_OK
;
/* Deleting an entry from the expires dict will not free the sds of
* the key, because it is shared with the main dictionary. */
if
(
dictSize
(
db
->
expires
)
>
0
)
dictDelete
(
db
->
expires
,
key
->
ptr
);
return
dictDelete
(
db
->
dict
,
key
->
ptr
)
==
DICT_OK
;
}
/*============================ RDB saving/loading =========================== */
...
...
@@ -7856,6 +7854,9 @@ static void monitorCommand(redisClient *c) {
/* ================================= Expire ================================= */
static
int
removeExpire
(
redisDb
*
db
,
robj
*
key
)
{
/* An expire may only be removed if there is a corresponding entry in the
* main dict. Otherwise, the key will never be freed. */
redisAssert
(
dictFind
(
db
->
dict
,
key
->
ptr
)
!=
NULL
);
if
(
dictDelete
(
db
->
expires
,
key
->
ptr
)
==
DICT_OK
)
{
return
1
;
}
else
{
...
...
@@ -7864,9 +7865,11 @@ static int removeExpire(redisDb *db, robj *key) {
}
static
int
setExpire
(
redisDb
*
db
,
robj
*
key
,
time_t
when
)
{
sds
copy
=
sdsdup
(
key
->
ptr
);
if
(
dictAdd
(
db
->
expires
,
copy
,(
void
*
)
when
)
==
DICT_ERR
)
{
sdsfree
(
copy
);
dictEntry
*
de
;
/* Reuse the sds from the main dict in the expire dict */
redisAssert
((
de
=
dictFind
(
db
->
dict
,
key
->
ptr
))
!=
NULL
);
if
(
dictAdd
(
db
->
expires
,
dictGetEntryKey
(
de
),(
void
*
)
when
)
==
DICT_ERR
)
{
return
0
;
}
else
{
return
1
;
...
...
@@ -7882,39 +7885,32 @@ static time_t getExpire(redisDb *db, robj *key) {
if
(
dictSize
(
db
->
expires
)
==
0
||
(
de
=
dictFind
(
db
->
expires
,
key
->
ptr
))
==
NULL
)
return
-
1
;
/* The entry was found in the expire dict, this means it should also
* be present in the main dict (safety check). */
redisAssert
(
dictFind
(
db
->
dict
,
key
->
ptr
)
!=
NULL
);
return
(
time_t
)
dictGetEntryVal
(
de
);
}
static
int
expireIfNeeded
(
redisDb
*
db
,
robj
*
key
)
{
time_t
when
;
dictEntry
*
de
;
/* No expire? return ASAP */
if
(
dictSize
(
db
->
expires
)
==
0
||
(
de
=
dictFind
(
db
->
expires
,
key
->
ptr
))
==
NULL
)
return
0
;
time_t
when
=
getExpire
(
db
,
key
);
if
(
when
<
0
)
return
0
;
/* Lookup the expire */
when
=
(
time_t
)
dictGetEntryVal
(
de
);
/* Return when this key has not expired */
if
(
time
(
NULL
)
<=
when
)
return
0
;
/* Delete the key */
dbDelete
(
db
,
key
);
server
.
stat_expiredkeys
++
;
return
1
;
server
.
dirty
++
;
return
dbDelete
(
db
,
key
);
}
static
int
deleteIfVolatile
(
redisDb
*
db
,
robj
*
key
)
{
dictEntry
*
de
;
/* No expire? return ASAP */
if
(
dictSize
(
db
->
expires
)
==
0
||
(
de
=
dictFind
(
db
->
expires
,
key
->
ptr
))
==
NULL
)
return
0
;
if
(
getExpire
(
db
,
key
)
<
0
)
return
0
;
/* Delete the key */
server
.
dirty
++
;
server
.
stat_expiredkeys
++
;
dictDelete
(
db
->
expires
,
key
->
ptr
)
;
return
d
ictDelete
(
db
->
dict
,
key
->
ptr
)
==
DICT_OK
;
server
.
dirty
++
;
return
d
bDelete
(
db
,
key
)
;
}
static
void
expireGenericCommand
(
redisClient
*
c
,
robj
*
key
,
robj
*
param
,
long
offset
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录