当前位置: 首页>>代码示例>>C#>>正文


C# AerospikeClient.Operate方法代码示例

本文整理汇总了C#中Aerospike.Client.AerospikeClient.Operate方法的典型用法代码示例。如果您正苦于以下问题:C# AerospikeClient.Operate方法的具体用法?C# AerospikeClient.Operate怎么用?C# AerospikeClient.Operate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Aerospike.Client.AerospikeClient的用法示例。


在下文中一共展示了AerospikeClient.Operate方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RunSimpleExample

        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);
            }
        }
开发者ID:Caldas,项目名称:aerospike-client-csharp,代码行数:32,代码来源:OperateList.cs

示例2: RunExample

        /// <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));
        }
开发者ID:alanprot,项目名称:aerospike-client-csharp,代码行数:30,代码来源:Operate.cs

示例3: RunScoreExample

        public void RunScoreExample(AerospikeClient client, Arguments args)
        {
            Key key = new Key(args.ns, args.set, "mapkey");
            string binName = args.GetBinName("mapbin");

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

            IDictionary inputMap = new Dictionary<Value, Value>();
            inputMap[Value.Get("Charlie")] = Value.Get(55);
            inputMap[Value.Get("Jim")] = Value.Get(98);
            inputMap[Value.Get("John")] = Value.Get(76);
            inputMap[Value.Get("Harry")] = Value.Get(82);

            // Write values to empty map.
            Record record = client.Operate(args.writePolicy, key,
                MapOperation.PutItems(MapPolicy.Default, binName, inputMap)
                );

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

            // Increment some user scores.
            record = client.Operate(args.writePolicy, key,
                MapOperation.Increment(MapPolicy.Default, binName, Value.Get("John"), Value.Get(5)),
                MapOperation.Decrement(MapPolicy.Default, binName, Value.Get("Jim"), Value.Get(4))
                );

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

            // Get top two scores.
            record = client.Operate(args.writePolicy, key,
                MapOperation.GetByRankRange(binName, -2, 2, MapReturnType.KEY_VALUE)
                );

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

            foreach (object value in results)
            {
                console.Info("Received: " + value);
            }
        }
开发者ID:Caldas,项目名称:aerospike-client-csharp,代码行数:44,代码来源:OperateMap.cs

示例4: RunExample

        /// <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.");
            }
        }
开发者ID:vonbv,项目名称:aerospike-client-csharp,代码行数:55,代码来源:Touch.cs

示例5: RunSimpleExample

        public void RunSimpleExample(AerospikeClient client, Arguments args)
        {
            Key key = new Key(args.ns, args.set, "mapkey");
            string binName = args.GetBinName("mapbin");

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

            IDictionary inputMap = new Dictionary<Value, Value>();
            inputMap[Value.Get(1)] = Value.Get(55);
            inputMap[Value.Get(2)] = Value.Get(33);

            // Write values to empty map.
            Record record = client.Operate(args.writePolicy, key, MapOperation.PutItems(MapPolicy.Default, binName, inputMap));

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

            // Pop value from map and also return new size of map.
            record = client.Operate(args.writePolicy, key, MapOperation.RemoveByKey(binName, Value.Get(1), MapReturnType.VALUE), MapOperation.Size(binName));

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

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

            foreach (object value in results)
            {
                console.Info("Received: " + value);
            }
        }
开发者ID:Caldas,项目名称:aerospike-client-csharp,代码行数:32,代码来源:OperateMap.cs

示例6: RunExample

        /// <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);
            }
        }
开发者ID:alanprot,项目名称:aerospike-client-csharp,代码行数:61,代码来源:Add.cs

示例7: WriteEventToAerospike

        public static void WriteEventToAerospike(string date, AerospikeClient client, string account, string product, string txType)
        {
            /*
            Event record schema

            Key: account::date::sequence
            Bin: keyBinName - contains string same as key (diagnostic only)
            Bin: accBinName - contains string:  account
            Bin: dayBinName - contains string:  day
            Bin: seqBinName - contains integer sequence number
            Bin: listBinName - contains a CDT list of events

            CDT list element: product,txType
            */
            int seq = 1;
            int eventSize = 0;

            string accDayString = account + "::" + date;
            string keyString = accDayString + "::" + seq;
            string eventString = product + "," + txType;
            Key key = new Key (ns, seqSet, keyString);
            /*
                         * get the size of the event list in first record
                         */
            Record record = client.Operate (null, key, ListOperation.Size (listBinName), Operation.Get (seqBinName));

            if (record != null) {
                eventSize = record.GetInt (listBinName);

                if (eventSize == 30) {
                    record = client.Operate (null, key, Operation.Add (new Bin (seqBinName, 1)), Operation.Get (seqBinName));
                    seq = record.GetInt (seqBinName);
                    keyString = account + "::" + date + "::" + seq;
                    key = new Key (ns, seqSet, keyString);
                }
            }

            client.Operate (null, key,
                Operation.Put (new Bin (keyBinName, keyString)),
                Operation.Put (new Bin (accBinName, account)),
                Operation.Put (new Bin (dayBinName, date)),
                Operation.Put (new Bin (seqBinName, seq)),
                ListOperation.Append (listBinName, Value.Get (eventString)));
        }
开发者ID:helipilot50,项目名称:Aerospike-list-expansion,代码行数:44,代码来源:Program.cs

示例8: updateUserUsingOperate

 private void updateUserUsingOperate(AerospikeClient client, Key userKey, WritePolicy policy, long ts)
 {
     Record record = client.Operate(policy, userKey, Operation.Add(new Bin("tweetcount", 1)), Operation.Put(new Bin("lasttweeted", ts)), Operation.Get());
     Console.WriteLine("INFO: The tweet count now is: " + record.GetValue("tweetcount"));
 }
开发者ID:aerospike,项目名称:user-events-csharp,代码行数:5,代码来源:TweetService.cs

示例9: MultiOps

 private static void MultiOps(AerospikeClient client,
         WritePolicy writePolicy, Key key)
 {
     Console.WriteLine("Multiops");
     var bin1 = new Bin("optintbin", 7);
     var bin2 = new Bin("optstringbin", "string value");
     client.Put(writePolicy, key, bin1, bin2);
     var bin3 = new Bin(bin1.name, 4);
     var bin4 = new Bin(bin2.name, "new string");
     var record = client.Operate(writePolicy, key, Operation.Add(bin3),
             Operation.Put(bin4), Operation.Get());
     Console.WriteLine("Record: " + record);
 }
开发者ID:jamesrcounts,项目名称:areospike-client-demo-net,代码行数:13,代码来源:Program.cs


注:本文中的Aerospike.Client.AerospikeClient.Operate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。