Skip to content

Commit 9562e62

Browse files
committed
add code for hset function
1 parent 14d96f8 commit 9562e62

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/t_hash.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1109,13 +1109,24 @@ void hsetnxCommand(client *c) {
11091109
void hsetCommand(client *c) {
11101110
int i, created = 0;
11111111
robj *o;
1112+
long previous_element_number;
1113+
long current_element_number;
11121114

11131115
if ((c->argc % 2) == 1) {
11141116
addReplyErrorArity(c);
11151117
return;
11161118
}
11171119

1118-
if ((o = hashTypeLookupWriteOrCreate(c, c->argv[1])) == NULL) return;
1120+
o = lookupKeyWrite(c->db, c->argv[1]);
1121+
if (checkType(c, o, OBJ_HASH)) return;
1122+
if (o == NULL) {
1123+
o = createHashObject();
1124+
dbAdd(c->db, c->argv[1], &o);
1125+
previous_element_number = 0;
1126+
} else {
1127+
previous_element_number = hashTypeLength(o);
1128+
}
1129+
11191130
hashTypeTryConversion(o, c->argv, 2, c->argc - 1);
11201131
bool has_volatile_fields = hashTypeHasVolatileFields(o);
11211132
for (i = 2; i < c->argc; i += 2) {
@@ -1128,6 +1139,11 @@ void hsetCommand(client *c) {
11281139
notifyKeyspaceEvent(NOTIFY_HASH, "hset", c->argv[1], c->db->id);
11291140
server.dirty += (c->argc - 2) / 2;
11301141

1142+
if (created > 0) {
1143+
current_element_number = previous_element_number + created;
1144+
updateBigKeyList(c->argv[1], previous_element_number, current_element_number, HASH_TYPE);
1145+
}
1146+
11311147
/* HMSET (deprecated) and HSET return value is different. */
11321148
char *cmdname = c->argv[0]->ptr;
11331149
if (cmdname[1] == 's' || cmdname[1] == 'S') {

src/t_list.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,8 @@ void linsertCommand(client *c) {
521521
listTypeIterator *iter;
522522
listTypeEntry entry;
523523
int inserted = 0;
524+
long previous_element_number;
525+
long current_element_number;
524526

525527
if (strcasecmp(c->argv[2]->ptr, "after") == 0) {
526528
where = LIST_TAIL;
@@ -539,6 +541,7 @@ void linsertCommand(client *c) {
539541
* the list twice (once to see if the value can be inserted and once
540542
* to do the actual insert), so we assume this value can be inserted
541543
* and convert the listpack to a regular list if necessary. */
544+
previous_element_number = listTypeLength(subject);
542545
listTypeTryConversionAppend(subject, c->argv, 4, 4, NULL, NULL);
543546

544547
/* Seek pivot from head to tail */
@@ -556,6 +559,8 @@ void linsertCommand(client *c) {
556559
signalModifiedKey(c, c->db, c->argv[1]);
557560
notifyKeyspaceEvent(NOTIFY_LIST, "linsert", c->argv[1], c->db->id);
558561
server.dirty++;
562+
current_element_number = previous_element_number + 1;
563+
updateBigKeyList(c->argv[1], previous_element_number, current_element_number, LIST_TYPE);
559564
} else {
560565
/* Notify client of a failed insert */
561566
addReplyLongLong(c, -1);

0 commit comments

Comments
 (0)