コード例 #1
0
        } //scanTweetsCallback

        public void queryTweetsByUsername()
        {
            Console.WriteLine("\n********** Query Tweets By Username **********\n");

            RecordSet rs = null;

            try
            {
                // Get username
                string username;
                Console.WriteLine("\nEnter username:"******"test", "tweets", "username_index", "username", IndexType.STRING);
                    task.Wait();

                    string[]  bins = { "tweet" };
                    Statement stmt = new Statement();
                    stmt.SetNamespace("test");
                    stmt.SetSetName("tweets");
                    stmt.SetIndexName("username_index");
                    stmt.SetBinNames(bins);
                    stmt.SetFilters(Filter.Equal("username", username));

                    Console.WriteLine("\nHere's " + username + "'s tweet(s):\n");

                    rs = client.Query(null, stmt);
                    while (rs.Next())
                    {
                        Record r = rs.Record;
                        Console.WriteLine(r.GetValue("tweet"));
                    }
                }
                else
                {
                    Console.WriteLine("ERROR: User record not found!");
                }
            }
            finally
            {
                if (rs != null)
                {
                    // Close record set
                    rs.Close();
                }
            }
        } //queryTweetsByUsername
コード例 #2
0
ファイル: QueryTest.cs プロジェクト: ahmetsekmen/Aerospike
        private static void CreateIndex(AerospikeClient client, string ns, string set, string indexName, string binName)
        {
            Console.WriteLine("Create index");
            Policy policy = new Policy();

            policy.SetTimeout(0); // Do not timeout on index create.
            IndexTask task = client.CreateIndex(policy, ns, set, indexName, binName, IndexType.NUMERIC);

            task.Wait();
        }
コード例 #3
0
        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();
        }
コード例 #4
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();
        }
コード例 #5
0
        public void createSecondaryIndexes()
        {
            // NOTE: Index creation has been included in here for convenience and to demonstrate the syntax. The recommended way of creating indexes in production env is via AQL

            IndexTask task1 = client.CreateIndex(null, "test", "tweets", "username_index", "username", IndexType.STRING);

            task1.Wait();
            Console.WriteLine("Done creating secondary index on: set=tweets, bin=username");

            Console.WriteLine("\nCreating secondary index on: set=tweets, bin=ts. Hang on...");
            IndexTask task2 = client.CreateIndex(null, "test", "tweets", "ts_index", "ts", IndexType.NUMERIC);

            task2.Wait();
            Console.WriteLine("Done creating secondary index on: set=tweets, bin=ts");

            Console.WriteLine("\nCreating secondary index on: set=users, bin=tweetcount. Hang on...");
            IndexTask task3 = client.CreateIndex(null, "test", "users", "tweetcount_index", "tweetcount", IndexType.NUMERIC);

            task3.Wait();
            Console.WriteLine("Done creating secondary index on: set=users, bin=tweetcount");
        }
コード例 #6
0
        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.totalTimeout = 0;             // Do not timeout on index create.

            try
            {
                IndexTask task = client.CreateIndex(policy, args.ns, args.set, indexName, binName, IndexType.GEO2DSPHERE, indexType);
                task.Wait();
            }
            catch (AerospikeException ae)
            {
                if (ae.Result != ResultCode.INDEX_ALREADY_EXISTS)
                {
                    throw;
                }
            }
        }
コード例 #7
0
        } //main

        public void aggregateUsersByTweetCountByRegion(AerospikeClient client)
        {
            ResultSet rs = null;

            try
            {
                int min;
                int max;
                Console.WriteLine("\nEnter Min Tweet Count:");
                min = int.Parse(Console.ReadLine());
                Console.WriteLine("Enter Max Tweet Count:");
                max = int.Parse(Console.ReadLine());

                Console.WriteLine("\nAggregating users with " + min + "-" + max + " tweets by region. Hang on...\n");

                // NOTE: Index creation has been included in here for convenience and to demonstrate the syntax.
                // NOTE: The recommended way of creating indexes in production env is via AQL.
                IndexTask task = client.CreateIndex(null, "test", "testusers", "tweetcountindex", "tweetcount", IndexType.NUMERIC);
                task.Wait();

                // NOTE: UDF registration has been included here for convenience and to demonstrate the syntax.
                // NOTE: The recommended way of registering UDFs in production env is via AQL
                string luaDirectory = @"..\..\udf";
                LuaConfig.PackagePath = luaDirectory + @"\?.lua";

                string filename = "aggregationByRegion.lua";
                string path     = Path.Combine(luaDirectory, filename);

                RegisterTask rt = client.Register(null, path, filename, Language.LUA);
                rt.Wait();

                Statement stmt = new Statement();
                stmt.SetNamespace("test");
                stmt.SetSetName("testusers");
                stmt.SetIndexName("tweetcountindex");
                stmt.SetFilters(Filter.Range("tweetcount", min, max));

                rs = client.QueryAggregate(null, stmt, "aggregationByRegion", "sum");

                if (rs.Next())
                {
                    Dictionary <object, object> result = (Dictionary <object, object>)rs.Object;

                    Console.WriteLine("Here's the breakdown...\n");
                    Console.WriteLine("Total Users in North: " + result["n"]);
                    Console.WriteLine("Total Users in South: " + result["s"]);
                    Console.WriteLine("Total Users in East: " + result["e"]);
                    Console.WriteLine("Total Users in West: " + result["w"]);
                }
            }
            catch (AerospikeException e)
            {
                Console.WriteLine("AerospikeException - Message: " + e.Message);
                Console.WriteLine("AerospikeException - StackTrace: " + e.StackTrace);
            }
            finally
            {
                if (rs != null)
                {
                    // Close record set
                    rs.Close();
                }
            }
        } //aggregateUsersByTweetCountByRegion