• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Client.WritePolicy类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: LargeList

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


示例4: LargeSet

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


示例5: ExecuteCommand

 public ExecuteCommand(Cluster cluster, WritePolicy writePolicy, Key key, string packageName, string functionName, Value[] args)
     : base(cluster, writePolicy, key, null)
 {
     this.writePolicy = writePolicy;
     this.packageName = packageName;
     this.functionName = functionName;
     this.args = args;
 }
开发者ID:vonbv,项目名称:aerospike-client-csharp,代码行数:8,代码来源:ExecuteCommand.cs


示例6: AddSingleValue

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


示例7: AsyncExecute

 public AsyncExecute(AsyncCluster cluster, WritePolicy writePolicy, ExecuteListener listener, Key key, string packageName, string functionName, Value[] args)
     : base(cluster, writePolicy, null, key, null)
 {
     this.writePolicy = writePolicy;
     this.executeListener = listener;
     this.packageName = packageName;
     this.functionName = functionName;
     this.args = args;
 }
开发者ID:Caldas,项目名称:aerospike-client-csharp,代码行数:9,代码来源:AsyncExecute.cs


示例8: Program

 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;
 }
开发者ID:aerospike,项目名称:user-events-csharp,代码行数:10,代码来源:Program.cs


示例9: AddRecords

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


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


示例11: WriteRecords

        public static void WriteRecords(TestContext testContext)
        {
            WritePolicy policy = new WritePolicy();
            policy.expiration = 2592000;

            for (int i = 1; i <= size; i++)
            {
                Key key = new Key(args.ns, args.set, keyPrefix + i);
                Bin bin = new Bin(binName, valuePrefix + i);

                client.Put(policy, key, bin);
            }
        }
开发者ID:Caldas,项目名称:aerospike-client-csharp,代码行数:13,代码来源:TestBatch.cs


示例12: RunExample

        /// <summary>
        /// Write and twice read a bin value, demonstrating record expiration.
        /// </summary>
        public override void RunExample(AerospikeClient client, Arguments args)
        {
            Key key = new Key(args.ns, args.set, "expirekey");
            Bin bin = new Bin(args.GetBinName("expirebin"), "expirevalue");

            console.Info("Put: namespace={0} set={1} key={2} bin={3} value={4} expiration=2",
                key.ns, key.setName, key.userKey, bin.name, bin.value);

            // Specify that record expires 2 seconds after it's written.
            WritePolicy writePolicy = new WritePolicy();
            writePolicy.expiration = 2;
            client.Put(writePolicy, key, bin);

            // Read the record before it expires, showing it's there.
            console.Info("Get: namespace={0} set={1} key={2}", key.ns, key.setName, key.userKey);

            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));
            }

            object received = record.GetValue(bin.name);
            string expected = bin.value.ToString();

            if (received.Equals(expected))
            {
                console.Info("Get successful: namespace={0} set={1} key={2} bin={3} value={4}",
                    key.ns, key.setName, key.userKey, bin.name, received);
            }
            else
            {
                throw new Exception(string.Format("Expire mismatch: Expected {0}. Received {1}.", expected, received));
            }

            // Read the record after it expires, showing it's gone.
            console.Info("Sleeping for 3 seconds ...");
            Thread.Sleep(3 * 1000);
            record = client.Get(args.policy, key, bin.name);

            if (record == null)
            {
                console.Info("Expiry successful. Record not found.");
            }
            else
            {
                console.Error("Found record when it should have expired.");
            }
        }
开发者ID:Caldas,项目名称:aerospike-client-csharp,代码行数:54,代码来源:Expire.cs


示例13: createTweet

        public void createTweet()
        {
            Console.WriteLine("\n********** Create Tweet **********\n");

            Record userRecord = null;
            Key userKey = null;
            Key tweetKey = null;

            // Get username
            string username;
            Console.WriteLine("\nEnter username:");
            username = Console.ReadLine();

            if (username != null && username.Length > 0)
            {
                // Check if username exists
                userKey = new Key("test", "users", username);
                userRecord = client.Get(null, userKey);
                if (userRecord != null)
                {
                    int nextTweetCount = int.Parse(userRecord.GetValue("tweetcount").ToString()) + 1;

                    // Get tweet
                    string tweet;
                    Console.WriteLine("Enter tweet for " + username + ":");
                    tweet = Console.ReadLine();

                    // Write record
                    WritePolicy wPolicy = new WritePolicy();
                    wPolicy.recordExistsAction = RecordExistsAction.UPDATE;

                    // Create timestamp to store along with the tweet so we can query, index and report on it
                    long ts = getTimeStamp();

                    tweetKey = new Key("test", "tweets", username + ":" + nextTweetCount);
                    Bin bin1 = new Bin("tweet", tweet);
                    Bin bin2 = new Bin("ts", ts);
                    Bin bin3 = new Bin("username", username);

                    client.Put(wPolicy, tweetKey, bin1, bin2, bin3);
                    Console.WriteLine("\nINFO: Tweet record created!");

                    // Update tweet count and last tweet'd timestamp in the user record
                    updateUser(client, userKey, wPolicy, ts, nextTweetCount);
                }
                else
                {
                    Console.WriteLine("ERROR: User record not found!");
                }
            }
        }
开发者ID:rmondragon,项目名称:student-workbook,代码行数:51,代码来源:TweetService.cs


示例14: Generation

        public void Generation()
        {
            Key key = new Key(args.ns, args.set, "genkey");
            string binName = args.GetBinName("genbin");

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

            // Set some values for the same record.
            Bin bin = new Bin(binName, "genvalue1");

            client.Put(null, key, bin);

            bin = new Bin(binName, "genvalue2");

            client.Put(null, key, bin);

            // Retrieve record and its generation count.
            Record record = client.Get(null, key, bin.name);
            AssertBinEqual(key, record, bin);

            // Set record and fail if it's not the expected generation.
            bin = new Bin(binName, "genvalue3");

            WritePolicy writePolicy = new WritePolicy();
            writePolicy.generationPolicy = GenerationPolicy.EXPECT_GEN_EQUAL;
            writePolicy.generation = record.generation;
            client.Put(writePolicy, key, bin);

            // Set record with invalid generation and check results .
            bin = new Bin(binName, "genvalue4");
            writePolicy.generation = 9999;

            try
            {
                client.Put(writePolicy, key, bin);
                Assert.Fail("Should have received generation error instead of success.");
            }
            catch (AerospikeException ae)
            {
                if (ae.Result != ResultCode.GENERATION_ERROR)
                {
                    Assert.Fail("Unexpected return code: namespace=" + key.ns + " set=" + key.setName + " key=" + key.userKey + " bin=" + bin.name + " value=" + bin.value + " code=" + ae.Result);
                }
            }

            // Verify results.
            record = client.Get(null, key, bin.name);
            AssertBinEqual(key, record, bin.name, "genvalue3");
        }
开发者ID:vonbv,项目名称:aerospike-client-csharp,代码行数:50,代码来源:TestGeneration.cs


示例15: WriteRecord

 protected override void WriteRecord(WritePolicy policy, Key key, Bin bin)
 {
     if (shared.writeLatency != null)
     {
         Stopwatch watch = Stopwatch.StartNew();
         client.Put(policy, key, bin);
         double elapsed = watch.Elapsed.TotalMilliseconds;
         OnWriteSuccess(elapsed);
     }
     else
     {
         client.Put(policy, key, bin);
         OnWriteSuccess();
     }
 }
开发者ID:Caldas,项目名称:aerospike-client-csharp,代码行数:15,代码来源:BenchmarkThreadSync.cs


示例16: RunReplaceExample

        private void RunReplaceExample(AerospikeClient client, Arguments args)
        {
            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");

            console.Info("Put: namespace={0} set={1} key={2} bin1={3} value1={4} bin2={5} value2={6}",
                key.ns, key.setName, key.userKey, bin1.name, bin1.value, bin2.name, bin2.value);

            client.Put(args.writePolicy, key, bin1, bin2);

            console.Info("Replace with: namespace={0} set={1} key={2} bin={3} value={4}",
                key.ns, key.setName, key.userKey, bin3.name, bin3.value);

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

            console.Info("Get: namespace={0} set={1} key={2}", key.ns, key.setName, key.userKey);

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

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

            if (record.GetValue(bin1.name) == null)
            {
                console.Info(bin1.name + " was deleted as expected.");
            }
            else
            {
                console.Error(bin1.name + " found when it should have been deleted.");
            }

            if (record.GetValue(bin2.name) == null)
            {
                console.Info(bin2.name + " was deleted as expected.");
            }
            else
            {
                console.Error(bin2.name + " found when it should have been deleted.");
            }
            ValidateBin(key, bin3, record);
        }
开发者ID:vonbv,项目名称:aerospike-client-csharp,代码行数:48,代码来源:Replace.cs


示例17: Prepare

        public static void Prepare(TestContext testContext)
        {
            Policy policy = new Policy();
            policy.timeout = 0; // Do not timeout on index create.
            IndexTask itask = client.CreateIndex(policy, args.ns, args.set, indexName, binName, IndexType.NUMERIC);
            itask.Wait();

            WritePolicy writePolicy = new WritePolicy();
            writePolicy.sendKey = true;

            for (int i = 1; i <= size; i++)
            {
                Key key = new Key(args.ns, args.set, keyPrefix + i);
                Bin bin = new Bin(binName, i);
                client.Put(writePolicy, key, bin);
            }
        }
开发者ID:Caldas,项目名称:aerospike-client-csharp,代码行数:17,代码来源:TestQueryKey.cs


示例18: WriteRecord

        protected override void WriteRecord(WritePolicy policy, Key key, Bin bin)
        {
            // If timeout occurred, yield thread to back off throttle.
            // Fail counters are reset every second.
            if (shared.writeTimeoutCount > 0)
            {
                Thread.Yield();
            }

            if (shared.writeLatency != null)
            {
                client.Put(policy, new LatencyWriteHandler(this, key, bin), key, bin);
            }
            else
            {
                client.Put(policy, new WriteHandler(this, key, bin), key, bin);
            }
        }
开发者ID:Caldas,项目名称:aerospike-client-csharp,代码行数:18,代码来源:BenchmarkThreadAsync.cs


示例19: ServerSideExists

        private void ServerSideExists(AerospikeClient client, WritePolicy policy, Key key, Bin bin, int search, bool expected)
        {
            long lexists = (long)client.Execute(policy, key, "record_example", "valueExists", Value.Get(bin.name), Value.Get(search));
            bool exists = (lexists != 0);

            if (expected && exists)
            {
                console.Info("Value found as expected.");
                return;
            }

            if (!expected && !exists)
            {
                console.Info("Value not found as expected.");
                return;
            }

            console.Error("Data mismatch. Expected " + expected + " Received " + exists);
        }
开发者ID:Caldas,项目名称:aerospike-client-csharp,代码行数:19,代码来源:UserDefinedFunction.cs


示例20: Expire

        public void Expire()
        {
            Key key = new Key(args.ns, args.set, "expirekey ");
            Bin bin = new Bin(binName, "expirevalue");

            // Specify that record expires 2 seconds after it's written.
            WritePolicy writePolicy = new WritePolicy();
            writePolicy.expiration = 2;
            client.Put(writePolicy, key, bin);

            // Read the record before it expires, showing it is there.
            Record record = client.Get(null, key, bin.name);
            AssertBinEqual(key, record, bin);

            // Read the record after it expires, showing it's gone.
            Util.Sleep(3 * 1000);
            record = client.Get(null, key, bin.name);
            Assert.IsNull(record);
        }
开发者ID:Caldas,项目名称:aerospike-client-csharp,代码行数:19,代码来源:TestExpire.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Tree.DrawContext类代码示例发布时间:2022-05-24
下一篇:
C# Client.Value类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap