Ejemplo n.º 1
0
        /// <summary>
        /// Demonstrate multiple operations on a single record in one call.
        /// </summary>
        public override void RunExample(AerospikeClient client, Arguments args)
        {
            // Write initial record.
            Key key = new Key(args.ns, args.set, "opkey");
            Bin bin1 = new Bin("optintbin", 7);
            Bin bin2 = new Bin("optstringbin", "string value");
            console.Info("Put: namespace={0} set={1} key={2} binname1={3} binvalue1={4} binname1={5} binvalue1={6}",
                key.ns, key.setName, key.userKey, bin1.name, bin1.value, bin2.name, bin2.value);
            client.Put(args.writePolicy, key, bin1, bin2);

            // Add integer, write new string and read record.
            Bin bin3 = new Bin(bin1.name, 4);
            Bin bin4 = new Bin(bin2.name, "new string");
            console.Info("Add: " + bin3.value);
            console.Info("Write: " + bin4.value);
            console.Info("Read:");
            Record record = client.Operate(args.writePolicy, key, Operation.Add(bin3), Operation.Put(bin4), Operation.Get());

            if (record == null)
            {
                throw new Exception(string.Format("Failed to get: namespace={0} set={1} key={2}",
                    key.ns, key.setName, key.userKey));
            }

            ValidateBin(key, record, bin3.name, 11L, record.GetValue(bin3.name));
            ValidateBin(key, record, bin4.name, bin4.value.ToString(), record.GetValue(bin4.name));
        }
Ejemplo n.º 2
0
        public RoleEditForm(AerospikeClient client, EditType editType, RoleRow row)
        {
            this.client = client;
            this.editType = editType;
            InitializeComponent();

            grid.AutoGenerateColumns = false;
            PrivilegeCodeColumn.DataPropertyName = "Code";
            PrivilegeCodeColumn.ValueMember = "PrivilegeCode";
            PrivilegeCodeColumn.DisplayMember = "Label";
            PrivilegeCodeColumn.DataSource = GetPrivilegeTypeBinding();
            NamespaceColumn.DataPropertyName = "Namespace";
            SetNameColumn.DataPropertyName = "SetName";

            BindingSource bindingSource = new BindingSource();

            switch (editType)
            {
                case EditType.CREATE:
                    bindingSource.DataSource = new BindingList<Privilege>();
                    break;

                case EditType.EDIT:
                    this.Text = "Edit Role";
                    nameBox.Enabled = false;
                    nameBox.Text = row.name;
                    bindingSource.DataSource = LoadPrivileges(row.privileges);
                    oldPrivileges = row.privileges;
                    break;
            }
            grid.DataSource = bindingSource;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Batch multiple gets in one call to the server.
        /// </summary>
        public override void RunExample(AerospikeClient client, Arguments args)
        {
            string keyPrefix = "batchkey";
            string valuePrefix = "batchvalue";
            string binName = args.GetBinName("batchbin");
            int size = 8;

            WriteRecords(client, args, keyPrefix, binName, valuePrefix, size);
            BatchExists(client, args, keyPrefix, size);
            BatchReads(client, args, keyPrefix, binName, size);
            BatchReadHeaders(client, args, keyPrefix, size);

            try
            {
                BatchReadComplex(client, args, keyPrefix, binName);
            }
            catch (Exception ex)
            {
                // Server version may not yet support new batch protocol.
                Node[] nodes = client.Nodes;

                foreach (Node node in nodes)
                {
                    if (!node.HasBatchIndex)
                    {
                        Log.Warn("Server does not support new batch protocol");
                        return;
                    }
                }
                throw ex;
            }
        }
        public static void generateCustomerProduct(AerospikeClient client)
        {
            Random products = new Random (2727);
            Random productsPerAccount = new Random (9898);
            Random productQuantity = new Random (1919);
            for (int i = 0; i < accountTotal; i++) {

                int productsToAdd = productsPerAccount.Next (1, 150);
                string keyString = i.ToString ();
                Key cdtkey = new Key (ns, cdtSet, keyString);
                Aerospike.Helper.Collection.LargeList clist = new Aerospike.Helper.Collection.LargeList (client, null, cdtkey, cdtBinName);
                Key ldtkey = new Key (ns, ldtSet, keyString);
                LargeList llist = client.GetLargeList (null, ldtkey, ldtBinName);

                //for diagnositics
                client.Put (null, cdtkey, new Bin (keyBinName, keyString), new Bin (accBinName, keyString));
                client.Put (null, ldtkey, new Bin (keyBinName, keyString), new Bin (accBinName, keyString));

                for (int j = 0; j < productsToAdd; j++) {
                    int product = products.Next (1, productTotal);
                    int productAmount = productQuantity.Next (1, 100);
                    Value value = makeValue (product, productAmount);

                    llist.Update (value);
                    clist.Update (value);

                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Write array of integers using standard C# serializer.
        /// </summary>
        public virtual void TestArray(AerospikeClient client, Arguments args)
        {
            Key key = new Key(args.ns, args.set, "serialarraykey");

            // Delete record if it already exists.
            client.Delete(args.writePolicy, key);

            console.Info("Initialize array");

            int[] array = new int[10000];

            for (int i = 0; i < 10000; i++)
            {
                array[i] = i * i;
            }

            Bin bin = new Bin(args.GetBinName("serialbin"), (object)array);

            // Do a test that pushes this complex object through the serializer
            console.Info("Write array using serializer.");
            client.Put(args.writePolicy, key, bin);

            console.Info("Read array using serializer.");
            Record record = client.Get(args.policy, key, bin.name);

            if (record == null)
            {
                throw new Exception(string.Format("Failed to get: namespace={0} set={1} key={2}",
                    key.ns, key.setName, key.userKey));
            }

            int[] received;

            try
            {
                received = (int[])record.GetValue(bin.name);
            }
            catch (Exception)
            {
                throw new Exception(string.Format("Failed to parse returned value: namespace={0} set={1} key={2} bin={3}",
                    key.ns, key.setName, key.userKey, bin.name));
            }

            if (received.Length != 10000)
            {
                throw new Exception(string.Format("Array length mismatch: Expected={0:D} Received={1:D}",
                    10000, received.Length));
            }

            for (int i = 0; i < 10000; i++)
            {
                if (received[i] != i * i)
                {
                    throw new Exception(string.Format("Mismatch: index={0:D} expected={1:D} received={2:D}",
                        i, i * i, received[i]));
                }
            }

            console.Info("Read array successful.");
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Demonstrate writing bins with replace option. Replace will cause all record bins
        /// to be overwritten.  If an existing bin is not referenced in the replace command,
        /// the bin will be deleted.
        /// <para>
        /// The replace command has a performance advantage over the default put, because 
        /// the server does not have to read the existing record before overwriting it.
        /// </para>
        /// </summary>
        public override void RunExample(AerospikeClient client, Arguments args)
        {
            // Write securities
            console.Info("Write securities");
            Security security = new Security("GE", 26.89);
            security.Write(client, args.writePolicy, args.ns, args.set);

            security = new Security("IBM", 183.6);
            security.Write(client, args.writePolicy, args.ns, args.set);

            // Write account with positions.
            console.Info("Write account with positions");
            List<Position> positions = new List<Position>(2);
            positions.Add(new Position("GE", 1000));
            positions.Add(new Position("IBM", 500));
            Account accountWrite = new Account("123456", positions);
            accountWrite.Write(client, args.writePolicy, args.ns, args.set);

            // Read account/positions and join with securities.
            console.Info("Read accounts, positions and securities");
            Account accountRead = new Account();
            accountRead.Read(client, null, args.ns, args.set, "123456");

            // Validate data
            accountWrite.Validate(accountRead);
            console.Info("Accounts match");
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Query server configuration, cluster status and namespace configuration.
 /// </summary>
 public override void RunExample(AerospikeClient client, Arguments args)
 {
     Node node = client.Nodes[0];
     GetServerConfig(node, args);
     console.Write("");
     GetNamespaceConfig(node, args);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Initialize large list operator.
 /// </summary>
 /// <param name="client">client</param>
 /// <param name="policy">generic configuration parameters, pass in null for defaults</param>
 /// <param name="key">unique record identifier</param>
 /// <param name="binName">bin name</param>
 public LargeList(AerospikeClient client, WritePolicy policy, Key key, string binName)
 {
     this.client = client;
     this.policy = policy;
     this.key = key;
     this.binName = Value.Get(binName);
 }
Ejemplo n.º 9
0
        public void RunSimpleExample(AerospikeClient client, Arguments args)
        {
            Key key = new Key(args.ns, args.set, "listkey");
            string binName = args.GetBinName("listbin");

            // Delete record if it already exists.
            client.Delete(args.writePolicy, key);

            IList inputList = new List<Value>();
            inputList.Add(Value.Get(55));
            inputList.Add(Value.Get(77));

            // Write values to empty list.
            Record record = client.Operate(args.writePolicy, key, ListOperation.AppendItems(binName, inputList));

            console.Info("Record: " + record);

            // Pop value from end of list and also return new size of list.
            record = client.Operate(args.writePolicy, key, ListOperation.Pop(binName, -1), ListOperation.Size(binName));

            console.Info("Record: " + record);

            // There should be one result for each list operation on the same list bin.
            // In this case, there are two list operations (pop and size), so there
            // should be two results.
            IList list = record.GetList(binName);

            foreach (object value in list)
            {
                console.Info("Received: " + value);
            }
        }
Ejemplo n.º 10
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            // Establish connection the server
            try
            {
                AerospikeClient client = new AerospikeClient("45.55.231.46", 3000);

                // Create key
                Aerospike.Client.Key key = new Aerospike.Client.Key("test", "myset", "mykey");

                // Create Bins
                Bin bin1 = new Bin("name", "John");
                Bin bin2 = new Bin("age", 25);

                // Write record
                client.Put(null, key, bin1, bin2);

                // Read record
                Record record = client.Get(null, key);

                Record userRecord = client.Get(null, key);
                Console.WriteLine("Info:");
                Console.WriteLine("Name: " + userRecord.GetValue("name"));
                Console.WriteLine("Age: " + userRecord.GetValue("age"));

                // Close connection
                client.Close();
            }
            catch (AerospikeException.Connection conError)
            {
                Console.Write(conError);
            }
        }
Ejemplo n.º 11
0
 public static String infoAll(AerospikeClient client, String cmd)
 {
     StringBuilder results = new StringBuilder();
     foreach (Node node in client.Nodes){
         results.Append(Info.Request(node.Host.name, node.Host.port, cmd)).Append("\n");
     }
     return results.ToString();
 }
 private static void CheckKeyExists(AerospikeClient client, Policy policy,
         Key key)
 {
     Console.WriteLine("Check a record exists");
     var exists = client.Exists(policy, key);
     Console.WriteLine(key + " exists? " + exists);
     Console.WriteLine("");
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Initialize large set operator.
 /// </summary>
 /// <param name="client">client</param>
 /// <param name="policy">generic configuration parameters, pass in null for defaults</param>
 /// <param name="key">unique record identifier</param>
 /// <param name="binName">bin name</param>
 /// <param name="createModule">Lua function name that initializes list configuration parameters, pass null for default set</param>
 public LargeSet(AerospikeClient client, WritePolicy policy, Key key, string binName, string createModule)
 {
     this.client = client;
     this.policy = policy;
     this.key = key;
     this.binName = Value.Get(binName);
     this.createModule = Value.Get(createModule);
 }
 private void DeleteRecords(AerospikeClient client, Arguments args, string keyPrefix, int size)
 {
     for (int i = 0; i < size; i++)
     {
         Key key = new Key(args.ns, args.set, keyPrefix + i);
         client.Delete(args.writePolicy, key);
     }
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Add integer values.
        /// </summary>
        public override void RunExample(AerospikeClient client, Arguments args)
        {
            Key key = new Key(args.ns, args.set, "addkey");
            string binName = args.GetBinName("addbin");

            // Delete record if it already exists.
            client.Delete(args.writePolicy, key);

            // Perform some adds and check results.
            Bin bin = new Bin(binName, 10);
            console.Info("Initial add will create record.  Initial value is " + bin.value + '.');
            client.Add(args.writePolicy, key, bin);

            bin = new Bin(binName, 5);
            console.Info("Add " + bin.value + " to existing record.");
            client.Add(args.writePolicy, key, bin);

            Record record = client.Get(args.policy, key, bin.name);

            if (record == null)
            {
                throw new Exception(string.Format("Failed to get: namespace={0} set={1} key={2}",
                    key.ns, key.setName, key.userKey));
            }

            // The value received from the server is an unsigned byte stream.
            // Convert to an integer before comparing with expected.
            int received = record.GetInt(bin.name);
            int expected = 15;

            if (received == expected)
            {
                console.Info("Add successful: namespace={0} set={1} key={2} bin={3} value={4}",
                    key.ns, key.setName, key.userKey, bin.name, received);
            }
            else
            {
                console.Error("Add mismatch: Expected {0}. Received {1}.", expected, received);
            }

            // Demonstrate add and get combined.
            bin = new Bin(binName, 30);
            console.Info("Add " + bin.value + " to existing record.");
            record = client.Operate(args.writePolicy, key, Operation.Add(bin), Operation.Get(bin.name));

            expected = 45;
            received = record.GetInt(bin.name);

            if (received == expected)
            {
                console.Info("Add successful: namespace={0} set={1} key={2} bin={3} value={4}",
                    key.ns, key.setName, key.userKey, bin.name, received);
            }
            else
            {
                console.Error("Add mismatch: Expected {0}. Received {1}.", expected, received);
            }
        }
        public override void RunExample(Arguments a)
        {
            this.args = (BenchmarkArguments)a;
            shared = new BenchmarkShared(args);

            if (args.sync)
            {
                ClientPolicy policy = new ClientPolicy();
                policy.user = args.user;
                policy.password = args.password;
                policy.failIfNotConnected = true;
                client = new AerospikeClient(policy, args.host, args.port);

                try
                {
                    args.SetServerSpecific(client);
                    threads = new BenchmarkThreadSync[args.threadMax];
                    for (int i = 0; i < args.threadMax; i++)
                    {
                        threads[i] = new BenchmarkThreadSync(console, args, shared, this, client);
                    }
                    RunThreads();
                }
                finally
                {
                    client.Close();
                }
            }
            else
            {
                console.Info("Maximum concurrent commands: " + args.commandMax);

                AsyncClientPolicy policy = new AsyncClientPolicy();
                policy.user = args.user;
                policy.password = args.password;
                policy.failIfNotConnected = true;
                policy.asyncMaxCommands = args.commandMax;

                AsyncClient client = new AsyncClient(policy, args.host, args.port);
                this.client = client;

                try
                {
                    args.SetServerSpecific(client);
                    threads = new BenchmarkThreadAsync[args.threadMax];
                    for (int i = 0; i < args.threadMax; i++)
                    {
                        threads[i] = new BenchmarkThreadAsync(console, args, shared, this, client);
                    }
                    RunThreads();
                }
                finally
                {
                    client.Close();
                }
            }
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Perform operations on a list bin.
 /// </summary>
 public override void RunExample(AerospikeClient client, Arguments args)
 {
     if (! args.hasCDTList)
     {
         console.Info("CDT list functions are not supported by the connected Aerospike server.");
         return;
     }
     RunSimpleExample(client, args);
 }
 private static void AddSingleValue(AerospikeClient client,
         WritePolicy writePolicy)
 {
     var newKey = new Key("test", "myAddSet", "myAddKey");
     var counter = new Bin("mybin", 1);
     client.Add(writePolicy, newKey, counter);
     Console.WriteLine("Wrote this additional value (or bin):  " + newKey);
     Console.WriteLine("");
 }
        private void CreateIndex(AerospikeClient client, Arguments args, IndexCollectionType indexType, string indexName, string binName)
        {
            console.Info("Create GeoJSON {0} index: ns={1} set={2} index={3} bin={4}", indexType, args.ns, args.set, indexName, binName);

            Policy policy = new Policy();
            policy.timeout = 0; // Do not timeout on index create.
            IndexTask task = client.CreateIndex(policy, args.ns, args.set, indexName, binName, IndexType.GEO2DSPHERE, indexType);
            task.Wait();
        }
Ejemplo n.º 20
0
        private void RunQuery(AerospikeClient client, Arguments args, string indexName, string binName)
        {
            int begin = 4;
            int end = 7;

            console.Info("Query for:ns={0} set={1} index={2} bin={3} >= {4} <= {5}",
                args.ns, args.set, indexName, binName, begin, end);

            Statement stmt = new Statement();
            stmt.SetNamespace(args.ns);
            stmt.SetSetName(args.set);
            stmt.SetBinNames(binName);
            stmt.SetFilters(Filter.Range(binName, begin, end));

            ResultSet rs = client.QueryAggregate(null, stmt, "sum_example", "sum_single_bin", Value.Get(binName));

            try
            {
                int expected = 22; // 4 + 5 + 6 + 7
                int count = 0;

                while (rs.Next())
                {
                    object obj = rs.Object;

                    if (obj is long)
                    {
                        long sum = (long)rs.Object;

                        if (expected == (int)sum)
                        {
                            console.Info("Sum matched: value=" + expected);
                        }
                        else
                        {
                            console.Error("Sum mismatch: Expected {0}. Received {1}.", expected, sum);
                        }
                    }
                    else
                    {
                        console.Error("Unexpected return value: " + obj);
                        continue;
                    }
                    count++;
                }

                if (count == 0)
                {
                    console.Error("Query failed. No records returned.");
                }
            }
            finally
            {
                rs.Close();
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Drop a bin from a record.
        /// </summary>
        public override void RunExample(AerospikeClient client, Arguments args)
        {
            if (args.singleBin)
            {
                console.Info("Delete bin is not applicable to single bin servers.");
                return;
            }

            console.Info("Write multi-bin record.");
            Key key = new Key(args.ns, args.set, "delbinkey");
            string binName1 = args.GetBinName("bin1");
            string binName2 = args.GetBinName("bin2");
            Bin bin1 = new Bin(binName1, "value1");
            Bin bin2 = new Bin(binName2, "value2");
            client.Put(args.writePolicy, key, bin1, bin2);

            console.Info("Delete one bin in the record.");
            bin1 = Bin.AsNull(binName1); // Set bin value to null to drop bin.
            client.Put(args.writePolicy, key, bin1);

            console.Info("Read record.");
            Record record = client.Get(args.policy, key, bin1.name, bin2.name, "bin3");

            if (record == null)
            {
                throw new Exception(string.Format("Failed to get: namespace={0} set={1} key={2}",
                    key.ns, key.setName, key.userKey));
            }

            foreach (KeyValuePair<string, object> entry in record.bins)
            {
                console.Info("Received: namespace={0} set={1} key={2} bin={3} value={4}",
                    key.ns, key.setName, key.userKey, entry.Key, entry.Value);
            }

            bool valid = true;

            if (record.GetValue("bin1") != null)
            {
                console.Error("bin1 still exists.");
                valid = false;
            }

            object v2 = record.GetValue("bin2");

            if (v2 == null || !v2.Equals("value2"))
            {
                console.Error("bin2 value mismatch.");
                valid = false;
            }

            if (valid)
            {
                console.Info("Bin delete successful");
            }
        }
Ejemplo n.º 22
0
        private void CreateIndex(AerospikeClient client, Arguments args, string indexName, string binName)
        {
            console.Info("Create index: ns={0} set={1} index={2} bin={3}",
                args.ns, args.set, indexName, binName);

            Policy policy = new Policy();
            policy.timeout = 0; // Do not timeout on index create.
            IndexTask task = client.CreateIndex(policy, args.ns, args.set, indexName, binName, IndexType.NUMERIC);
            task.Wait();
        }
Ejemplo n.º 23
0
 public Program(AerospikeClient c)
 {
     this.client = c;
     this.epoch = DateTime.Now;
     this.updatePolicy = new WritePolicy ();
     this.updatePolicy.generationPolicy = GenerationPolicy.EXPECT_GEN_EQUAL;
     this.updatePolicy.recordExistsAction = RecordExistsAction.UPDATE_ONLY;
     this.createPolicy = new WritePolicy ();
     this.createPolicy.recordExistsAction = RecordExistsAction.CREATE_ONLY;
 }
 public BenchmarkThreadSync(
     Console console,
     BenchmarkArguments args,
     BenchmarkShared shared,
     Example example,
     AerospikeClient client
 )
     : base(console, args, shared, example)
 {
     this.client = client;
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Write and read a bin value.
 /// </summary>
 public override void RunExample(AerospikeClient client, Arguments args)
 {
     if (args.singleBin)
     {
         RunSingleBinTest(client, args);
     }
     else
     {
         RunMultiBinTest(client, args);
     }
     RunGetHeaderTest(client, args);
 }
 private static void AddRecords(AerospikeClient client,
         WritePolicy writePolicy)
 {
     const int size = 1024;
     for (var i = 0; i < size; i++)
     {
         var key = new Key("test", "myset", (i + 1));
         client.Put(writePolicy, key, new Bin("dots", i + " dots"));
     }
     Console.WriteLine("Added " + size + " Records");
     Console.WriteLine("");
 }
 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");
 }
Ejemplo n.º 28
0
        /// <summary>
        /// Perform operations on a list within a single bin.
        /// </summary>
        public override void RunExample(AerospikeClient client, Arguments args)
        {
            if (!args.hasLargeDataTypes)
            {
                console.Info("Large set functions are not supported by the connected Aerospike server.");
                return;
            }

            Key key = new Key(args.ns, args.set, "setkey");
            string binName = args.GetBinName("setbin");

            // Delete record if it already exists.
            client.Delete(args.writePolicy, key);

            // Initialize large set operator.
            Aerospike.Client.LargeSet set = client.GetLargeSet(args.writePolicy, key, binName, null);

            // Write values.
            set.Add(Value.Get("setvalue1"));
            set.Add(Value.Get("setvalue2"));
            set.Add(Value.Get("setvalue3"));

            // Verify large set was created with default configuration.
            IDictionary map = set.GetConfig();

            foreach (DictionaryEntry entry in map)
            {
                console.Info(entry.Key.ToString() + ',' + entry.Value);
            }

            // Remove last value.
            set.Remove(Value.Get("setvalue3"));

            int size = set.Size();

            if (size != 2)
            {
                throw new Exception("Size mismatch. Expected 2 Received " + size);
            }

            string received = (string)set.Get(Value.Get("setvalue2"));
            string expected = "setvalue2";

            if (received != null && received.Equals(expected))
            {
                console.Info("Data matched: namespace={0} set={1} key={2} value={3}", key.ns, key.setName, key.userKey, received);
            }
            else
            {
                console.Error("Data mismatch: Expected {0}. Received {1}.", expected, received);
            }
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Demonstrate touch command.
        /// </summary>
        public override void RunExample(AerospikeClient client, Arguments args)
        {
            Key key = new Key(args.ns, args.set, "touchkey");
            Bin bin = new Bin(args.GetBinName("touchbin"), "touchvalue");

            console.Info("Create record with 2 second expiration.");
            WritePolicy writePolicy = new WritePolicy();
            writePolicy.expiration = 2;
            client.Put(writePolicy, key, bin);

            console.Info("Touch same record with 5 second expiration.");
            writePolicy.expiration = 5;
            Record record = client.Operate(writePolicy, key, Operation.Touch(), Operation.GetHeader());

            if (record == null)
            {
                throw new Exception(string.Format("Failed to get: namespace={0} set={1} key={2} bin={3} value={4}",
                    key.ns, key.setName, key.userKey, bin.name, null));
            }

            if (record.expiration == 0)
            {
                throw new Exception(string.Format("Failed to get record expiration: namespace={0} set={1} key={2}",
                    key.ns, key.setName, key.userKey));
            }

            console.Info("Sleep 3 seconds.");
            Thread.Sleep(3000);

            record = client.Get(args.policy, key, bin.name);

            if (record == null)
            {
                throw new Exception(string.Format("Failed to get: namespace={0} set={1} key={2}",
                    key.ns, key.setName, key.userKey));
            }

            console.Info("Success. Record still exists.");
            console.Info("Sleep 4 seconds.");
            Thread.Sleep(4000);

            record = client.Get(args.policy, key, bin.name);

            if (record == null)
            {
                console.Info("Success. Record expired as expected.");
            }
            else
            {
                console.Error("Found record when it should have expired.");
            }
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Perform operations on a list within a single bin.
        /// </summary>
        public override void RunExample(AerospikeClient client, Arguments args)
        {
            if (!args.hasLargeDataTypes)
            {
                console.Info("Large list functions are not supported by the connected Aerospike server.");
                return;
            }

            RunSimpleExample(client, args);
            RunWithDistinctBins(client, args);
            RunWithSerializedBin(client, args);
            RunWithDefaultSerializedBin(client, args);
        }
Ejemplo n.º 31
0
        private static void AerospikeWriteMethod(User user)
        {
            using (var client = new AC.AerospikeClient(Config.DOCKER_MACHINE_IP, 3000))
            {
                if (!client.Connected)
                {
                    Console.WriteLine("Aerospike ERROR: Connection failed!");
                    return;
                }

                var wPolicy = new AC.WritePolicy
                {
                    recordExistsAction = AC.RecordExistsAction.UPDATE
                };

                var key     = new AC.Key("test", "users", user.Id);
                var binId   = new AC.Bin("id", user.Id);
                var binName = new AC.Bin("name", user.Name);
                var binAge  = new AC.Bin("age", user.Age);

                client.Put(wPolicy, key, binId, binName, binAge);
            }
        }
Ejemplo n.º 32
0
        private static void AerospikeReadMethod(long userId)
        {
            using (var client = new AC.AerospikeClient(Config.DOCKER_MACHINE_IP, 3000))
            {
                if (!client.Connected)
                {
                    Console.WriteLine("Aerospike ERROR: Connection failed!");
                    return;
                }

                var key = new AC.Key("test", "users", userId);

                var user = client.Get(null, key);
                if (user != null)
                {
                    Console.WriteLine($"Aerospike: ID: {user.GetValue("id")}, Name: {user.GetValue("name")}, Age:{user.GetValue("age")}");
                }
                else
                {
                    Console.WriteLine("Aerospike ERROR: User record not found!");
                }
            }
        }