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
满意答案
你需要括号:
(4).__str__()
问题是词法学家认为“4.” 将是一个浮点数。
此外,这样做:
x = 4 x.__str__()
So you think you can
dancefloating-point?
123
is just as much of an object as3.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 the123
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"
相关问答
更多Kotlin数组类型和类文字(Kotlin array types and class literals)
标量类型的复合文字(Compound literals for scalar types)
访问文字上的属性适用于所有类型,但不是`int`;(Accessing attributes on literals work on all types, but not `int`; why? [duplicate])
Python,将类变量设置为int值不是int类型[duplicate](Python, set class variable to int value not int type [duplicate])
使函数适用于所有数字类型(int,float,long)(make function work with all numeric types (int, float, long))
C#对Int32文字浮动的性能损失(C# Performance penalty for Int32 literals to floats)
整数文字是否被认为是未签名的?(Are integer literals considered unsigned? [duplicate])
我应该总是使用适当的文字来表示数字类型吗?(Should I always use the appropriate literals for number types?)
VC ++中的文字类型(Literals types in VC++)
整数文字(Integer literals)
相关文章
更多Redis概述
Struts2标签select的使用
redis sentinel(哨兵) 配置详解-redis集群管理
Solr Performance Factors(Solr 性能因素)
Redis Cookbook
Select2在Bootstrap 3 Modal框中不能搜索的解决方法
redis 集群使用主从复制架构-redis集群管理
Redis配置文件详解
redis安装-redis集群管理
对比下HBase, Memcached, MongoDB, Redis和Solr
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!