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


C# Client.Key类代码示例

本文整理汇总了C#中Aerospike.Client.Key的典型用法代码示例。如果您正苦于以下问题:C# Key类的具体用法?C# Key怎么用?C# Key使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Key类属于Aerospike.Client命名空间,在下文中一共展示了Key类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: printRecord

        protected void printRecord(Key key, Record record)
        {
            Console.WriteLine("Key");
            if (key == null)
            {
                Console.WriteLine("\tkey == null");
            }
            else
            {
                Console.WriteLine(String.Format("\tNamespace: {0}", key.ns));
                Console.WriteLine(String.Format("\t      Set: {0}", key.setName));
                Console.WriteLine(String.Format("\t      Key: {0}", key.userKey));
                Console.WriteLine(String.Format("\t   Digest: {0}", key.digest.ToString()));
            }
            Console.WriteLine("Record");
            if (record == null)
            {
                Console.WriteLine("\trecord == null");
            }
            else
            {
                Console.WriteLine(String.Format("\tGeneration: {0}", record.generation));
                Console.WriteLine(String.Format("\tExpiration: {0}", record.expiration));
                Console.WriteLine(String.Format("\t       TTL: {0}", record.TimeToLive));
                Console.WriteLine("Bins");

                foreach (KeyValuePair<string, Object> entry in record.bins)
                {
                    Console.WriteLine(String.Format("\t{0} = {1}", entry.Key, entry.Value.ToString()));
                }
            }
        }
开发者ID:helipilot50,项目名称:aerospike-helper,代码行数:32,代码来源:HelperTests.cs

示例2: Replace

        public void Replace()
        {
            Key key = new Key(args.ns, args.set, "replacekey");
            Bin bin1 = new Bin("bin1", "value1");
            Bin bin2 = new Bin("bin2", "value2");
            Bin bin3 = new Bin("bin3", "value3");

            client.Put(null, key, bin1, bin2);

            WritePolicy policy = new WritePolicy();
            policy.recordExistsAction = RecordExistsAction.REPLACE;
            client.Put(policy, key, bin3);

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

            if (record.GetValue(bin1.name) != null)
            {
                Assert.Fail(bin1.name + " found when it should have been deleted.");
            }

            if (record.GetValue(bin2.name) != null)
            {
                Assert.Fail(bin2.name + " found when it should have been deleted.");
            }
            AssertBinEqual(key, record, bin3);
        }
开发者ID:Caldas,项目名称:aerospike-client-csharp,代码行数:27,代码来源:TestReplace.cs

示例3: ReadHeaderCommand

 public ReadHeaderCommand(Cluster cluster, Policy policy, Key key)
 {
     this.cluster = cluster;
     this.policy = policy;
     this.key = key;
     this.partition = new Partition(key);
 }
开发者ID:vonbv,项目名称:aerospike-client-csharp,代码行数:7,代码来源:ReadHeaderCommand.cs

示例4: Main

        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();
        }
开发者ID:jamesrcounts,项目名称:areospike-client-demo-net,代码行数:30,代码来源:Program.cs

示例5: LargeMap

        public void LargeMap()
        {
            if (!args.ValidateLDT())
            {
                return;
            }
            Key key = new Key(args.ns, args.set, "setkey");
            string binName = args.GetBinName("setbin");

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

            // Initialize Large Map operator.
            LargeMap lmap = client.GetLargeMap(null, key, binName, null);

            // Write values.
            lmap.Put(Value.Get("lmapName1"), Value.Get("lmapValue1"));
            lmap.Put(Value.Get("lmapName2"), Value.Get("lmapValue2"));
            lmap.Put(Value.Get("lmapName3"), Value.Get("lmapValue3"));

            // Remove last value.
            lmap.Remove(Value.Get("lmapName3"));
            Assert.AreEqual(2, lmap.Size());

            IDictionary mapReceived = lmap.Get(Value.Get("lmapName2"));
            string stringReceived = (string)mapReceived["lmapName2"];
            Assert.AreEqual("lmapValue2", stringReceived);
        }
开发者ID:Caldas,项目名称:aerospike-client-csharp,代码行数:28,代码来源:TestLargeMap.cs

示例6: 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

示例7: AsyncBatchExistsArrayExecutor

        public AsyncBatchExistsArrayExecutor(
			AsyncCluster cluster,
			BatchPolicy policy,
			Key[] keys,
			ExistsArrayListener listener
		)
            : base(cluster, policy, keys)
        {
            this.existsArray = new bool[keys.Length];
            this.listener = listener;

            // Create commands.
            AsyncMultiCommand[] tasks = new AsyncMultiCommand[base.taskSize];
            int count = 0;

            foreach (BatchNode batchNode in batchNodes)
            {
                if (batchNode.node.UseNewBatch(policy))
                {
                    // New batch
                    tasks[count++] = new AsyncBatchExistsArrayCommand(this, cluster, batchNode, policy, keys, existsArray);
                }
                else
                {
                    // Old batch only allows one namespace per call.
                    foreach (BatchNode.BatchNamespace batchNamespace in batchNode.batchNamespaces)
                    {
                        tasks[count++] = new AsyncBatchExistsArrayDirect(this, cluster, (AsyncNode)batchNode.node, batchNamespace, policy, keys, existsArray);
                    }
                }
            }
            // Dispatch commands to nodes.
            Execute(tasks, policy.maxConcurrentThreads);
        }
开发者ID:vonbv,项目名称:aerospike-client-csharp,代码行数:34,代码来源:AsyncBatch.cs

示例8: Prepare

        public static void Prepare(TestContext testContext)
        {
            Assembly assembly = Assembly.GetExecutingAssembly();
            RegisterTask rtask = client.Register(null, assembly, "Aerospike.Test.Resources.record_example.lua", "record_example.lua", Language.LUA);
            rtask.Wait();

            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.STRING, IndexCollectionType.MAPKEYS);
            task.Wait();

            for (int i = 1; i <= size; i++)
            {
                Key key = new Key(args.ns, args.set, keyPrefix + i);
                Dictionary<string, string> map = new Dictionary<string, string>();

                map[mapKeyPrefix + 1] = mapValuePrefix + i;
                if (i % 2 == 0)
                {
                    map[mapKeyPrefix + 2] = mapValuePrefix + i;
                }
                if (i % 3 == 0)
                {
                    map[mapKeyPrefix + 3] = mapValuePrefix + i;
                }

                Bin bin = new Bin(binName, map);
                client.Put(null, key, bin);
            }
        }
开发者ID:Caldas,项目名称:aerospike-client-csharp,代码行数:30,代码来源:TestQueryCollection.cs

示例9: 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

示例10: InsertByKey

        public void InsertByKey()
        {
            int i = 0;
            for (int x = 1; x <= TestQueryEngine.RECORD_COUNT; x++)
            {
                String keyString = "selector-test:" + x;

                Bin name = new Bin("name", "name:" + x);
                Bin age = new Bin("age", ages[i]);
                Bin colour = new Bin("color", colours[i]);
                Bin animal = new Bin("animal", animals[i]);
                List<Bin> bins = new List<Bin>() { name, age, colour, animal };

                Key key = new Key(TestQueryEngine.NAMESPACE, TestQueryEngine.SET_NAME, keyString);
                this.client.Delete(null, key);

                KeyQualifier kq = new KeyQualifier(Value.Get(keyString));
                Statement stmt = new Statement();
                stmt.Namespace = TestQueryEngine.NAMESPACE;
                stmt.SetName = TestQueryEngine.SET_NAME;

                queryEngine.Insert(stmt, kq, bins);

                Record record = this.client.Get(null, key);
                Assert.NotNull(record);
                i++;
                if (i == 5)
                    i = 0;
            }
        }
开发者ID:helipilot50,项目名称:aerospike-helper,代码行数:30,代码来源:InserterTests.cs

示例11: OperateMapClear

        public void OperateMapClear()
        {
            // Test clear.
            if (!args.ValidateMap())
            {
                return;
            }

            Key key = new Key(args.ns, args.set, "opmkey9");
            client.Delete(null, key);

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

            Record record = client.Operate(null, key, MapOperation.PutItems(MapPolicy.Default, binName, inputMap));

            AssertRecordFound(key, record);

            long size = record.GetLong(binName);
            Assert.AreEqual(2, size);

            record = client.Operate(null, key,
                MapOperation.Clear(binName),
                MapOperation.Size(binName)
                );

            IList results = record.GetList(binName);
            size = (long)results[1];
            Assert.AreEqual(0, size);
        }
开发者ID:Caldas,项目名称:aerospike-client-csharp,代码行数:31,代码来源:TestOperateMap.cs

示例12: TestArray

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

示例13: Button_Click

        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);
            }
        }
开发者ID:bohregard,项目名称:SampleCsAeroSpike,代码行数:33,代码来源:MainWindow.xaml.cs

示例14: LargeStack

        public void LargeStack()
        {
            Key key = new Key(args.ns, args.set, "stackkey");
            string binName = args.GetBinName("stackbin");

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

            // Initialize large stack operator.
            LargeStack stack = client.GetLargeStack(null, key, binName, null);

            // Write values.
            stack.Push(Value.Get("stackvalue1"));
            stack.Push(Value.Get("stackvalue2"));
            //stack.push(Value.get("stackvalue3"));

            // Delete last value.
            // Comment out until trim supported on server.
            //stack.trim(1);

            Assert.AreEqual(2, stack.Size());

            IList list = stack.Peek(1);
            string received = (string)list[0];
            Assert.AreEqual("stackvalue2", received);
        }
开发者ID:vonbv,项目名称:aerospike-client-csharp,代码行数:26,代码来源:TestLargeSet.cs

示例15: LargeSet

        public void LargeSet()
        {
            if (!args.ValidateLDT())
            {
                return;
            }
            Key key = new Key(args.ns, args.set, "setkey");
            string binName = args.GetBinName("setbin");

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

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

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

            // Remove last value.
            set.Remove(Value.Get("setvalue3"));
            Assert.AreEqual(2, set.Size());

            string received = (string)set.Get(Value.Get("setvalue2"));
            Assert.AreEqual("setvalue2", received);
        }
开发者ID:Caldas,项目名称:aerospike-client-csharp,代码行数:27,代码来源:TestLargeStack.cs


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