コード例 #1
0
        public void Read(AerospikeClient client, BatchPolicy policy, string ns, string set, string accountId)
        {
            Record record = client.Join(policy,
                                        new Key(ns, set, accountId),
                                        new Join("tickers", ns, set));

            if (record == null)
            {
                throw new Exception("Failed to read: " + accountId);
            }

            this.accountId = accountId;
            byte[]   positionsBytes = (byte[])record.GetValue("positions");
            Record[] records        = (Record[])record.GetValue("tickers");

            if (positionsBytes != null)
            {
                MemoryStream ms     = new MemoryStream(positionsBytes);
                BinaryReader reader = new BinaryReader(ms);
                int          count  = reader.ReadInt32();
                positions = new List <Position>(count);

                for (int i = 0; i < count; i++)
                {
                    positions.Add(new Position(reader, records[i]));
                }
            }
            else
            {
                positions = new List <Position>(0);
            }
        }
コード例 #2
0
        public void Initialize()
        {
            predAEq1BPolicy = new BatchPolicy();
            predAEq1RPolicy = new Policy();
            predAEq1WPolicy = new WritePolicy();

            predAEq1BPolicy.SetPredExp(
                PredExp.IntegerBin(binAName),
                PredExp.IntegerValue(1),
                PredExp.IntegerEqual());

            predAEq1RPolicy.SetPredExp(
                PredExp.IntegerBin(binAName),
                PredExp.IntegerValue(1),
                PredExp.IntegerEqual());

            predAEq1WPolicy.SetPredExp(
                PredExp.IntegerBin(binAName),
                PredExp.IntegerValue(1),
                PredExp.IntegerEqual());

            client.Delete(null, keyA);
            client.Delete(null, keyB);

            client.Put(null, keyA, binA1);
            client.Put(null, keyB, binA2);
        }
コード例 #3
0
        public static void Main(string[] args)
        {
            var client      = Connect();
            var policy      = new Policy();
            var writePolicy = new WritePolicy();
            var batchPolicy = new BatchPolicy();

            //NOTE: adjust the timeout value depending on your demo machine
            writePolicy.timeout = 1000;
            var key = new Key("test", "myset", "mykey");

            WriteSingleValue(client, writePolicy, key);
            CheckKeyExists(client, policy, key);
            AddSingleValue(client, writePolicy);
            WriteMultipleValues(client, writePolicy, key);
            WriteValueWithTtl(client);

            ReadAllValuesForKey(client, policy, key);
            ReadSomeValuesForKey(client, policy, key);

            DeleteValue(client, writePolicy, key);
            DeleteRecord(client, writePolicy, key);

            AddRecords(client, writePolicy);
            BatchReadRecords(client, batchPolicy);

            MultiOps(client, writePolicy, key);

            client.Close();
        }
コード例 #4
0
 /// <summary>
 /// Copy batch policy from another batch policy.
 /// </summary>
 public BatchPolicy(BatchPolicy other)
     : base(other)
 {
     this.maxConcurrentThreads = other.maxConcurrentThreads;
     this.useBatchDirect       = other.useBatchDirect;
     this.allowInline          = other.allowInline;
     this.allowProleReads      = other.allowProleReads;
 }
コード例 #5
0
 /// <summary>
 /// Copy batch policy from another batch policy.
 /// </summary>
 public BatchPolicy(BatchPolicy other)
     : base(other)
 {
     this.maxConcurrentThreads = other.maxConcurrentThreads;
     this.allowInline          = other.allowInline;
     this.allowProleReads      = other.allowProleReads;
     this.sendSetName          = other.sendSetName;
 }
コード例 #6
0
        private static void BatchReadRecords(AerospikeClient client, BatchPolicy batchPolicy)
        {
            Console.WriteLine("Batch Reads");
            const int size = 1024;
            var       keys = new Key[size];

            for (var i = 0; i < keys.Length; i++)
            {
                keys[i] = new Key("test", "myset", (i + 1));
            }
            var records = client.Get(batchPolicy, keys);

            Console.WriteLine("Read " + records.Length + " records");
        }
コード例 #7
0
        public async Task Init(CancellationToken cancellationToken)
        {
            _logger.LogInformation($"Init host={_options.Host} port={_options.Port} ns:{_options.Namespace} serializer={_aerospikeSerializer.GetType().Name}");

            _clientPolicy = new AsyncClientPolicy()
            {
                user     = _options.Username,
                password = _options.Password
            };

            _readPolicy = new BatchPolicy(_clientPolicy.batchPolicyDefault)
            {
                sendKey = true
            };

            _writeStatePolicy = new WritePolicy(_clientPolicy.writePolicyDefault)
            {
                recordExistsAction = RecordExistsAction.REPLACE,
                sendKey            = true
            };

            Log.SetLevel(Log.Level.INFO);
            Log.SetCallback((level, message) =>
            {
                LogLevel logLevel = LogLevel.None;
                switch (level)
                {
                case Log.Level.DEBUG:
                    logLevel = LogLevel.Debug;
                    break;

                case Log.Level.ERROR:
                    logLevel = LogLevel.Error;
                    break;

                case Log.Level.INFO:
                    logLevel = LogLevel.Information;
                    break;

                case Log.Level.WARN:
                    logLevel = LogLevel.Warning;
                    break;
                }
                _logger.Log(logLevel, "Aerospike-Message: " + message);
            });

            _client = new AsyncClient(_clientPolicy,
                                      _options.Host,
                                      _options.Port);
        }
コード例 #8
0
 protected override void BatchRead(BatchPolicy policy, Key[] keys, string binName)
 {
     if (shared.readLatency != null)
     {
         Stopwatch watch   = Stopwatch.StartNew();
         Record[]  records = client.Get(policy, keys, binName);
         double    elapsed = watch.Elapsed.TotalMilliseconds;
         OnBatchSuccess(elapsed);
     }
     else
     {
         Record[] records = client.Get(policy, keys, binName);
         OnBatchSuccess();
     }
 }
        public AsyncBatchExistsSequenceExecutor(AsyncCluster cluster, BatchPolicy policy, Key[] keys, ExistsSequenceListener listener)
            : base(cluster, policy, keys)
        {
            this.listener = listener;

            // Dispatch asynchronous commands to nodes.
            foreach (BatchNode batchNode in batchNodes)
            {
                foreach (BatchNode.BatchNamespace batchNamespace in batchNode.batchNamespaces)
                {
                    AsyncBatchExistsSequence async = new AsyncBatchExistsSequence(this, cluster, (AsyncNode)batchNode.node, batchNamespace, policy, keys, listener);
                    async.Execute();
                }
            }
        }
コード例 #10
0
        protected override void BatchRead(BatchPolicy policy, Key[] keys, string binName)
        {
            if (shared.readTimeoutCount > 0)
            {
                Thread.Yield();
            }

            if (shared.readLatency != null)
            {
                client.Get(policy, new LatencyBatchHandler(this), keys, binName);
            }
            else
            {
                client.Get(policy, new BatchHandler(this), keys, binName);
            }
        }
コード例 #11
0
        public void Initialize()
        {
            predAEq1BPolicy = new BatchPolicy();
            predAEq1RPolicy = new Policy();
            predAEq1WPolicy = new WritePolicy();

            Expression filter = Exp.Build(Exp.EQ(Exp.IntBin(binAName), Exp.Val(1)));

            predAEq1BPolicy.filterExp = filter;
            predAEq1RPolicy.filterExp = filter;
            predAEq1WPolicy.filterExp = filter;

            client.Delete(null, keyA);
            client.Delete(null, keyB);

            client.Put(null, keyA, binA1);
            client.Put(null, keyB, binA2);
        }
コード例 #12
0
 /// <summary>
 /// Copy batch policy from another batch policy.
 /// </summary>
 public BatchPolicy(BatchPolicy other)
     : base(other)
 {
     this.maxConcurrentThreads = other.maxConcurrentThreads;
     this.allowProleReads      = other.allowProleReads;
 }
コード例 #13
0
 protected internal Arguments()
 {
     this.writePolicy = new WritePolicy();
     this.policy      = new Policy();
     this.batchPolicy = new BatchPolicy();
 }
コード例 #14
0
 /// <summary>
 /// Copy batch policy from another batch policy.
 /// </summary>
 public BatchPolicy(BatchPolicy other)
     : base(other)
 {
     this.maxConcurrentThreads = other.maxConcurrentThreads;
     this.useBatchDirect = other.useBatchDirect;
     this.allowInline = other.allowInline;
     this.allowProleReads = other.allowProleReads;
 }
コード例 #15
0
 protected abstract void BatchRead(BatchPolicy policy, Key[] keys, string binName);