Redis中的事务自动增量ID(ServiceStack RedisClient)(Autoincrement Id with transaction in Redis (ServiceStack RedisClient))

使用IncrementKey的ActionSuccess回调在事务中不起作用:

public class Article
{
    public long Id { get; set; }
    public string Name { get; set; }
}

[Test]
public void Can_create_article_with_autoincremental-id()
{
    Article a = new Article() { Name = "I Love Writing Test" };
    using (var trans = Redis.CreateTransaction())
    {
        trans.QueueCommand(r => r.IncrementValue("id:article"), id => a.Id = id);
        trans.QueueCommand(r => r.Store<Article>(a));

        trans.Commit();
    }

    Assert.That(Redis.Get<Article>("1").Id,Is.Equal("1"));
}

ActionSuccess callback with IncrementKey does not work in transaction:

public class Article
{
    public long Id { get; set; }
    public string Name { get; set; }
}

[Test]
public void Can_create_article_with_autoincremental-id()
{
    Article a = new Article() { Name = "I Love Writing Test" };
    using (var trans = Redis.CreateTransaction())
    {
        trans.QueueCommand(r => r.IncrementValue("id:article"), id => a.Id = id);
        trans.QueueCommand(r => r.Store<Article>(a));

        trans.Commit();
    }

    Assert.That(Redis.Get<Article>("1").Id,Is.Equal("1"));
}

原文:https://stackoverflow.com/questions/10907878
2023-08-30 07:08

满意答案

您可以将编码传递给Integer#chr

hex = 0x0905
hex.chr('UTF-8') #=> "अ"

如果Encoding::default_internal设置为UTF-8,则可以省略该参数:

$ ruby -E UTF-8:UTF-8 -e "p 0x0905.chr"
"अ"

您还可以将代码点附加到其他字符串:

'' << hex #=> "अ"

You can pass an encoding to Integer#chr:

hex = 0x0905
hex.chr('UTF-8') #=> "अ"

The parameter can be omitted, if Encoding::default_internal is set to UTF-8:

$ ruby -E UTF-8:UTF-8 -e "p 0x0905.chr"
"अ"

You can also append codepoints to other strings:

'' << hex #=> "अ"

相关问答

更多

将unicode转换为unicode转义语法(Convert unicode to unicode escape syntax)

>>> u"ÿ".encode('raw-unicode-escape') '\xff' r"\u%04X" % ord(u"ÿ") This did the trick for me. It returns a string object ('\\u00FF') which I can use to make a string compare. It fails for unicode characters above U+FFFF but this is not necessary in ...

是否可以在Java中动态生成Unicode字符?(Is it possible to dynamically generate Unicode characters in Java? [duplicate])

您可以简单地将代码点值转换为char : (char)0x2070 + x 请注意,您可能会考虑以十六进制表示的代码点值。 You can simply cast the codepoint value to a char: (char)0x2070 + x Note that you probably think about codepoint values in hex.

如何在Python中替换字符串中的无效unicode字符?(How to replace invalid unicode characters in a string in Python?)

如果您有一个bytestring (未解码的数据),请使用'replace'错误处理程序。 例如,如果您的数据(大部分)是UTF-8编码的,那么您可以使用: decoded_unicode = bytestring.decode('utf-8', 'replace') 和U + FFFD REPLACEMENT将为任何无法解码的字节插入字符字符。 如果您想使用不同的替换字符,以后可以轻松替换这些字符: decoded_unicode = decoded_unicode.replace(u'\uf...

如何将Unicode转义序列转换为Haskell中的Unicode字符串(How to convert Unicode Escape Sequence to Unicode String in Haskell)

Prelude> putStrLn“\ 3619 \ 3657 \ 3634 \ 3609 \ 3648 \ 3592 \ 3657 \ 3648 \ 3621 \ 3657 \ 3591” ร้านเจ้เล้ง 请注意,您实际上没有字符串"\3619\3657\3634\3609\3648\3592\3657\3648\3621\3657\3591" - 相反,您具有UTF-32字符串的ร้านเจ้เล้ง , "\3619\3657..."恰好是ASCII兼容文字。 默认情况下,GHCi使...

Javascript:存储访问unicode时,Unicode转义序列无效(Javascript: Invalid Unicode escape sequence while storing accessing unicode)

如果Unicode转义序列完全包含在单个字符串文字中,则它们只能被识别。 连接转义序列的部分将不起作用。 要从代码点动态创建字符串,请尝试String.fromCodePoint 。 该函数将代码点作为数字,而不是字符串。 // works console.log("\u0041"); // doesn't work try { eval('console.log("\\u" + "0041");'); } catch (e) { console.log(e.messag...

BigQuery - 查找unicode字符(BigQuery - finding unicode characters)

尝试下面 - for / with BigQuery Standard SQL #standardSQL SELECT col FROM `project.dataset.table` WHERE REGEXP_CONTAINS(path, '''[\u0020-\u007E]''') 想象一下,我想找到任何数据分数a包含unicode字符的记录。 #standardSQL WITH `project.dataset.table` AS ( SELECT 1 AS col, ['ab...

Ruby试图动态创建unicode字符串抛出“无效的Unicode转义”错误(Ruby trying to dynamically create unicode string throws “invalid Unicode escape” error)

您可以将编码传递给Integer#chr : hex = 0x0905 hex.chr('UTF-8') #=> "अ" 如果Encoding::default_internal设置为UTF-8,则可以省略该参数: $ ruby -E UTF-8:UTF-8 -e "p 0x0905.chr" "अ" 您还可以将代码点附加到其他字符串: '' << hex #=> "अ" You can pass an encoding to Integer#chr: hex = 0x0905 hex.ch...

以编程方式创建Unicode?(Programmatically Create Unicode?)

如果有疑问,请遵循Java库: scala> def hexStrToChar(hex: String): Char = Integer.parseInt(hex, 16).toChar hexStrToChar: (hex: String)Char scala> hexStrToChar("0021") res1: Char = ! When in doubt defer to the Java libs: scala> def hexStrToChar(hex: String): Char...

Ruby:unescape unicode字符串(Ruby: unescape unicode string)

你是从irb尝试它,还是用p输出字符串? String#inspect (从irb和p str调用)将unicode字符转换为\uxxxx格式,以允许在任何地方打印字符串。 此外,当您键入"CEO Frye \u2013 response to..." ,这是由ruby解析器解析的转义序列。 它是最终字符串中的unicode字符。 str1 = "a\u2013b" str1.size #=> 3 str2 = "a\\u2013b" str2.size #=> 8 unescape_unicod...

解析unicode JSON字符串(Parse unicode JSON string)

它不是有效的json s = "{'to': 1234, 'message': u'sample message', 'user': 65773722, 'msgId': 28198}" valid = s.replace("u'", "'") supervalid = v.replace("'", '"') json.loads(super_valid) it is not valid json s = "{'to': 1234, 'message': u'sample message', '...

相关文章

更多

Redis概述

什么是Redis Redis是Remote Dictionary Server的缩写, Redis是一 ...

基于window安装redis

1、下载redis的window版本 下载地址: https://github.com/Service ...

redis整合spring示例二—java操作redis(存对象及List)

在java操作redis中,咱们已经有了基本的java操作redis相关代码。下面继续 redis存放 ...

transaction.auto_close_session参数的问题

当hibernate设置采用JDBC事务,事务上下文设置为thread的时候,将transaction ...

redis整合spring示例一

这里使用java操作redis的示例,也是领悟书生网站项目中使用的代码.当然本示例也是参考网上的相关文 ...

redis sentinel(哨兵) 配置详解-redis集群管理

1. redis sentinel(哨兵) redis sentinel(哨兵)是对Redis系统的 ...

redis 使用笔记01

今天和张哥商量 准备将微信服务端 移植到4joy服务器上。首先一个问题就是解决人员列表缓存同步问题。 ...

redis新增集群节点-redis集群管理

新增一个节点6383,并启动 执行redis-trib.rb add-node命令添加节点 redi ...

redis 集群环境搭建-redis集群管理

集群架构 (1)所有的redis节点彼此互联(PING-PONG机制),内部使用二进制协议优化传输速度 ...

redis 字符串(String) SET 操作

命令格式: SET key value 把字符串值value存储到key中。如果存在此key,SE ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本