Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
b46239e5
Commit
b46239e5
authored
Jul 06, 2016
by
antirez
Browse files
Expire and LRU related code moved into different files.
parent
0610683d
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
src/Makefile
View file @
b46239e5
...
@@ -128,7 +128,7 @@ endif
...
@@ -128,7 +128,7 @@ endif
REDIS_SERVER_NAME
=
redis-server
REDIS_SERVER_NAME
=
redis-server
REDIS_SENTINEL_NAME
=
redis-sentinel
REDIS_SENTINEL_NAME
=
redis-sentinel
REDIS_SERVER_OBJ
=
adlist.o quicklist.o ae.o anet.o dict.o server.o sds.o zmalloc.o lzf_c.o lzf_d.o pqsort.o zipmap.o sha1.o ziplist.o release.o networking.o util.o object.o db.o replication.o rdb.o t_string.o t_list.o t_set.o t_zset.o t_hash.o config.o aof.o pubsub.o multi.o debug.o sort.o intset.o syncio.o cluster.o crc16.o endianconv.o slowlog.o scripting.o bio.o rio.o rand.o memtest.o crc64.o bitops.o sentinel.o notify.o setproctitle.o blocked.o hyperloglog.o latency.o sparkline.o redis-check-rdb.o geo.o lazyfree.o module.o
REDIS_SERVER_OBJ
=
adlist.o quicklist.o ae.o anet.o dict.o server.o sds.o zmalloc.o lzf_c.o lzf_d.o pqsort.o zipmap.o sha1.o ziplist.o release.o networking.o util.o object.o db.o replication.o rdb.o t_string.o t_list.o t_set.o t_zset.o t_hash.o config.o aof.o pubsub.o multi.o debug.o sort.o intset.o syncio.o cluster.o crc16.o endianconv.o slowlog.o scripting.o bio.o rio.o rand.o memtest.o crc64.o bitops.o sentinel.o notify.o setproctitle.o blocked.o hyperloglog.o latency.o sparkline.o redis-check-rdb.o geo.o lazyfree.o module.o
evict.o expire.o
REDIS_GEOHASH_OBJ
=
../deps/geohash-int/geohash.o ../deps/geohash-int/geohash_helper.o
REDIS_GEOHASH_OBJ
=
../deps/geohash-int/geohash.o ../deps/geohash-int/geohash_helper.o
REDIS_CLI_NAME
=
redis-cli
REDIS_CLI_NAME
=
redis-cli
REDIS_CLI_OBJ
=
anet.o adlist.o redis-cli.o zmalloc.o release.o anet.o ae.o crc64.o
REDIS_CLI_OBJ
=
anet.o adlist.o redis-cli.o zmalloc.o release.o anet.o ae.o crc64.o
...
...
src/db.c
View file @
b46239e5
...
@@ -1010,134 +1010,6 @@ int expireIfNeeded(redisDb *db, robj *key) {
...
@@ -1010,134 +1010,6 @@ int expireIfNeeded(redisDb *db, robj *key) {
dbSyncDelete
(
db
,
key
);
dbSyncDelete
(
db
,
key
);
}
}
/*-----------------------------------------------------------------------------
* Expires Commands
*----------------------------------------------------------------------------*/
/* This is the generic command implementation for EXPIRE, PEXPIRE, EXPIREAT
* and PEXPIREAT. Because the commad second argument may be relative or absolute
* the "basetime" argument is used to signal what the base time is (either 0
* for *AT variants of the command, or the current time for relative expires).
*
* unit is either UNIT_SECONDS or UNIT_MILLISECONDS, and is only used for
* the argv[2] parameter. The basetime is always specified in milliseconds. */
void
expireGenericCommand
(
client
*
c
,
long
long
basetime
,
int
unit
)
{
robj
*
key
=
c
->
argv
[
1
],
*
param
=
c
->
argv
[
2
];
long
long
when
;
/* unix time in milliseconds when the key will expire. */
if
(
getLongLongFromObjectOrReply
(
c
,
param
,
&
when
,
NULL
)
!=
C_OK
)
return
;
if
(
unit
==
UNIT_SECONDS
)
when
*=
1000
;
when
+=
basetime
;
/* No key, return zero. */
if
(
lookupKeyWrite
(
c
->
db
,
key
)
==
NULL
)
{
addReply
(
c
,
shared
.
czero
);
return
;
}
/* EXPIRE with negative TTL, or EXPIREAT with a timestamp into the past
* should never be executed as a DEL when load the AOF or in the context
* of a slave instance.
*
* Instead we take the other branch of the IF statement setting an expire
* (possibly in the past) and wait for an explicit DEL from the master. */
if
(
when
<=
mstime
()
&&
!
server
.
loading
&&
!
server
.
masterhost
)
{
robj
*
aux
;
int
deleted
=
server
.
lazyfree_lazy_expire
?
dbAsyncDelete
(
c
->
db
,
key
)
:
dbSyncDelete
(
c
->
db
,
key
);
serverAssertWithInfo
(
c
,
key
,
deleted
);
server
.
dirty
++
;
/* Replicate/AOF this as an explicit DEL or UNLINK. */
aux
=
server
.
lazyfree_lazy_expire
?
shared
.
unlink
:
shared
.
del
;
rewriteClientCommandVector
(
c
,
2
,
aux
,
key
);
signalModifiedKey
(
c
->
db
,
key
);
notifyKeyspaceEvent
(
NOTIFY_GENERIC
,
"del"
,
key
,
c
->
db
->
id
);
addReply
(
c
,
shared
.
cone
);
return
;
}
else
{
setExpire
(
c
->
db
,
key
,
when
);
addReply
(
c
,
shared
.
cone
);
signalModifiedKey
(
c
->
db
,
key
);
notifyKeyspaceEvent
(
NOTIFY_GENERIC
,
"expire"
,
key
,
c
->
db
->
id
);
server
.
dirty
++
;
return
;
}
}
void
expireCommand
(
client
*
c
)
{
expireGenericCommand
(
c
,
mstime
(),
UNIT_SECONDS
);
}
void
expireatCommand
(
client
*
c
)
{
expireGenericCommand
(
c
,
0
,
UNIT_SECONDS
);
}
void
pexpireCommand
(
client
*
c
)
{
expireGenericCommand
(
c
,
mstime
(),
UNIT_MILLISECONDS
);
}
void
pexpireatCommand
(
client
*
c
)
{
expireGenericCommand
(
c
,
0
,
UNIT_MILLISECONDS
);
}
void
ttlGenericCommand
(
client
*
c
,
int
output_ms
)
{
long
long
expire
,
ttl
=
-
1
;
/* If the key does not exist at all, return -2 */
if
(
lookupKeyReadWithFlags
(
c
->
db
,
c
->
argv
[
1
],
LOOKUP_NOTOUCH
)
==
NULL
)
{
addReplyLongLong
(
c
,
-
2
);
return
;
}
/* The key exists. Return -1 if it has no expire, or the actual
* TTL value otherwise. */
expire
=
getExpire
(
c
->
db
,
c
->
argv
[
1
]);
if
(
expire
!=
-
1
)
{
ttl
=
expire
-
mstime
();
if
(
ttl
<
0
)
ttl
=
0
;
}
if
(
ttl
==
-
1
)
{
addReplyLongLong
(
c
,
-
1
);
}
else
{
addReplyLongLong
(
c
,
output_ms
?
ttl
:
((
ttl
+
500
)
/
1000
));
}
}
void
ttlCommand
(
client
*
c
)
{
ttlGenericCommand
(
c
,
0
);
}
void
pttlCommand
(
client
*
c
)
{
ttlGenericCommand
(
c
,
1
);
}
void
persistCommand
(
client
*
c
)
{
dictEntry
*
de
;
de
=
dictFind
(
c
->
db
->
dict
,
c
->
argv
[
1
]
->
ptr
);
if
(
de
==
NULL
)
{
addReply
(
c
,
shared
.
czero
);
}
else
{
if
(
removeExpire
(
c
->
db
,
c
->
argv
[
1
]))
{
addReply
(
c
,
shared
.
cone
);
server
.
dirty
++
;
}
else
{
addReply
(
c
,
shared
.
czero
);
}
}
}
/* TOUCH key1 [key2 key3 ... keyN] */
void
touchCommand
(
client
*
c
)
{
int
touched
=
0
;
for
(
int
j
=
1
;
j
<
c
->
argc
;
j
++
)
if
(
lookupKeyRead
(
c
->
db
,
c
->
argv
[
j
])
!=
NULL
)
touched
++
;
addReplyLongLong
(
c
,
touched
);
}
/* -----------------------------------------------------------------------------
/* -----------------------------------------------------------------------------
* API to get key arguments from commands
* API to get key arguments from commands
* ---------------------------------------------------------------------------*/
* ---------------------------------------------------------------------------*/
...
...
src/object.c
View file @
b46239e5
...
@@ -682,18 +682,6 @@ char *strEncoding(int encoding) {
...
@@ -682,18 +682,6 @@ char *strEncoding(int encoding) {
}
}
}
}
/* Given an object returns the min number of milliseconds the object was never
* requested, using an approximated LRU algorithm. */
unsigned
long
long
estimateObjectIdleTime
(
robj
*
o
)
{
unsigned
long
long
lruclock
=
LRU_CLOCK
();
if
(
lruclock
>=
o
->
lru
)
{
return
(
lruclock
-
o
->
lru
)
*
LRU_CLOCK_RESOLUTION
;
}
else
{
return
(
lruclock
+
(
LRU_CLOCK_MAX
-
o
->
lru
))
*
LRU_CLOCK_RESOLUTION
;
}
}
/* This is a helper function for the OBJECT command. We need to lookup keys
/* This is a helper function for the OBJECT command. We need to lookup keys
* without any modification of LRU or other parameters. */
* without any modification of LRU or other parameters. */
robj
*
objectCommandLookup
(
client
*
c
,
robj
*
key
)
{
robj
*
objectCommandLookup
(
client
*
c
,
robj
*
key
)
{
...
...
src/server.c
View file @
b46239e5
This diff is collapsed.
Click to expand it.
src/server.h
View file @
b46239e5
...
@@ -1613,6 +1613,9 @@ void replyToBlockedClientTimedOut(client *c);
...
@@ -1613,6 +1613,9 @@ void replyToBlockedClientTimedOut(client *c);
int
getTimeoutFromObjectOrReply
(
client
*
c
,
robj
*
object
,
mstime_t
*
timeout
,
int
unit
);
int
getTimeoutFromObjectOrReply
(
client
*
c
,
robj
*
object
,
mstime_t
*
timeout
,
int
unit
);
void
disconnectAllBlockedClients
(
void
);
void
disconnectAllBlockedClients
(
void
);
/* expire.c -- Handling of expired keys */
void
activeExpireCycle
(
int
type
);
/* Git SHA1 */
/* Git SHA1 */
char
*
redisGitSHA1
(
void
);
char
*
redisGitSHA1
(
void
);
char
*
redisGitDirty
(
void
);
char
*
redisGitDirty
(
void
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment