如何删除redis的hash结构中第一个域?
PHP中文网
PHP中文网 2017-04-24 09:12:30
0
3
716

例如:

user:1 name "zhangsan"
user:1 num "001"

user:2 name "lisi"
user:2 num "002"

user:3 name "wang"
user:3 num "003"

在不指定user:1的情况下删除第一条域user:1。
其实需求类似list中的lpop,但是还是现在需要hash这种数据结构来记录id。

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(3)
大家讲道理

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.

PHPzhong

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!