问题
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