首页 \ 问答 \ Redis SELECT性能(Redis SELECT performance)

Redis SELECT性能(Redis SELECT performance)

我正在使用带有多个数据库的redis(我通过SELECT命令切换)。

我将不同类型的信息存储到redis中,我需要以某种方式将其分开。 我不喜欢在密钥的前面添加信息类型,因此我创建了更多的数据库。

我想问一下这是一个正确的决定,关注绩效吗?

SELECT还会产生多少开销? 如果我需要从两个数据库中遍历一些相关数据,哪种方法更好(参见伪代码)?

for data in array {
  redis_select(0)
  k = redis_get(...)
  redis_select(1)
  k2 = redis_get(k)
}

要么

redis_select(0)
k = []
for data in array {
  k[x] = redis_get(...)
}

redis_select(1)
k2 = []
for data in array {
  k2[x] = redis_get(k[x])
}

I am using redis with multiple databases (which I switch by the SELECT command).

I am storing different types of information into redis and I needed to seperate it somehow. I didn't like to prefix the keys to distniguish the information type so I created more databases.

I would like to ask if it was a right decission, with concern for performance ?

Also how much overhead does SELECT cause ? If I need to traverse some related data from say two databases, which aproach is better (see pseudo code) ?

for data in array {
  redis_select(0)
  k = redis_get(...)
  redis_select(1)
  k2 = redis_get(k)
}

or

redis_select(0)
k = []
for data in array {
  k[x] = redis_get(...)
}

redis_select(1)
k2 = []
for data in array {
  k2[x] = redis_get(k[x])
}

原文:https://stackoverflow.com/questions/8805004
更新时间:2022-10-06 18:10

最满意答案

你需要括号:

(4).__str__()

问题是词法学家认为“4.” 将是一个浮点数。

此外,这样做:

x = 4
x.__str__()

So you think you can  dance  floating-point?

123 is just as much of an object as 3.14, the "problem" lies within the grammar rules of the language; the parser thinks we are about to define a float — not an int with a trailing method call.

We will get the expected behavior if we wrap the number in parenthesis, as in the below.

>>> (123).__str__()
'123'

Or if we simply add some whitespace after 123:

>>> 123 .__str__()
'123'


The reason it does not work for 123.__str__() is that the dot following the 123 is interpreted as the decimal-point of some partially declared floating-point.

>>> 123.__str__()
  File "", line 1
    123.__str__()
              ^
SyntaxError: invalid syntax

The parser tries to interpret __str__() as a sequence of digits, but obviously fails — and we get a SyntaxError basically saying that the parser stumbled upon something that it did not expect.



Elaboration

When looking at 123.__str__() the python parser could use either 3 characters and interpret these 3 characters as an integer, or it could use 4 characters and interpret these as the start of a floating-point.

123.__str__()
^^^ - int
123.__str__()
^^^^- start of floating-point

Just as a little child would like as much cake as possible on their plate, the parser is greedy and would like to swallow as much as it can all at once — even if this isn't always the best of ideas —as such the latter ("better") alternative is chosen.

When it later realizes that __str__() can in no way be interpreted as the decimals of a floating-point it is already too late; SyntaxError.

Note

 123 .__str__() # works fine

In the above snippet, 123  (note the space) must be interpreted as an integer since no number can contain spaces. This means that it is semantically equivalent to (123).__str__().

Note

 123..__str__() # works fine

The above also works because a number can contain at most one decimal-point, meaning that it is equivalent to (123.).__str__().



For the language-lawyers

This section contains the lexical definition of the relevant literals.

Lexical analysis - 2.4.5 Floating point literals

floatnumber   ::=  pointfloat | exponentfloat
pointfloat    ::=  [intpart] fraction | intpart "."
exponentfloat ::=  (intpart | pointfloat) exponent
intpart       ::=  digit+
fraction      ::=  "." digit+
exponent      ::=  ("e" | "E") ["+" | "-"] digit+

Lexical analysis - 2.4.4 Integer literals

integer        ::=  decimalinteger | octinteger | hexinteger | bininteger
decimalinteger ::=  nonzerodigit digit* | "0"+
nonzerodigit   ::=  "1"..."9"
digit          ::=  "0"..."9"
octinteger     ::=  "0" ("o" | "O") octdigit+
hexinteger     ::=  "0" ("x" | "X") hexdigit+
bininteger     ::=  "0" ("b" | "B") bindigit+
octdigit       ::=  "0"..."7"
hexdigit       ::=  digit | "a"..."f" | "A"..."F"
bindigit       ::=  "0" | "1"

相关问答

更多
  • 基本问题:您需要指定数组的类型。 这是使用Gson中的TypeToken完成的。 我希望这有帮助: val listType = object : TypeToken>() {}.type val json = """["1"]""" val yourClassList :Array = Gson().fromJson(json, listType) print(yourClassList) 请注意,对于基元,它更简单: Gson().fromJson(jso ...
  • 根据定义,复合文字不包含& address-of运算符。 来自N1570 6.5.2.5/p3 复合文字 : 后缀表达式由带括号的类型名称后跟括号括起的初始值设定项列表组成,是一个复合文字 。 现在,他们的声明: 标量类型和联合类型的复合文字也是允许的,但是复合文字等同于强制转换。 如果我正确阅读它是错误的。 复合文字和强制算子之间的根本区别在于前者是左值 ,如N1570 6.5.2.5/p4 (强调我的): 否则(当类型名称指定对象类型时),复合文字的类型是由类型名称指定的类型。 在任何一种情况下, 结果 ...
  • 你需要括号: (4).__str__() 问题是词法学家认为“4.” 将是一个浮点数。 此外,这样做: x = 4 x.__str__() So you think you can dance floating-point? 123 is just as much of an object as 3.14, the "problem" lies within the grammar rules of the language; the parser thinks we are about to defi ...
  • 如此处所述。 以下方法仅适用于包含方法的类的实例(所谓的描述符类)出现在所有者类中时(描述符必须位于所有者的类字典或父类之一的类字典中)。 As stated here. The following methods only apply when an instance of the class containing the method (a so-called descriptor class) appears in an owner class (the descriptor must be in e ...
  • 使用内联 : let inline sum a b = a + b 更新: 如果你有兴趣编写你自己的多态数值函数,你应该使用inline和LanguagePrimitives模块。 这里是从线程转换Haskell多态余弦函数到F#的多态余弦函数 : let inline cosine n (x: ^a) = let one: ^a = LanguagePrimitives.GenericOne Seq.initInfinite(fun i -> LanguagePrimitives.Di ...
  • 答案是肯定的。 知道这一点足够聪明。 这是一个简单程序的拆卸IL( ILSpy提供 ),它具有这样一个任务。 正如您从ldc.r4指令中看到的那样 ,不会发生转换: .method private hidebysig static void Main ( string[] args ) cil managed { // Method begins at RVA 0x2050 // Code size 8 (0x8) .maxstack 1 ...
  • 十进制整数文字是第一种类型,可以用int , long或long long 。 50是int类型。 可以使用u或U后缀指定无符号文字。 后缀为u或U十进制整数字是第一种类型,可以用unsigned int , unsigned long或unsigned long long 。 50U的类型为unsigned int 。 A decimal integer literal is of the first type where it can be represented in int, long or lon ...
  • 您应该始终明确指出您打算使用的文字类型。 例如,当这种代码时,这将防止出现问题: float foo = 9.0f; float bar = foo / 2; 更改以下内容,截断结果: int foo = 9; float bar = foo / 2; 当您涉及重载和模板时,这也是函数参数的一个问题。 我知道gcc有-Wconversion但我不记得它涵盖的一切。 对于适合int整数值,我通常不会对那些long或unsigned值进行限定,因为通常存在更少的微小错误。 You should always ...
  • 看来,就你的第一个结果而言,VC ++仍然遵循C89 / 90的规则,其中说(第6.1.3.2节): 整数常量的类型是相应列表中可以表示其值的第一个。 unsuffixed decimal: int , long int , unsigned long int ; [...] 因此,由于4294967295可以表示为unsigned long int ,因此它正在使用它。 在C ++ 98/03中,仍然允许这样做,但不再需要 - 您使用的值大于可以在long int表示的值,这会给出未定义的行为(第2.13 ...
  • 如果不进行强制转换,则无法将具有较高容量的类型的值分配给较低容量的类型。 long可以存储更大的数字,因此无法分配给int 。 You cannot assign a value of a type with higher capacity to a type of lower capacity without casting. long can store larger numbers, so it can't be assigned to int.

相关文章

更多

最新问答

更多
  • 如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
  • linux的常用命令干什么用的
  • 由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
  • 如何交换返回集中的行?(How to swap rows in a return set?)
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • 使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
  • Java中的不可变类(Immutable class in Java)
  • WordPress发布查询(WordPress post query)
  • 如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
  • 是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
  • GEP分段错误LLVM C ++ API(GEP segmentation fault LLVM C++ API)
  • 绑定属性设置器未被调用(Bound Property Setter not getting Called)
  • linux ubuntu14.04版没有那个文件或目录
  • 如何使用JSF EL表达式在param中迭代变量(How to iterate over variable in param using JSF EL expression)
  • 是否有可能在WPF中的一个单独的进程中隔离一些控件?(Is it possible to isolate some controls in a separate process in WPF?)
  • 使用Python 2.7的MSI安装的默认安装目录是什么?(What is the default installation directory with an MSI install of Python 2.7?)
  • 寻求多次出现的表达式(Seeking for more than one occurrence of an expression)
  • ckeditor config.protectedSource不适用于editor.insertHtml上的html元素属性(ckeditor config.protectedSource dont work for html element attributes on editor.insertHtml)
  • linux只知道文件名,不知道在哪个目录,怎么找到文件所在目录
  • Actionscript:检查字符串是否包含域或子域(Actionscript: check if string contains domain or subdomain)
  • 将CouchDB与AJAX一起使用是否安全?(Is it safe to use CouchDB with AJAX?)
  • 懒惰地初始化AutoMapper(Lazily initializing AutoMapper)
  • 使用hasclass为多个div与一个按钮问题(using hasclass for multiple divs with one button Problems)
  • Windows Phone 7:检查资源是否存在(Windows Phone 7: Check If Resource Exists)
  • 无法在新线程中从FREContext调用getActivity()?(Can't call getActivity() from FREContext in a new thread?)
  • 在Alpine上升级到postgres96(/ usr / bin / pg_dump:没有这样的文件或目录)(Upgrade to postgres96 on Alpine (/usr/bin/pg_dump: No such file or directory))
  • 如何按部门显示报告(How to display a report by Department wise)
  • Facebook墙贴在需要访问令牌密钥后无法正常工作(Facebook wall post not working after access token key required)
  • Javascript - 如何在不擦除输入的情况下更改标签的innerText(Javascript - how to change innerText of label while not wiping out the input)
  • WooCommerce / WordPress - 不显示具有特定标题的产品(WooCommerce/WordPress - Products with specific titles are not displayed)