The hash structure has no order, so you don’t know what the first item is. How did you delete the first item? The first item you think is just the first item in the order you inserted, but I’m sorry that hash does not Sort according to your insertion order, so even if you traverse the hash, you may not be able to get the result you want. If you want the traversal order to remain consistent with the insertion order, you can use list. Your needs can be realized through two structures. One list is used to maintain the collection order, and the other hash is used to save k-v data. When deleting, pop out a data from the list, and then delete it according to the key in the hash.
The hash structure has no order, so you don’t know what the first item is. How did you delete the first item? The first item you think is just the first item in the order you inserted, but I’m sorry that hash does not Sort according to your insertion order, so even if you traverse the hash, you may not be able to get the result you want.
If you want the traversal order to remain consistent with the insertion order, you can use list.
Your needs can be realized through two structures. One list is used to maintain the collection order, and the other hash is used to save k-v data. When deleting, pop out a data from the list, and then delete it according to the key in the hash.
Well, we can only use hKeys to retrieve all key values, then retrieve the first key at the application layer, and then hget and hdel at the same time
Hash linked list, //Delete a single entity
$redis->hDel('hashkey', 'key1');
//Delete the entire hash
$redis->del('hashkey');
To delete a redis key, use the del method. Whether it is string, hash, list, set, etc., it is the same. RPOP can also be taken out.