我正在创建一个 Redis(键值)数据库,我希望能够轻松更改表示数据存储方式的图表。 在此图中,我希望能够区分保存为 JSON 字符串的数据与实际上是哈希表、集合或有序集合的数据。
我试着用 excel 写一些东西,但它太像关系数据库了,我试着用 JSON 写,但很难分辨什么是 JSON 字符串的值,什么是哈希值。
是否有关于如何绘制此图表的行业标准?
编辑: 我最终编写了自己的语法,但仍然想知道这个问题的答案。
最佳答案
这是我为自己创建的语法:(这是我要制作的纸牌游戏的示例 Redis 结构:http://pastebin.com/4aRye4HQ)
key: = string
#key: = hash
$key: = set
$$key: = sortedSet
这是我用来对语法进行颜色编码的 Sublime 语法高亮文件(保存为 redis.YAML-tmLanguage ):
# [PackageDev] target_format: plist, ext: tmLanguage
---
name: Redis
scopeName: source.redis
fileTypes: []
uuid: 0033bdf9-cd9f-4147-bd2e-a9fed3d07e1e
patterns:
- include: '#erb'
- match: \#[A-Za-z][A-Za-z0-9_]+
name: variable.parameter
comment: Hashes
- match: \$[A-Za-z][A-Za-z0-9_]+
name: support.constant
comment: Sets
- match: \$\$[A-Za-z][A-Za-z0-9_]+
name: entity.name.class
comment: Sets
- match: \d+
name: constant.numeric
comment: Numbers
- name: constant.numeric.yaml
match: (?:(?:(-\s*)?(\w+\s*(:)))|(-))\s*((0(x|X)[0-9a-fA-F]*)|(([0-9]+\.?[0-9]*)|(\.[0-9]+))((e|E)(\+|-)?[0-9]+)?)(L|l|UL|ul|u|U|F|f)?\s*$
captures:
'1': {name: punctuation.definition.entry.yaml}
'2': {name: entity.name.tag.yaml}
'3': {name: punctuation.separator.key-value.yaml}
'4': {name: punctuation.definition.entry.yaml}
- name: string.unquoted.yaml
match: (?:(?:(-\s*)?(\w+\s*(:)))|(-))\s*(?:((")[^"]*("))|((')[^']*('))|([^,{}&#\[\]]+))\s*
captures:
'1': {name: punctuation.definition.entry.yaml}
'2': {name: entity.name.tag.yaml}
'3': {name: punctuation.separator.key-value.yaml}
'4': {name: punctuation.definition.entry.yaml}
'5': {name: string.quoted.double.yaml}
'6': {name: punctuation.definition.string.begin.yaml}
'7': {name: punctuation.definition.string.end.yaml}
'8': {name: string.quoted.single.yaml}
'9': {name: punctuation.definition.string.begin.yaml}
'10': {name: punctuation.definition.string.end.yaml}
'11': {name: string.unquoted.yaml}
- name: constant.other.date.yaml
match: (?:(?:(-\s*)?(\w+\s*(:)))|(-))\s*([0-9]{4}-[0-9]{2}-[0-9]{2})\s*$
captures:
'1': {name: punctuation.definition.entry.yaml}
'2': {name: entity.name.tag.yaml}
'3': {name: punctuation.separator.key-value.yaml}
'4': {name: punctuation.definition.entry.yaml}
- include: '#value'
repository:
array:
name: meta.structure.array.json
begin: \[
beginCaptures:
'0': {name: punctuation.definition.array.begin.json}
end: \]
endCaptures:
'0': {name: punctuation.definition.array.end.json}
patterns:
- include: '#value'
- name: punctuation.separator.array.json
match: ','
- name: invalid.illegal.expected-array-separator.json
match: '[^\s\]]'
comments:
patterns:
- name: comment.block.documentation.json
begin: /\*\*
end: \*/
captures:
'0': {name: punctuation.definition.comment.json}
- name: comment.block.json
begin: /\*
end: \*/
captures:
'0': {name: punctuation.definition.comment.json}
- name: comment.line.double-slash.js
match: (//).*$\n?
captures:
'1': {name: punctuation.definition.comment.json}
constant:
name: constant.language.json
match: \b(?:true|false|null)\b
number:
comment: handles integer and decimal numbers
name: constant.numeric.json
match: "(?x: # turn on extended mode\n\t\t\t -? #\
\ an optional minus\n\t\t\t (?:\n\t\t\t 0 #\
\ a zero\n\t\t\t | # ...or...\n\t\t\t [1-9]\
\ # a 1-9 character\n\t\t\t \\d* # followed by zero or\
\ more digits\n\t\t\t )\n\t\t\t (?:\n\t\t\t \
\ (?:\n\t\t\t \\. # a period\n\t\t\t \
\ \\d+ # followed by one or more digits\n\t\t\t )?\n\t\t\
\t (?:\n\t\t\t [eE] # an e character\n\t\t\t\
\ [+-]? # followed by an option +/-\n\t\t\t \
\ \\d+ # followed by one or more digits\n\t\t\t )? #\
\ make exponent optional\n\t\t\t )? # make decimal portion\
\ optional\n\t\t\t )"
object:
comment: a JSON object
name: meta.structure.dictionary.json
begin: \{
beginCaptures:
'0': {name: punctuation.definition.dictionary.begin.json}
end: \}
endCaptures:
'0': {name: punctuation.definition.dictionary.end.json}
patterns:
- comment: the JSON object key
include: '#string'
- include: '#comments'
- name: meta.structure.dictionary.value.json
begin: ':'
beginCaptures:
'0': {name: punctuation.separator.dictionary.key-value.json}
end: (,)|(?=\})
endCaptures:
'1': {name: punctuation.separator.dictionary.pair.json}
patterns:
- comment: the JSON object value
include: '#value'
- name: invalid.illegal.expected-dictionary-separator.json
match: '[^\s,]'
- name: invalid.illegal.expected-dictionary-separator.json
match: '[^\s\}]'
string:
name: string.quoted.double.json
begin: '"'
beginCaptures:
'0': {name: punctuation.definition.string.begin.json}
end: '"'
endCaptures:
'0': {name: punctuation.definition.string.end.json}
patterns:
- name: constant.character.escape.json
match: |-
(?x: # turn on extended mode
\\ # a literal backslash
(?: # ...followed by...
["\\/bfnrt] # one of these characters
| # ...or...
u # a u
[0-9a-fA-F]{4} # and four hex digits
)
)
- name: invalid.illegal.unrecognized-string-escape.json
match: \\.
value:
comment: "the 'value' diagram at http://json.org"
patterns:
- include: '#constant'
- include: '#number'
- include: '#string'
- include: '#array'
- include: '#object'
- include: '#comments'
foldingStartMarker: |-
(?x: # turn on extended mode
^ # a line beginning with
\s* # some optional space
[{\[] # the start of an object or array
(?! # but not followed by
.* # whatever
[}\]] # and the close of an object or array
,? # an optional comma
\s* # some optional space
$ # at the end of the line
)
| # ...or...
[{\[] # the start of an object or array
\s* # some optional space
$ # at the end of the line
)
foldingStopMarker: |-
(?x: # turn on extended mode
^ # a line beginning with
\s* # some optional space
[}\]] # and the close of an object or array
)
keyEquivalent: ^~J
...
关于redis - 绘制 redis(键值)数据结构图的标准方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29456468/
我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div
总的来说,我对ruby还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用
类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc
我正在尝试设置一个puppet节点,但rubygems似乎不正常。如果我通过它自己的二进制文件(/usr/lib/ruby/gems/1.8/gems/facter-1.5.8/bin/facter)在cli上运行facter,它工作正常,但如果我通过由rubygems(/usr/bin/facter)安装的二进制文件,它抛出:/usr/lib/ruby/1.8/facter/uptime.rb:11:undefinedmethod`get_uptime'forFacter::Util::Uptime:Module(NoMethodError)from/usr/lib/ruby
我有一个模型:classItem项目有一个属性“商店”基于存储的值,我希望Item对象对特定方法具有不同的行为。Rails中是否有针对此的通用设计模式?如果方法中没有大的if-else语句,这是如何干净利落地完成的? 最佳答案 通常通过Single-TableInheritance. 关于ruby-on-rails-Rails-子类化模型的设计模式是什么?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.co
我想将html转换为纯文本。不过,我不想只删除标签,我想智能地保留尽可能多的格式。为插入换行符标签,检测段落并格式化它们等。输入非常简单,通常是格式良好的html(不是整个文档,只是一堆内容,通常没有anchor或图像)。我可以将几个正则表达式放在一起,让我达到80%,但我认为可能有一些现有的解决方案更智能。 最佳答案 首先,不要尝试为此使用正则表达式。很有可能你会想出一个脆弱/脆弱的解决方案,它会随着HTML的变化而崩溃,或者很难管理和维护。您可以使用Nokogiri快速解析HTML并提取文本:require'nokogiri'h
我想了解Ruby方法methods()是如何工作的。我尝试使用“ruby方法”在Google上搜索,但这不是我需要的。我也看过ruby-doc.org,但我没有找到这种方法。你能详细解释一下它是如何工作的或者给我一个链接吗?更新我用methods()方法做了实验,得到了这样的结果:'labrat'代码classFirstdeffirst_instance_mymethodenddefself.first_class_mymethodendendclassSecond使用类#returnsavailablemethodslistforclassandancestorsputsSeco
我正在使用的第三方API的文档状态:"[O]urAPIonlyacceptspaddedBase64encodedstrings."什么是“填充的Base64编码字符串”以及如何在Ruby中生成它们。下面的代码是我第一次尝试创建转换为Base64的JSON格式数据。xa=Base64.encode64(a.to_json) 最佳答案 他们说的padding其实就是Base64本身的一部分。它是末尾的“=”和“==”。Base64将3个字节的数据包编码为4个编码字符。所以如果你的输入数据有长度n和n%3=1=>"=="末尾用于填充n%
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
为什么4.1%2返回0.0999999999999996?但是4.2%2==0.2。 最佳答案 参见此处:WhatEveryProgrammerShouldKnowAboutFloating-PointArithmetic实数是无限的。计算机使用的位数有限(今天是32位、64位)。因此计算机进行的浮点运算不能代表所有的实数。0.1是这些数字之一。请注意,这不是与Ruby相关的问题,而是与所有编程语言相关的问题,因为它来自计算机表示实数的方式。 关于ruby-为什么4.1%2使用Ruby返