Bulk create keys in Redis - ServiceStack C#

丶灬走出姿态 提交于 2019-12-12 02:22:59

问题


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

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"

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)

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

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

回答1:


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);

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.



来源:https://stackoverflow.com/questions/39513697/bulk-create-keys-in-redis-servicestack-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!