@@ -284,12 +284,6 @@ int hashTypeExpireEntry(void *entry) {
284284 }
285285 hashTypePropagateDeletion (server .access_context .db , key , entry );
286286 decrRefCount (keyobj );
287- return 1 ;
288- }
289-
290- int hashTypeExpireRemoveEntry (void * entry ) {
291- serverAssert (server .access_context .key && server .access_context .db );
292- hashTypeExpireEntry (entry );
293287 return hashTypeDelete (server .access_context .key , (sds )entry );
294288}
295289
@@ -301,55 +295,7 @@ hashtableElementAccessState hashHashtableTypeAccess(hashtable *ht, void *entry)
301295
302296 if ((server .access_context .flags & OBJ_ACCESS_IGNORE_TTL ) || !hashTypeEntryIsExpired (entry )) return ELEMENT_VALID ;
303297
304- if (!delete_expired ) return ELEMENT_INVALID ;
305-
306- if (server .access_context .flags == OBJ_ACCESS_NONE ) return ELEMENT_INVALID ;
307-
308- /* From this point we will be deleting the entry */
309- server .access_context .expired ++ ;
310- robj * o = server .access_context .val ;
311- serverDb * db = server .access_context .db ;
312-
313- serverAssert (o && db );
314-
315- hashTypeUntrackEntry (o , entry );
316- hashTypeExpireEntry (entry );
317- return ELEMENT_DELETE ;
318- }
319-
320- void hashTypeSetAccessContext (robj * key , robj * val , serverDb * db ) {
321- setAccessContext (key , val , db );
322- }
323-
324- void hashTypeResetAccessContext (void ) {
325- robj * keyobj = server .access_context .key ;
326- robj * o = server .access_context .val ;
327- serverDb * db = server .access_context .db ;
328- serverAssert (!o || o -> type == OBJ_HASH );
329- uint64_t num_expired = server .access_context .expired ;
330- resetAccessContext ();
331- if (o ) {
332- int is_empty = hashTypeLength (o ) == 0 ;
333- if (is_empty || num_expired ) {
334- /* We need to report key changes and notifications. for that we need to make sure we have the key object */
335- if (!keyobj ) {
336- sds key = objectGetKey (o );
337- keyobj = createStringObject (key , sdslen (key ));
338- } else {
339- incrRefCount (keyobj );
340- }
341- /* In case we have some entries which are expired we need to report it */
342- if (num_expired )
343- notifyKeyspaceEvent (NOTIFY_EXPIRED , "hexpired" , keyobj , db -> id );
344- /* In casethe object was left empty, we need to make sure to delete it (we do not support zero size hashes) */
345- if (is_empty ) {
346- notifyKeyspaceEvent (NOTIFY_GENERIC , "del" , keyobj , db -> id );
347- dbDelete (db , keyobj );
348- }
349- signalModifiedKey (server .current_client , db , keyobj );
350- decrRefCount (keyobj );
351- }
352- }
298+ return ELEMENT_INVALID ;
353299}
354300
355301/*-----------------------------------------------------------------------------
@@ -1081,12 +1027,10 @@ void hincrbyCommand(client *c) {
10811027
10821028 if (getLongLongFromObjectOrReply (c , c -> argv [3 ], & incr , NULL ) != C_OK ) return ;
10831029 if ((o = hashTypeLookupWriteOrCreate (c , c -> argv [1 ])) == NULL ) return ;
1084- hashTypeSetAccessContext (c -> argv [1 ], o , c -> db );
10851030 if (hashTypeGetValue (o , c -> argv [2 ]-> ptr , & vstr , & vlen , & value ) == C_OK ) {
10861031 if (vstr ) {
10871032 if (string2ll ((char * )vstr , vlen , & value ) == 0 ) {
10881033 addReplyError (c , "hash value is not an integer" );
1089- hashTypeResetAccessContext ();
10901034 return ;
10911035 }
10921036 } /* Else hashTypeGetValue() already stored it into &value */
@@ -1098,7 +1042,6 @@ void hincrbyCommand(client *c) {
10981042 if ((incr < 0 && oldvalue < 0 && incr < (LLONG_MIN - oldvalue )) ||
10991043 (incr > 0 && oldvalue > 0 && incr > (LLONG_MAX - oldvalue ))) {
11001044 addReplyError (c , "increment or decrement would overflow" );
1101- hashTypeResetAccessContext ();
11021045 return ;
11031046 }
11041047 value += incr ;
@@ -1108,7 +1051,6 @@ void hincrbyCommand(client *c) {
11081051 notifyKeyspaceEvent (NOTIFY_HASH , "hincrby" , c -> argv [1 ], c -> db -> id );
11091052 server .dirty ++ ;
11101053 addReplyLongLong (c , value );
1111- hashTypeResetAccessContext ();
11121054}
11131055
11141056void hincrbyfloatCommand (client * c ) {
@@ -1130,7 +1072,6 @@ void hincrbyfloatCommand(client *c) {
11301072 if (vstr ) {
11311073 if (string2ld ((char * )vstr , vlen , & value ) == 0 ) {
11321074 addReplyError (c , "hash value is not a float" );
1133- hashTypeResetAccessContext ();
11341075 return ;
11351076 }
11361077 } else {
@@ -1143,7 +1084,6 @@ void hincrbyfloatCommand(client *c) {
11431084 value += incr ;
11441085 if (isnan (value ) || isinf (value )) {
11451086 addReplyError (c , "increment would produce NaN or Infinity" );
1146- hashTypeResetAccessContext ();
11471087 return ;
11481088 }
11491089
@@ -1164,7 +1104,6 @@ void hincrbyfloatCommand(client *c) {
11641104 rewriteClientCommandArgument (c , 0 , shared .hset );
11651105 rewriteClientCommandArgument (c , 3 , newobj );
11661106 decrRefCount (newobj );
1167- hashTypeResetAccessContext ();
11681107}
11691108
11701109static void addHashFieldToReply (client * c , robj * o , sds field ) {
@@ -1193,8 +1132,6 @@ void hgetCommand(client *c) {
11931132
11941133 if ((o = lookupKeyReadOrReply (c , c -> argv [1 ], shared .null [c -> resp ])) == NULL || checkType (c , o , OBJ_HASH )) return ;
11951134 addHashFieldToReply (c , o , c -> argv [2 ]-> ptr );
1196-
1197- hashTypeResetAccessContext ();
11981135}
11991136
12001137void hmgetCommand (client * c ) {
@@ -1207,8 +1144,6 @@ void hmgetCommand(client *c) {
12071144
12081145 if (checkType (c , o , OBJ_HASH )) return ;
12091146
1210- hashTypeSetAccessContext (c -> argv [1 ], o , c -> db );
1211-
12121147 addReplyArrayLen (c , c -> argc - 2 );
12131148 for (i = 2 ; i < c -> argc ; i ++ ) {
12141149 addHashFieldToReply (c , o , c -> argv [i ]-> ptr );
@@ -1220,23 +1155,25 @@ void hmgetCommand(client *c) {
12201155
12211156void hdelCommand (client * c ) {
12221157 robj * o ;
1223- int j , deleted = 0 ;
1158+ int j , deleted = 0 , keyremoved = 0 ;
12241159
12251160 if ((o = lookupKeyWriteOrReply (c , c -> argv [1 ], shared .czero )) == NULL || checkType (c , o , OBJ_HASH )) return ;
12261161 for (j = 2 ; j < c -> argc ; j ++ ) {
12271162 if (hashTypeDelete (o , c -> argv [j ]-> ptr )) {
12281163 deleted ++ ;
12291164 if (hashTypeLength (o ) == 0 ) {
1165+ dbDelete (c -> db , c -> argv [1 ]);
1166+ keyremoved = 1 ;
12301167 break ;
12311168 }
12321169 }
12331170 }
12341171 if (deleted ) {
12351172 signalModifiedKey (c , c -> db , c -> argv [1 ]);
12361173 notifyKeyspaceEvent (NOTIFY_HASH , "hdel" , c -> argv [1 ], c -> db -> id );
1174+ if (keyremoved ) notifyKeyspaceEvent (NOTIFY_GENERIC , "del" , c -> argv [1 ], c -> db -> id );
12371175 server .dirty += deleted ;
12381176 }
1239- hashTypeResetAccessContext ();
12401177 addReplyLongLong (c , deleted );
12411178}
12421179
@@ -1252,9 +1189,7 @@ void hstrlenCommand(client *c) {
12521189 robj * o ;
12531190
12541191 if ((o = lookupKeyReadOrReply (c , c -> argv [1 ], shared .czero )) == NULL || checkType (c , o , OBJ_HASH )) return ;
1255- hashTypeSetAccessContext (c -> argv [1 ], o , c -> db );
12561192 addReplyLongLong (c , hashTypeGetValueLength (o , c -> argv [2 ]-> ptr ));
1257- hashTypeResetAccessContext ();
12581193}
12591194
12601195static void addHashIteratorCursorToReply (writePreparedClient * wpc , hashTypeIterator * hi , int what ) {
@@ -1594,7 +1529,6 @@ void hexistsCommand(client *c) {
15941529 robj * o ;
15951530 if ((o = lookupKeyReadOrReply (c , c -> argv [1 ], shared .czero )) == NULL || checkType (c , o , OBJ_HASH )) return ;
15961531 addReply (c , hashTypeExists (o , c -> argv [2 ]-> ptr ) ? shared .cone : shared .czero );
1597- hashTypeResetAccessContext ();
15981532}
15991533
16001534void hscanCommand (client * c ) {
0 commit comments