在Redis中批量创建密钥-ServiceStack C# [英] Bulk create keys in Redis - ServiceStack C#

查看:279
本文介绍了在Redis中批量创建密钥-ServiceStack C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在" Redis ServiceStack客户端"中批量创建密钥(SETS)?当然,无需放置for循环.

Is there any way to bulk-create keys (SETS) in "Redis ServiceStack client"? Of course, without putting for loop.

Redis中有一个命令可以执行此操作: MSET ,但是我找不到任何实现 ServiceStack.Redis 客户端中此命令的内容.

There is one command in Redis which does this: MSET but, I couldn't find any implementation of this command in ServiceStack.Redis client.

Ex:

MSET key1 "val1" key2 "val2"

更新:
@mythz建议了一种创建多个SET的方法,但使用单个成员 SETALL().
此外,我找到了一种通过 AddRangeToSet(字符串setId,列表项)

UPDATE:
@mythz suggested a way to create multiple SETS but with single member SETALL().
Additionally, I found a way to bulk add members to a single set by AddRangeToSet(string setId, List items)

但是,在批量创建SETS时,有什么方法可以添加多个成员.

But, is there any way I can add multiple MEMBERS while bulk creating SETS. Something like

  XXXCOMMAND key1 "val11","val12","val13" key2 "val21","val22"

推荐答案

您可以在ServiceStack.Redis中使用SetValuesSetAll API,其中

You can use the SetValues or SetAll APIs in ServiceStack.Redis which batches all keys into a single MSET operation, e.g:

var map = new Dictionary<string,string> {
  {"key1","val1"},
  {"key2","val2"},
  {"key3","val3"},
};

redis.SetAll(map);

ServiceStack.Redis中收集集合的大多数操作是通过单个操作发送的,或者在管道中不存在的批量操作中发送,并作为单个Network write发送.

Most operations in ServiceStack.Redis that take a collection are sent in either a single operation or when it doesn't exist batched in a pipeline and sent as a single Network write.

这篇关于在Redis中批量创建密钥-ServiceStack C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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