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
d1949054
Commit
d1949054
authored
Mar 27, 2012
by
Premysl Hruby
Browse files
use server.unixtime instead of time(NULL) where possible (cluster.c not checked though)
parent
024f213b
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/aof.c
View file @
d1949054
...
@@ -46,7 +46,7 @@ void stopAppendOnly(void) {
...
@@ -46,7 +46,7 @@ void stopAppendOnly(void) {
/* Called when the user switches from "appendonly no" to "appendonly yes"
/* Called when the user switches from "appendonly no" to "appendonly yes"
* at runtime using the CONFIG command. */
* at runtime using the CONFIG command. */
int
startAppendOnly
(
void
)
{
int
startAppendOnly
(
void
)
{
server
.
aof_last_fsync
=
time
(
NULL
)
;
server
.
aof_last_fsync
=
server
.
unixtime
;
server
.
aof_fd
=
open
(
server
.
aof_filename
,
O_WRONLY
|
O_APPEND
|
O_CREAT
,
0644
);
server
.
aof_fd
=
open
(
server
.
aof_filename
,
O_WRONLY
|
O_APPEND
|
O_CREAT
,
0644
);
redisAssert
(
server
.
aof_state
==
REDIS_AOF_OFF
);
redisAssert
(
server
.
aof_state
==
REDIS_AOF_OFF
);
if
(
server
.
aof_fd
==
-
1
)
{
if
(
server
.
aof_fd
==
-
1
)
{
...
...
src/networking.c
View file @
d1949054
...
@@ -52,7 +52,7 @@ redisClient *createClient(int fd) {
...
@@ -52,7 +52,7 @@ redisClient *createClient(int fd) {
c
->
bulklen
=
-
1
;
c
->
bulklen
=
-
1
;
c
->
sentlen
=
0
;
c
->
sentlen
=
0
;
c
->
flags
=
0
;
c
->
flags
=
0
;
c
->
ctime
=
c
->
lastinteraction
=
time
(
NULL
)
;
c
->
ctime
=
c
->
lastinteraction
=
server
.
unixtime
;
c
->
authenticated
=
0
;
c
->
authenticated
=
0
;
c
->
replstate
=
REDIS_REPL_NONE
;
c
->
replstate
=
REDIS_REPL_NONE
;
c
->
reply
=
listCreate
();
c
->
reply
=
listCreate
();
...
@@ -604,7 +604,7 @@ void freeClient(redisClient *c) {
...
@@ -604,7 +604,7 @@ void freeClient(redisClient *c) {
if
(
c
->
flags
&
REDIS_MASTER
)
{
if
(
c
->
flags
&
REDIS_MASTER
)
{
server
.
master
=
NULL
;
server
.
master
=
NULL
;
server
.
repl_state
=
REDIS_REPL_CONNECT
;
server
.
repl_state
=
REDIS_REPL_CONNECT
;
server
.
repl_down_since
=
time
(
NULL
)
;
server
.
repl_down_since
=
server
.
unixtime
;
/* Since we lost the connection with the master, we should also
/* Since we lost the connection with the master, we should also
* close the connection with all our slaves if we have any, so
* close the connection with all our slaves if we have any, so
* when we'll resync with the master the other slaves will sync again
* when we'll resync with the master the other slaves will sync again
...
@@ -732,7 +732,7 @@ void sendReplyToClient(aeEventLoop *el, int fd, void *privdata, int mask) {
...
@@ -732,7 +732,7 @@ void sendReplyToClient(aeEventLoop *el, int fd, void *privdata, int mask) {
return
;
return
;
}
}
}
}
if
(
totwritten
>
0
)
c
->
lastinteraction
=
time
(
NULL
)
;
if
(
totwritten
>
0
)
c
->
lastinteraction
=
server
.
unixtime
;
if
(
c
->
bufpos
==
0
&&
listLength
(
c
->
reply
)
==
0
)
{
if
(
c
->
bufpos
==
0
&&
listLength
(
c
->
reply
)
==
0
)
{
c
->
sentlen
=
0
;
c
->
sentlen
=
0
;
aeDeleteFileEvent
(
server
.
el
,
c
->
fd
,
AE_WRITABLE
);
aeDeleteFileEvent
(
server
.
el
,
c
->
fd
,
AE_WRITABLE
);
...
@@ -1017,7 +1017,7 @@ void readQueryFromClient(aeEventLoop *el, int fd, void *privdata, int mask) {
...
@@ -1017,7 +1017,7 @@ void readQueryFromClient(aeEventLoop *el, int fd, void *privdata, int mask) {
}
}
if
(
nread
)
{
if
(
nread
)
{
sdsIncrLen
(
c
->
querybuf
,
nread
);
sdsIncrLen
(
c
->
querybuf
,
nread
);
c
->
lastinteraction
=
time
(
NULL
)
;
c
->
lastinteraction
=
server
.
unixtime
;
}
else
{
}
else
{
server
.
current_client
=
NULL
;
server
.
current_client
=
NULL
;
return
;
return
;
...
@@ -1058,7 +1058,6 @@ void getClientsMaxBuffers(unsigned long *longest_output_list,
...
@@ -1058,7 +1058,6 @@ void getClientsMaxBuffers(unsigned long *longest_output_list,
sds
getClientInfoString
(
redisClient
*
client
)
{
sds
getClientInfoString
(
redisClient
*
client
)
{
char
ip
[
32
],
flags
[
16
],
events
[
3
],
*
p
;
char
ip
[
32
],
flags
[
16
],
events
[
3
],
*
p
;
int
port
;
int
port
;
time_t
now
=
time
(
NULL
);
int
emask
;
int
emask
;
anetPeerToString
(
client
->
fd
,
ip
,
&
port
);
anetPeerToString
(
client
->
fd
,
ip
,
&
port
);
...
@@ -1087,8 +1086,8 @@ sds getClientInfoString(redisClient *client) {
...
@@ -1087,8 +1086,8 @@ sds getClientInfoString(redisClient *client) {
return
sdscatprintf
(
sdsempty
(),
return
sdscatprintf
(
sdsempty
(),
"addr=%s:%d fd=%d age=%ld idle=%ld flags=%s db=%d sub=%d psub=%d qbuf=%lu qbuf-free=%lu obl=%lu oll=%lu omem=%lu events=%s cmd=%s"
,
"addr=%s:%d fd=%d age=%ld idle=%ld flags=%s db=%d sub=%d psub=%d qbuf=%lu qbuf-free=%lu obl=%lu oll=%lu omem=%lu events=%s cmd=%s"
,
ip
,
port
,
client
->
fd
,
ip
,
port
,
client
->
fd
,
(
long
)(
now
-
client
->
ctime
),
(
long
)(
server
.
unixtime
-
client
->
ctime
),
(
long
)(
now
-
client
->
lastinteraction
),
(
long
)(
server
.
unixtime
-
client
->
lastinteraction
),
flags
,
flags
,
client
->
db
->
id
,
client
->
db
->
id
,
(
int
)
dictSize
(
client
->
pubsub_channels
),
(
int
)
dictSize
(
client
->
pubsub_channels
),
...
...
src/redis.c
View file @
d1949054
...
@@ -612,7 +612,7 @@ void activeExpireCycle(void) {
...
@@ -612,7 +612,7 @@ void activeExpireCycle(void) {
}
}
void
updateLRUClock
(
void
)
{
void
updateLRUClock
(
void
)
{
server
.
lruclock
=
(
time
(
NULL
)
/
REDIS_LRU_CLOCK_RESOLUTION
)
&
server
.
lruclock
=
(
server
.
unixtime
/
REDIS_LRU_CLOCK_RESOLUTION
)
&
REDIS_LRU_CLOCK_MAX
;
REDIS_LRU_CLOCK_MAX
;
}
}
...
@@ -821,15 +821,13 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) {
...
@@ -821,15 +821,13 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) {
updateDictResizePolicy
();
updateDictResizePolicy
();
}
}
}
else
{
}
else
{
time_t
now
=
time
(
NULL
);
/* If there is not a background saving/rewrite in progress check if
/* If there is not a background saving/rewrite in progress check if
* we have to save/rewrite now */
* we have to save/rewrite now */
for
(
j
=
0
;
j
<
server
.
saveparamslen
;
j
++
)
{
for
(
j
=
0
;
j
<
server
.
saveparamslen
;
j
++
)
{
struct
saveparam
*
sp
=
server
.
saveparams
+
j
;
struct
saveparam
*
sp
=
server
.
saveparams
+
j
;
if
(
server
.
dirty
>=
sp
->
changes
&&
if
(
server
.
dirty
>=
sp
->
changes
&&
now
-
server
.
lastsave
>
sp
->
seconds
)
{
server
.
unixtime
-
server
.
lastsave
>
sp
->
seconds
)
{
redisLog
(
REDIS_NOTICE
,
"%d changes in %d seconds. Saving..."
,
redisLog
(
REDIS_NOTICE
,
"%d changes in %d seconds. Saving..."
,
sp
->
changes
,
sp
->
seconds
);
sp
->
changes
,
sp
->
seconds
);
rdbSaveBackground
(
server
.
rdb_filename
);
rdbSaveBackground
(
server
.
rdb_filename
);
...
@@ -1683,7 +1681,7 @@ void bytesToHuman(char *s, unsigned long long n) {
...
@@ -1683,7 +1681,7 @@ void bytesToHuman(char *s, unsigned long long n) {
* on memory corruption problems. */
* on memory corruption problems. */
sds
genRedisInfoString
(
char
*
section
)
{
sds
genRedisInfoString
(
char
*
section
)
{
sds
info
=
sdsempty
();
sds
info
=
sdsempty
();
time_t
uptime
=
time
(
NULL
)
-
server
.
stat_starttime
;
time_t
uptime
=
server
.
unixtime
-
server
.
stat_starttime
;
int
j
,
numcommands
;
int
j
,
numcommands
;
struct
rusage
self_ru
,
c_ru
;
struct
rusage
self_ru
,
c_ru
;
unsigned
long
lol
,
bib
;
unsigned
long
lol
,
bib
;
...
@@ -1822,7 +1820,7 @@ sds genRedisInfoString(char *section) {
...
@@ -1822,7 +1820,7 @@ sds genRedisInfoString(char *section) {
perc
=
((
double
)
server
.
loading_loaded_bytes
/
perc
=
((
double
)
server
.
loading_loaded_bytes
/
server
.
loading_total_bytes
)
*
100
;
server
.
loading_total_bytes
)
*
100
;
elapsed
=
time
(
NULL
)
-
server
.
loading_start_time
;
elapsed
=
server
.
unixtime
-
server
.
loading_start_time
;
if
(
elapsed
==
0
)
{
if
(
elapsed
==
0
)
{
eta
=
1
;
/* A fake 1 second figure if we don't have
eta
=
1
;
/* A fake 1 second figure if we don't have
enough info */
enough info */
...
@@ -1893,7 +1891,7 @@ sds genRedisInfoString(char *section) {
...
@@ -1893,7 +1891,7 @@ sds genRedisInfoString(char *section) {
(
server
.
repl_state
==
REDIS_REPL_CONNECTED
)
?
(
server
.
repl_state
==
REDIS_REPL_CONNECTED
)
?
"up"
:
"down"
,
"up"
:
"down"
,
server
.
master
?
server
.
master
?
((
int
)(
time
(
NULL
)
-
server
.
master
->
lastinteraction
))
:
-
1
,
((
int
)(
server
.
unixtime
-
server
.
master
->
lastinteraction
))
:
-
1
,
server
.
repl_state
==
REDIS_REPL_TRANSFER
server
.
repl_state
==
REDIS_REPL_TRANSFER
);
);
...
@@ -1902,14 +1900,14 @@ sds genRedisInfoString(char *section) {
...
@@ -1902,14 +1900,14 @@ sds genRedisInfoString(char *section) {
"master_sync_left_bytes:%ld
\r\n
"
"master_sync_left_bytes:%ld
\r\n
"
"master_sync_last_io_seconds_ago:%d
\r\n
"
"master_sync_last_io_seconds_ago:%d
\r\n
"
,(
long
)
server
.
repl_transfer_left
,
,(
long
)
server
.
repl_transfer_left
,
(
int
)(
time
(
NULL
)
-
server
.
repl_transfer_lastio
)
(
int
)(
server
.
unixtime
-
server
.
repl_transfer_lastio
)
);
);
}
}
if
(
server
.
repl_state
!=
REDIS_REPL_CONNECTED
)
{
if
(
server
.
repl_state
!=
REDIS_REPL_CONNECTED
)
{
info
=
sdscatprintf
(
info
,
info
=
sdscatprintf
(
info
,
"master_link_down_since_seconds:%ld
\r\n
"
,
"master_link_down_since_seconds:%ld
\r\n
"
,
(
long
)
time
(
NULL
)
-
server
.
repl_down_since
);
(
long
)
server
.
unixtime
-
server
.
repl_down_since
);
}
}
}
}
info
=
sdscatprintf
(
info
,
info
=
sdscatprintf
(
info
,
...
...
src/replication.c
View file @
d1949054
...
@@ -307,7 +307,7 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
...
@@ -307,7 +307,7 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
/* At this stage just a newline works as a PING in order to take
/* At this stage just a newline works as a PING in order to take
* the connection live. So we refresh our last interaction
* the connection live. So we refresh our last interaction
* timestamp. */
* timestamp. */
server
.
repl_transfer_lastio
=
time
(
NULL
)
;
server
.
repl_transfer_lastio
=
server
.
unixtime
;
return
;
return
;
}
else
if
(
buf
[
0
]
!=
'$'
)
{
}
else
if
(
buf
[
0
]
!=
'$'
)
{
redisLog
(
REDIS_WARNING
,
"Bad protocol from MASTER, the first byte is not '$', are you sure the host and port are right?"
);
redisLog
(
REDIS_WARNING
,
"Bad protocol from MASTER, the first byte is not '$', are you sure the host and port are right?"
);
...
@@ -330,7 +330,7 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
...
@@ -330,7 +330,7 @@ void readSyncBulkPayload(aeEventLoop *el, int fd, void *privdata, int mask) {
replicationAbortSyncTransfer
();
replicationAbortSyncTransfer
();
return
;
return
;
}
}
server
.
repl_transfer_lastio
=
time
(
NULL
)
;
server
.
repl_transfer_lastio
=
server
.
unixtime
;
if
(
write
(
server
.
repl_transfer_fd
,
buf
,
nread
)
!=
nread
)
{
if
(
write
(
server
.
repl_transfer_fd
,
buf
,
nread
)
!=
nread
)
{
redisLog
(
REDIS_WARNING
,
"Write error or short write writing to the DB dump file needed for MASTER <-> SLAVE synchrnonization: %s"
,
strerror
(
errno
));
redisLog
(
REDIS_WARNING
,
"Write error or short write writing to the DB dump file needed for MASTER <-> SLAVE synchrnonization: %s"
,
strerror
(
errno
));
goto
error
;
goto
error
;
...
@@ -441,7 +441,7 @@ void syncWithMaster(aeEventLoop *el, int fd, void *privdata, int mask) {
...
@@ -441,7 +441,7 @@ void syncWithMaster(aeEventLoop *el, int fd, void *privdata, int mask) {
/* Prepare a suitable temp file for bulk transfer */
/* Prepare a suitable temp file for bulk transfer */
while
(
maxtries
--
)
{
while
(
maxtries
--
)
{
snprintf
(
tmpfile
,
256
,
snprintf
(
tmpfile
,
256
,
"temp-%d.%ld.rdb"
,(
int
)
time
(
NULL
)
,(
long
int
)
getpid
());
"temp-%d.%ld.rdb"
,(
int
)
server
.
unixtime
,(
long
int
)
getpid
());
dfd
=
open
(
tmpfile
,
O_CREAT
|
O_WRONLY
|
O_EXCL
,
0644
);
dfd
=
open
(
tmpfile
,
O_CREAT
|
O_WRONLY
|
O_EXCL
,
0644
);
if
(
dfd
!=
-
1
)
break
;
if
(
dfd
!=
-
1
)
break
;
sleep
(
1
);
sleep
(
1
);
...
@@ -462,7 +462,7 @@ void syncWithMaster(aeEventLoop *el, int fd, void *privdata, int mask) {
...
@@ -462,7 +462,7 @@ void syncWithMaster(aeEventLoop *el, int fd, void *privdata, int mask) {
server
.
repl_state
=
REDIS_REPL_TRANSFER
;
server
.
repl_state
=
REDIS_REPL_TRANSFER
;
server
.
repl_transfer_left
=
-
1
;
server
.
repl_transfer_left
=
-
1
;
server
.
repl_transfer_fd
=
dfd
;
server
.
repl_transfer_fd
=
dfd
;
server
.
repl_transfer_lastio
=
time
(
NULL
)
;
server
.
repl_transfer_lastio
=
server
.
unixtime
;
server
.
repl_transfer_tmpfile
=
zstrdup
(
tmpfile
);
server
.
repl_transfer_tmpfile
=
zstrdup
(
tmpfile
);
return
;
return
;
...
@@ -490,7 +490,7 @@ int connectWithMaster(void) {
...
@@ -490,7 +490,7 @@ int connectWithMaster(void) {
return
REDIS_ERR
;
return
REDIS_ERR
;
}
}
server
.
repl_transfer_lastio
=
time
(
NULL
)
;
server
.
repl_transfer_lastio
=
server
.
unixtime
;
server
.
repl_transfer_s
=
fd
;
server
.
repl_transfer_s
=
fd
;
server
.
repl_state
=
REDIS_REPL_CONNECTING
;
server
.
repl_state
=
REDIS_REPL_CONNECTING
;
return
REDIS_OK
;
return
REDIS_OK
;
...
...
src/t_list.c
View file @
d1949054
...
@@ -910,7 +910,7 @@ int getTimeoutFromObjectOrReply(redisClient *c, robj *object, time_t *timeout) {
...
@@ -910,7 +910,7 @@ int getTimeoutFromObjectOrReply(redisClient *c, robj *object, time_t *timeout) {
return
REDIS_ERR
;
return
REDIS_ERR
;
}
}
if
(
tval
>
0
)
tval
+=
time
(
NULL
)
;
if
(
tval
>
0
)
tval
+=
server
.
unixtime
;
*
timeout
=
tval
;
*
timeout
=
tval
;
return
REDIS_OK
;
return
REDIS_OK
;
...
...
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