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


C# IDatabase.CreateTransaction方法代码示例

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


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

示例1: SetUp

        public void SetUp()
        {
            SetupEvent.WaitOne();

            database = CreateDatabase();

            if (storeType == StoreType.FileSystem)
                ((FileSystemDatabase) database).Start();
            else {
                ((MemoryDatabase)database).Start();
            }

            transaction = database.CreateTransaction();
        }
开发者ID:erpframework,项目名称:cloudb,代码行数:14,代码来源:ShardedDataTestBase.cs

示例2: ManualIncr

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

#pragma warning disable 4014
                tran.AddCondition(Condition.StringEqual(key, oldVal));
                tran.StringSetAsync(key, newVal);
#pragma warning restore 4014
                if (!await tran.ExecuteAsync()) return null; // aborted
                return newVal;
            }
        }
开发者ID:hongduo168,项目名称:StackExchange.Redis,代码行数:15,代码来源:Constraints.cs

示例3: LockedAction

        private static bool LockedAction(IDatabase db, string sessionID, string lockId, Action<ITransaction> action)
        {
            RedisKey keyLock = Tools.MakeLockKey(sessionID);
            Debug.Assert(!String.IsNullOrEmpty(lockId));

            var trans = db.CreateTransaction();
            trans.AddCondition(Condition.StringEqual(keyLock, lockId));
            action(trans);
            if (trans.Execute())
                return true;

            // failed
            var delta = (DateTime.Now - lockStart).TotalMilliseconds;
            Console.WriteLine("Lock {0} on key {1} held for {2} msec expired unexpectedly", lockId, sessionID, delta);
            return false;
        }
开发者ID:Jens-G,项目名称:Redis-Samples,代码行数:16,代码来源:Session.cs

示例4: RemoveServer

        public static void RemoveServer(IDatabase redis, string serverId)
        {
            var transaction = redis.CreateTransaction();

            transaction.SetRemoveAsync(
                RedisStorage.Prefix + "servers",
                serverId);

            transaction.KeyDeleteAsync(
                new RedisKey[]
                {
                    string.Format(RedisStorage.Prefix + "server:{0}", serverId),
                    string.Format(RedisStorage.Prefix + "server:{0}:queues", serverId)
                });

            transaction.Execute();
        }
开发者ID:xyting,项目名称:Hangfire.Redis.StackExchange,代码行数:17,代码来源:RedisConnection.cs

示例5: SyncGeneration

        private void SyncGeneration(IDatabase db)
        {
            var generationKey = CacheNamespace.GetGenerationKey();
            var serverGenerationValue = db.StringGet(generationKey);
            var serverGeneration = Convert.ToInt64(serverGenerationValue);
            var currentGeneration = CacheNamespace.GetGeneration();

            // Generation was cleared by someone else (shouldn't happen).
            if (serverGenerationValue.IsNullOrEmpty)
            {
                db.StringSetAsync(
                    key: generationKey,
                    value: currentGeneration,
                    // Only set if someone else doesn't jump in and set it first.
                    when: When.NotExists,
                    flags: CommandFlags.FireAndForget
                );

                log.InfoFormat("setting server generation ({0}) because it is empty", currentGeneration);
            }
            // Generation was lowered by someone else (shouldn't happen).
            else if (serverGeneration < CacheNamespace.GetGeneration())
            {
                var transaction = db.CreateTransaction();

                // Only set if someone else doesn't jump in and set it first.
                transaction.AddCondition(Condition.StringEqual(generationKey, serverGeneration));

                transaction.StringSetAsync(
                    key: generationKey,
                    value: CacheNamespace.GetGeneration(),
                    flags: CommandFlags.FireAndForget
                );

                // We don't need to worry about the result because we will
                // already retry if we can't sync the generation.
                transaction.ExecuteAsync(CommandFlags.FireAndForget);

                log.InfoFormat("syncing server generation (server={0}, current={1})", serverGeneration, currentGeneration); 
            }
            else
            {
                CacheNamespace.SetHigherGeneration(serverGeneration);

                log.InfoFormat("syncing server generation (server={0}, current={1})", serverGeneration, currentGeneration);
            }
        }
开发者ID:oskarn,项目名称:NHibernate.Caches.Redis,代码行数:47,代码来源:RedisCache.cs

示例6: Commit

 private static void Commit(IDatabase redis, Action<RedisWriteOnlyTransaction> action)
 {
     using (var transaction = new RedisWriteOnlyTransaction(redis.CreateTransaction()))
     {
         action(transaction);
         transaction.Commit();
     }
 }
开发者ID:xyting,项目名称:Hangfire.Redis.StackExchange,代码行数:8,代码来源:RedisWriteOnlyTransactionFacts.cs

示例7: Commit

 private void Commit(IDatabase connection, Action<RedisWriteOnlyTransaction> action)
 {
     using (var transaction = new RedisWriteOnlyTransaction(connection.CreateTransaction(), Redis.Storage.GetSubscribe(), Prefix))
     {
         action(transaction);
         transaction.Commit();
     }
 }
开发者ID:okusnadi,项目名称:Hangfire.Redis.StackExchange,代码行数:8,代码来源:RedisWriteOnlyTransactionFacts.cs

示例8: LockSession

        private static bool LockSession(IDatabase db, string sessionID, uint msec, out string lockId)
        {
            RedisKey keyLock = Tools.MakeLockKey(sessionID);

            lockId = Guid.NewGuid().ToString();

            var trans = db.CreateTransaction();
            trans.AddCondition(Condition.KeyNotExists(keyLock));
            trans.StringSetAsync(keyLock, lockId, TimeSpan.FromMilliseconds(msec));
            if( trans.Execute())
            {
                lockStart = DateTime.Now;
                //Console.WriteLine(" Aquired {0} on key {1}", lockId, keyLock);
                return true;
            }

            lockId = String.Empty;
            return false;
        }
开发者ID:Jens-G,项目名称:Redis-Samples,代码行数:19,代码来源:Session.cs

示例9: CreateTransaction

        private SystemTransaction CreateTransaction(IDatabase database, User user)
        {
            if (database == null)
                throw new InvalidOperationException("No database selected");

            // The commit version number of this transaction
            long transactionVersionNumber;
            lock (commitSyncRoot) {
                transactionVersionNumber = currentCommitVersion;
            }

            return new SystemTransaction(this, database.CreateTransaction(), transactionVersionNumber, user);
        }
开发者ID:ikvm,项目名称:deveelsql,代码行数:13,代码来源:DatabaseSession.cs

示例10: Save

        public override bool Save(object obj, Type objType, IDatabase redisDatabase, string id, PropertyInfo basePropertyInfo = null)
        {
            var listKey = new RedisKeyObject(basePropertyInfo, id);

            var trans = redisDatabase.CreateTransaction();
            foreach (var o in ((IEnumerable<RedisValue>) obj).ToArray())
            {
                trans.ListRemoveAsync(listKey.RedisKey, o);
                trans.ListLeftPushAsync(listKey.RedisKey, o);
            }
            trans.Execute();

            return true;
        }
开发者ID:DemgelOpenSource,项目名称:DemgelRedis,代码行数:14,代码来源:ListHandler.cs

示例11: CreateAdminSession

 protected virtual ISession CreateAdminSession(IDatabase database)
 {
     var user = database.Authenticate(AdminUserName, AdminPassword);
     var transaction = database.CreateTransaction(IsolationLevel.Serializable);
     return new Session(transaction, user);
 }
开发者ID:ArsenShnurkov,项目名称:deveeldb,代码行数:6,代码来源:ContextBasedTest.cs

示例12: RemoveServer

 public void RemoveServer(IDatabase redis, string serverId)
 {
     var transaction = redis.CreateTransaction();
     transaction.SetRemoveAsync(Prefix + "servers", serverId);
     transaction.KeyDeleteAsync(String.Format(Prefix + "server:{0}", serverId));
     transaction.KeyDeleteAsync(String.Format(Prefix + "server:{0}:queues", serverId));
     transaction.Execute();
 }
开发者ID:okusnadi,项目名称:Hangfire.Redis.StackExchange,代码行数:8,代码来源:RedisConnection.cs


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