Redis在哈希中存储列表 [英] Redis storing list inside hash

查看:71
本文介绍了Redis在哈希中存储列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在redis中存储一些机器详细信息.由于有许多不同的机器,我打算使用以下结构

I have to store some machine details in redis. As there are many different machines i am planning to use the below structure

server1 => {name => s1, cpu=>80}
server2 => {name => s2, cpu=>40}

我需要针对关键 CPU 存储多个值.此外,我只需要维护针对 cpu 的值列表中的最后 10 个值

I need to store more than one value against the key CPU. Also i need to maintain only the last 10 values in the list of values against cpu

1) 如何根据哈希中的键存储列表?

1) How can i store a list against the key inside the hash?

2) 我读过关于 ltrim 的文章.但它接受一个密钥.如何对 server1 中的关键 CPU 执行 ltrim?

2) I read about ltrim. But it accepts a key. How can i do a ltrim for key cpu inside server1?

我正在使用绝地武士.

推荐答案

Redis 的数据结构不能嵌套在其他数据结构中,因此无法将 List 存储在 Hash 中.相反,对服务器的 CPU 值使用不同的键(例如 server1:cpu).

Redis' data structures cannot be nested inside other data structures, so storing a List inside a Hash is not possible. Instead, use different keys for your servers' CPU values (e.g. server1:cpu).

这篇关于Redis在哈希中存储列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆