Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
StackExchange.Redis简单C#示例_C#_Redis_Stackexchange.redis - Fatal编程技术网

StackExchange.Redis简单C#示例

StackExchange.Redis简单C#示例,c#,redis,stackexchange.redis,C#,Redis,Stackexchange.redis,我正在寻找一个非常简单的初学者C#应用程序,用于使用StackExchange.Redis 我在网上搜索并找到了 但这似乎不是一个快速启动的例子 我已在windows上使用安装redis 有人能帮我找到一个简单的C#应用程序,它连接redis服务器,设置并获取一些密钥。你可以在文件中找到C#示例 请参阅其上的以下代码: 使用(var muxer=ConnectionMultiplexer.Connect(“localhost,resolvedns=1”)) { muxer.preserveAn

我正在寻找一个非常简单的初学者C#应用程序,用于使用StackExchange.Redis 我在网上搜索并找到了

但这似乎不是一个快速启动的例子

我已在windows上使用安装redis

有人能帮我找到一个简单的C#应用程序,它连接redis服务器,设置并获取一些密钥。

你可以在文件中找到C#示例


请参阅其上的以下代码:

使用(var muxer=ConnectionMultiplexer.Connect(“localhost,resolvedns=1”))
{
muxer.preserveAncyOrder=preserveOrder;
RedisKey=“MBOA”;
var conn=muxer.GetDatabase();
Wait(conn.PingAsync());
操作非平凡=委托
{
线程等待(5);
};
var watch=Stopwatch.StartNew();

对于(int i=0;我想使用缓存还是状态服务器?您看过吗?我还建议您使用在SE.Redis之上构建的库,该库提供额外的功能,如标记机制、可插入序列化等。这是一个糟糕的示例-Redis对象是长期存在的,示例无法捕获that@Abr你是对的,所以我已经编辑并向代码示例添加了注释您的链接现在是404…什么是AsyncOpsQty?这是一个糟糕的示例,因为Connection Multiplexer对象是长寿命的!不应该以这种方式使用它。同意。这是一个大约在2015年左右的示例,当时我几乎第一次使用它。即使提供的示例也不存在您可以在答案中自由地发布一个好的示例:)您还忘记了增加最小工作线程池数。
using StackExchange.Redis;
...

ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
// ^^^ store and re-use this!!!

IDatabase db = redis.GetDatabase();
string value = "abcdefg";
db.StringSet("mykey", value);
...
string value = db.StringGet("mykey");
Console.WriteLine(value); // writes: "abcdefg"
 using (var muxer = ConnectionMultiplexer.Connect("localhost,resolvedns=1"))
        {
            muxer.PreserveAsyncOrder = preserveOrder;
            RedisKey key = "MBOA";
            var conn = muxer.GetDatabase();
            muxer.Wait(conn.PingAsync());

            Action<Task> nonTrivial = delegate
            {
                Thread.SpinWait(5);
            };
            var watch = Stopwatch.StartNew();
            for (int i = 0; i <= AsyncOpsQty; i++)
            {
                var t = conn.StringSetAsync(key, i);
                if (withContinuation) t.ContinueWith(nonTrivial);
            }
            int val = (int)muxer.Wait(conn.StringGetAsync(key));
            watch.Stop();

            Console.WriteLine("After {0}: {1}", AsyncOpsQty, val);
            Console.WriteLine("({3}, {4})\r\n{2}: Time for {0} ops: {1}ms; ops/s: {5}", AsyncOpsQty, watch.ElapsedMilliseconds, Me(),
                withContinuation ? "with continuation" : "no continuation", preserveOrder ? "preserve order" : "any order",
                AsyncOpsQty / watch.Elapsed.TotalSeconds);
        }