Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add notification support for HFE #13237

Merged
merged 8 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/t_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ void hashTypeSetExDone(HashTypeSetEx *ex) {
if (ex->c) {
server.dirty += ex->fieldDeleted + ex->fieldUpdated;
signalModifiedKey(ex->c, ex->db, ex->key);
notifyKeyspaceEvent(NOTIFY_HASH, ex->cmd, ex->key, ex->db->id);
notifyKeyspaceEvent(NOTIFY_HASH, "hexpire", ex->key, ex->db->id);
}
if (ex->fieldDeleted && hashTypeLength(ex->hashObj, 0) == 0) {
dbDelete(ex->db,ex->key);
Expand Down Expand Up @@ -2947,6 +2947,7 @@ void hpexpiretimeCommand(client *c) {
void hpersistCommand(client *c) {
robj *hashObj;
long numFields = 0, numFieldsAt = 2;
int changed = 0; /* Used to determine whether to send a notification. */

/* Read the hash object */
if ((hashObj = lookupKeyReadOrReply(c, c->argv[1], shared.null[c->resp])) == NULL ||
Expand Down Expand Up @@ -3017,8 +3018,8 @@ void hpersistCommand(client *c) {

listpackExPersist(hashObj, field, fptr, vptr);
addReplyLongLong(c, HFE_PERSIST_OK);
changed = 1;
}
return;
} else if (hashObj->encoding == OBJ_ENCODING_HT) {
dict *d = hashObj->ptr;

Expand Down Expand Up @@ -3046,10 +3047,15 @@ void hpersistCommand(client *c) {

hfieldPersist(hashObj, hf);
addReplyLongLong(c, HFE_PERSIST_OK);
changed = 1;
}
} else {
serverPanic("Unknown encoding: %d", hashObj->encoding);
}

/* Generates a hpersist event if the expiry time associated with any field
* has been successfully deleted. */
if (changed) notifyKeyspaceEvent(NOTIFY_HASH,"hpersist",c->argv[1],c->db->id);
}

/**
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/pubsub.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -354,14 +354,23 @@ start_server {tags {"pubsub network"}} {
}

test "Keyspace notifications: hash events test" {
r config set hash-max-listpack-entries 1 ;# TODO: removed after hfe listpack is merged
moticless marked this conversation as resolved.
Show resolved Hide resolved
r config set notify-keyspace-events Kh
r del myhash
set rd1 [redis_deferring_client]
assert_equal {1} [psubscribe $rd1 *]
r hmset myhash yes 1 no 0
r hincrby myhash yes 10
r hexpire myhash 999999 1 yes
r hexpireat myhash [expr {[clock seconds] + 999999}] NX 1 no
r hpexpire myhash 5 1 yes
r hpersist myhash 1 yes
assert_equal "pmessage * __keyspace@${db}__:myhash hset" [$rd1 read]
assert_equal "pmessage * __keyspace@${db}__:myhash hincrby" [$rd1 read]
assert_equal "pmessage * __keyspace@${db}__:myhash hexpire" [$rd1 read]
assert_equal "pmessage * __keyspace@${db}__:myhash hexpire" [$rd1 read]
assert_equal "pmessage * __keyspace@${db}__:myhash hexpire" [$rd1 read]
assert_equal "pmessage * __keyspace@${db}__:myhash hpersist" [$rd1 read]
$rd1 close
}

Expand Down