Redis
 sql >> Database >  >> NoSQL >> Redis

Transazioni digitate Redis

L'interfaccia Redis Transactions implementata dal client Redis C# di ServiceStack.

Introduzione #

L'interfaccia della transazione Redis fornisce utili overload che consentono di mettere in coda qualsiasi operazione IRedisTypedClient all'interno di una singola transazione. L'API fornisce supporto per una richiamata in modo da avere accesso anche a tutti i valori restituiti come parte della transazione.

Utilizzo #

Di seguito è riportato un semplice esempio che mostra come accedere, utilizzare e confermare la transazione.

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

    trans.Commit();
}

Per una transazione che opera su valori di stringa, vedere IRedisTransaction.

Dettagli #

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();
}