summaryrefslogtreecommitdiff
path: root/src/networking.c
diff options
context:
space:
mode:
authorChen Tianjie <TJ_Chen@outlook.com>2023-02-23 15:07:49 +0800
committerGitHub <noreply@github.com>2023-02-23 09:07:49 +0200
commit897c3d522c6814b1853b767795a18565c047133e (patch)
treebdf1ccbb9b25d9144ba1c1ee115565c7a9f696d8 /src/networking.c
parentcd58af4d7fe4b506899591b2846cfba61335c958 (diff)
downloadredis-897c3d522c6814b1853b767795a18565c047133e.tar.gz
Add CLIENT NO-TOUCH for clients to run commands without affecting LRU/LFU of keys (#11483)
When no-touch mode is enabled, the client will not touch LRU/LFU of the keys it accesses, except when executing command `TOUCH`. This allows inspecting or modifying the key-space without affecting their eviction. Changes: - A command `CLIENT NO-TOUCH ON|OFF` to switch on and off this mode. - A client flag `#define CLIENT_NOTOUCH (1ULL<<45)`, which can be shown with `CLIENT INFO`, by the letter "T" in the "flags" field. - Clear `NO-TOUCH` flag in `clearClientConnectionState`, which is used by `RESET` command and resetting temp clients used by modules. - Also clear `NO-EVICT` flag in `clearClientConnectionState`, this might have been an oversight, spotted by @madolson. - A test using `DEBUG OBJECT` command to verify that LRU stat is not touched when no-touch mode is on. Co-authored-by: chentianjie <chentianjie@alibaba-inc.com> Co-authored-by: Madelyn Olson <34459052+madolson@users.noreply.github.com> Co-authored-by: sundb <sundbcn@gmail.com>
Diffstat (limited to 'src/networking.c')
-rw-r--r--src/networking.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/networking.c b/src/networking.c
index 117c54a96..2edb7b72a 100644
--- a/src/networking.c
+++ b/src/networking.c
@@ -1493,8 +1493,8 @@ void clearClientConnectionState(client *c) {
}
/* Selectively clear state flags not covered above */
- c->flags &= ~(CLIENT_ASKING|CLIENT_READONLY|CLIENT_PUBSUB|
- CLIENT_REPLY_OFF|CLIENT_REPLY_SKIP_NEXT);
+ c->flags &= ~(CLIENT_ASKING|CLIENT_READONLY|CLIENT_PUBSUB|CLIENT_REPLY_OFF|
+ CLIENT_REPLY_SKIP_NEXT|CLIENT_NO_TOUCH|CLIENT_NO_EVICT);
}
void freeClient(client *c) {
@@ -2692,7 +2692,7 @@ char *getClientSockname(client *c) {
/* Concatenate a string representing the state of a client in a human
* readable format, into the sds string 's'. */
sds catClientInfoString(sds s, client *client) {
- char flags[16], events[3], conninfo[CONN_INFO_LEN], *p;
+ char flags[17], events[3], conninfo[CONN_INFO_LEN], *p;
p = flags;
if (client->flags & CLIENT_SLAVE) {
@@ -2715,6 +2715,7 @@ sds catClientInfoString(sds s, client *client) {
if (client->flags & CLIENT_UNIX_SOCKET) *p++ = 'U';
if (client->flags & CLIENT_READONLY) *p++ = 'r';
if (client->flags & CLIENT_NO_EVICT) *p++ = 'e';
+ if (client->flags & CLIENT_NO_TOUCH) *p++ = 'T';
if (p == flags) *p++ = 'N';
*p++ = '\0';
@@ -2905,6 +2906,8 @@ void clientCommand(client *c) {
" Report tracking status for the current connection.",
"NO-EVICT (ON|OFF)",
" Protect current client connection from eviction.",
+"NO-TOUCH (ON|OFF)",
+" Will not touch LRU/LFU stats when this mode is on.",
NULL
};
addReplyHelp(c, help);
@@ -3374,6 +3377,17 @@ NULL
} else {
addReplyArrayLen(c,0);
}
+ } else if (!strcasecmp(c->argv[1]->ptr, "no-touch")) {
+ /* CLIENT NO-TOUCH ON|OFF */
+ if (!strcasecmp(c->argv[2]->ptr,"on")) {
+ c->flags |= CLIENT_NO_TOUCH;
+ addReply(c,shared.ok);
+ } else if (!strcasecmp(c->argv[2]->ptr,"off")) {
+ c->flags &= ~CLIENT_NO_TOUCH;
+ addReply(c,shared.ok);
+ } else {
+ addReplyErrorObject(c,shared.syntaxerr);
+ }
} else {
addReplySubcommandSyntaxError(c);
}