コード例 #1
0
 public IObservable <RedisResultInfo> Execute(
     RedisTargetInfo targetInfo, RedisCommandInfo commandInfo)
 {
     return(_clientAccessor.With(targetInfo, client =>
     {
         // TODO: async
         return client.Call(commandInfo.Name, commandInfo.Args);
     })
            .Select(data => RedisResultInfo.MapResult(
                        targetInfo,
                        commandInfo,
                        data))
            .Catch <RedisResultInfo, RedisException>(exception => Observable.Return(
                                                         new RedisResultInfo.Error(
                                                             targetInfo,
                                                             commandInfo,
                                                             exception))));
 }
コード例 #2
0
        public IObservable <RedisResultInfo> Execute(
            RedisTargetInfo targetInfo, RedisBatchInfo batchInfo)
        {
            return(_clientAccessor.With(targetInfo, client =>
            {
                return Observable.Create <RedisResultInfo>(observer =>
                {
                    foreach (var commandInfo in batchInfo.CommandInfos)
                    {
                        try
                        {
                            // TODO: async
                            var data = client.Call(commandInfo.Name, commandInfo.Args);

                            if (commandInfo.IsExec && batchInfo.IsTransaction)
                            {
                                observer.OnNext(
                                    RedisResultInfo.MapResult(
                                        targetInfo, batchInfo, commandInfo, data));
                            }
                            else
                            {
                                observer.OnNext(
                                    RedisResultInfo.MapResult(
                                        targetInfo, commandInfo, data));
                            }
                        }
                        catch (RedisException e)
                        {
                            observer.OnNext(new RedisResultInfo.Error(
                                                targetInfo, commandInfo, e));
                        }
                    }

                    observer.OnCompleted();
                    return Disposable.Empty;
                });
            }));
        }