Redis 类型及其各自的优缺点 [英] Redis types and their respective pros and cons

查看:52
本文介绍了Redis 类型及其各自的优缺点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解 Redis 列表、集合和散列

I understand that Redis lists, sets, and hashes

每种类型的优缺点是什么,以及一个集合在哪里的例子在列表上使用,或在集合上使用散列等

what are the pros/cons of each type, and an example of where a set would be used over a list, or a hash over a set etc

推荐答案

你要考虑的主要事情是你将要求它进行什么样的操作......这比性能更重要.因为,如果一个操作不可用,它就不会工作.

The major thing you want to think about is what kind of operations you are going to be asking of it... This over than the performance. Because, if an operation is not available, it just won't work.

查看 Redis 命令文档,首先,确保可用的命令集在那里为你.我在这里使用的大多数推理在通用编程中也是相同的.例如,为什么要在 Python 中使用字典与列表.Redis 命令文档通常对操作使用 Big-O 表示法.大多数单独的查找、插入等都是 O(1),因此不同类型之间没有太大区别.我也没有发现其中每一个的存储空间有太大差异.

Look at the Redis commands documentation, first of all, and make sure the set of commands available are there for you. Most of the reasoning I am using here is the same in general purpose programming as well. For example, why you would use a dictionary vs. a list in Python. The Redis command documentation typically has the Big-O notation for the operations. Most individual lookups, inserts, etc. are O(1), so there isn't much difference across types. I haven't found much difference in terms of storage space for each of these, either.

这里还有很多其他原因,因为我说得比较笼统.这篇文章可能会扩展成一本书的一章!这不是一个简单的问题.

There are many other reasons here because I'm being rather general. This post could likely be expanded out to a chapter in a book! It's not a straightforward question.

哈希:这是为了如果您想通过键获取值.几乎就像键值存储中的键值存储.此外,您可以通过按名称设置子参数(例如,使用键地址"、出生日期"等)来做类似类"的事情

Hash: This is for if you want to grab values by keys. Almost like a key-value store in a key-value store. Also, you can do "class"-like things, by having subparameters by name (e.g., with keys "address", "date of birth", ...)

列表:基本上是一个没有钥匙的集合,它是一组东西,立即找到一个人并不是什么大不了的事.例如,您可能有一个用户参与的交易列表.

List: Basically a set without a key, it is a collection of things where finding an individual one instantly isn't a big deal. For example, you might have a list of transactions a user has been involved in.

设置:基本上是一个哈希,但没有价值.这是当你想知道这个东西是不是在一个集合中?"的时候.与列表不同,集合需要恒定的时间来确定某物是否是成员.此外,与列表不同,集合中的项目是唯一的.使用集合,您还可以进行交叉和其他集合操作.这不是你可以用哈希做的事情.例如,您希望通过执行 union .

Set: Basically a Hash, but has no value. This is for when you want to know "is this thing in a set or not?". Sets, unlike lists, take constant time to figure out if something is a member. Also, unlike lists, the items in the set are unique. With sets, you can also do intersections and other set stuff. This is not something you can do with Hashes. For example, you want to find all the users that bought stuff at your Italy office (one set), and all the users that bought stuff at your France office (another set), by doing a union .

Sorted Sets:类似于一个集合,但有额外的选项,涉及查找项目的范围或等级.

Sorted Sets: Like a set, but has additional options involving finding ranges or ranks of items.

这篇关于Redis 类型及其各自的优缺点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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