Redis
 sql >> база данни >  >> NoSQL >> Redis

Транзакции, въведени в Redis

Интерфейсът Redis Transactions, реализиран от C# Redis Client на ServiceStack.

Въведение №

Интерфейсът за транзакции на Redis предоставя полезни претоварвания, които ви позволяват да поставите в опашка всяка операция IRedisTypedClient в рамките на една транзакция. API осигурява поддръжка за обратно извикване, така че също така имате достъп до всички върнати стойности, върнати като част от транзакцията.

Използване №

По-долу е даден прост пример, показващ как да получите достъп, да използвате и да извършите транзакцията.

var typedClient = Redis.GetTypedClient<MyPocoType>();			
using (var trans = typedClient.CreateTransaction())
{
    trans.QueueCommand(r => r.Set("nosqldbs", new MyPocoType {Id = 1, Name = "Redis"));

    trans.Commit();
}

За транзакция, която работи с низови стойности, вижте IRedisTransaction.

Подробности #

public interface IRedisTypedTransaction<T> 
    : IDisposable
{
    void QueueCommand(Action<IRedisTypedClient<T>> command);
    void QueueCommand(Action<IRedisTypedClient<T>> command, Action onSuccessCallback);
    void QueueCommand(Action<IRedisTypedClient<T>> command, Action onSuccessCallback, Action<Exception> onErrorCallback);

    void QueueCommand(Func<IRedisTypedClient<T>, int> command);
    void QueueCommand(Func<IRedisTypedClient<T>, int> command, Action<int> onSuccessCallback);
    void QueueCommand(Func<IRedisTypedClient<T>, int> command, Action<int> onSuccessCallback, Action<Exception> onErrorCallback);

    void QueueCommand(Func<IRedisTypedClient<T>, bool> command);
    void QueueCommand(Func<IRedisTypedClient<T>, bool> command, Action<bool> onSuccessCallback);
    void QueueCommand(Func<IRedisTypedClient<T>, bool> command, Action<bool> onSuccessCallback, Action<Exception> onErrorCallback);

    void QueueCommand(Func<IRedisTypedClient<T>, double> command);
    void QueueCommand(Func<IRedisTypedClient<T>, double> command, Action<double> onSuccessCallback);
    void QueueCommand(Func<IRedisTypedClient<T>, double> command, Action<double> onSuccessCallback, Action<Exception> onErrorCallback);

    void QueueCommand(Func<IRedisTypedClient<T>, byte[]> command);
    void QueueCommand(Func<IRedisTypedClient<T>, byte[]> command, Action<byte[]> onSuccessCallback);
    void QueueCommand(Func<IRedisTypedClient<T>, byte[]> command, Action<byte[]> onSuccessCallback, Action<Exception> onErrorCallback);

    void QueueCommand(Func<IRedisTypedClient<T>, string> command);
    void QueueCommand(Func<IRedisTypedClient<T>, string> command, Action<string> onSuccessCallback);
    void QueueCommand(Func<IRedisTypedClient<T>, string> command, Action<string> onSuccessCallback, Action<Exception> onErrorCallback);

    void QueueCommand(Func<IRedisTypedClient<T>, T> command);
    void QueueCommand(Func<IRedisTypedClient<T>, T> command, Action<T> onSuccessCallback);
    void QueueCommand(Func<IRedisTypedClient<T>, T> command, Action<T> onSuccessCallback, Action<Exception> onErrorCallback);

    void QueueCommand(Func<IRedisTypedClient<T>, List<string>> command);
    void QueueCommand(Func<IRedisTypedClient<T>, List<string>> command, Action<List<string>> onSuccessCallback);
    void QueueCommand(Func<IRedisTypedClient<T>, List<string>> command, Action<List<string>> onSuccessCallback, Action<Exception> onErrorCallback);

    void QueueCommand(Func<IRedisTypedClient<T>, List<T>> command);
    void QueueCommand(Func<IRedisTypedClient<T>, List<T>> command, Action<List<T>> onSuccessCallback);
    void QueueCommand(Func<IRedisTypedClient<T>, List<T>> command, Action<List<T>> onSuccessCallback, Action<Exception> onErrorCallback);

    void Commit();
    void Rollback();
}

  1. Redis
  2.   
  3. MongoDB
  4.   
  5. Memcached
  6.   
  7. HBase
  8.   
  9. CouchDB
  1. Как да разбера дали sidekiq е свързан към Redis сървър?

  2. Stackexchange.Redis стреля и забравя ли гарантира доставката?

  3. Уведомления за ключовото пространство на Redis със StackExchange.Redis

  4. Redis задава TTL на клавишите hSet

  5. Yii2 + Redis като база данни