Created
December 1, 2022 03:10
-
-
Save guitarrapc/2ea0f7fbcb7096a127d2221eda5a17c1 to your computer and use it in GitHub Desktop.
StackExchange.Redis での KeyPrefix 付きの処理
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using StackExchange.Redis; | |
using StackExchange.Redis.KeyspaceIsolation; | |
var connectionStrings = "localhost:6379,ssl=false,password=password"; | |
var connection = ConnectionMultiplexer.Connect(connectionStrings); | |
// Prefix は DB に対してつけることで透過的に処理される | |
//var db = connection.GetDatabase(); // Prefix なし | |
//var db = connection.GetDatabase().WithKeyPrefix(""); // Prefix なしと同じ | |
var db = connection.GetDatabase().WithKeyPrefix("PREFIX:"); // Prefix あり | |
var random = Random.Shared.Next(); | |
db.StringSet($"foo-{random}", "bar"); | |
db.StringGet($"foo-{random}").Dump($"foo-{random}"); // PREFIX:foo-111 = bar で保存 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment