当前位置: 首页>>代码示例>>C#>>正文


C# RedisConnection.CreateTransaction方法代码示例

本文整理汇总了C#中BookSleeve.RedisConnection.CreateTransaction方法的典型用法代码示例。如果您正苦于以下问题:C# RedisConnection.CreateTransaction方法的具体用法?C# RedisConnection.CreateTransaction怎么用?C# RedisConnection.CreateTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BookSleeve.RedisConnection的用法示例。


在下文中一共展示了RedisConnection.CreateTransaction方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ManualIncr

        public async Task<long?> ManualIncr(RedisConnection connection, int db, string key)
        {
            var oldVal = await connection.Strings.GetInt64(db, key);
            var newVal = (oldVal ?? 0) + 1;
            using (var tran = connection.CreateTransaction())
            { // check hasn't changed

#pragma warning disable 4014
                tran.AddCondition(Condition.KeyEquals(db, key, oldVal));
                tran.Strings.Set(db, key, newVal);
#pragma warning restore 4014
                if (!await tran.Execute()) return null; // aborted
                return newVal;
            }    
        }
开发者ID:jorik041,项目名称:booksleeve-unofficial,代码行数:15,代码来源:Constraints.cs

示例2: TestMethod1

        public void TestMethod1()
        {
            using (RedisConnection connection = new RedisConnection("localhost"))
            {
                connection.Open();

                RedisTransaction transaction = connection.CreateTransaction();
                string key = DateTime.Now.ToString();
                transaction.Lists.AddFirst(1, key, "pankaj", createIfMissing: true);
                transaction.Execute();

                connection.Keys.Exists(1, key);

            }
        }
开发者ID:sharmapankaj2512,项目名称:ExpenseManager,代码行数:15,代码来源:UnitTest1.cs

示例3: Send

        static async Task<int> Send(RedisConnection conn, string idKey, int db, string channel, string data)
        {
            int attempts = 0;
            bool success;
            do
            {
                var oldId = await conn.Strings.GetInt64(db, idKey).SafeAwaitable().ConfigureAwait(false); // important: let this be nullable;
                // means "doesn't exist"
                var newId = (oldId ?? 0) + 1;
                var payload = Pack(newId, data);

                using (var tran = conn.CreateTransaction())
                {
                    var x0 = tran.AddCondition(Condition.KeyEquals(db, idKey, oldId)).SafeAwaitable();
                    var x1 = tran.Strings.Increment(db, idKey).SafeAwaitable();
                    var x2 = tran.Publish(channel, payload).SafeAwaitable();
                    success = await tran.Execute().SafeAwaitable().ConfigureAwait(false);

                    if (success)
                    {
                        // still expect all of these to get answers
                        await Task.WhenAll(x0, x1, x2);

                        Assert.IsTrue(x0.Result, "condition passed");
                        Assert.AreEqual(newId, x1.Result);
                    }
                    else
                    {
                        // can't say much about x0; could have got past that
                        Assert.IsTrue(await IsCancelled(x1));
                        Assert.IsTrue(await IsCancelled(x2));
                    }

                    attempts++;
                }
            } while (!success);
            return attempts;
        }
开发者ID:raycode,项目名称:booksleeve,代码行数:38,代码来源:Transactions.cs


注:本文中的BookSleeve.RedisConnection.CreateTransaction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。