From cassandra-commits-return-6974-apmail-incubator-cassandra-commits-archive=incubator.apache.org@incubator.apache.org Tue Dec 01 23:52:23 2009 Return-Path: Delivered-To: apmail-incubator-cassandra-commits-archive@minotaur.apache.org Received: (qmail 74592 invoked from network); 1 Dec 2009 23:52:23 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 1 Dec 2009 23:52:23 -0000 Received: (qmail 70696 invoked by uid 500); 1 Dec 2009 23:52:23 -0000 Delivered-To: apmail-incubator-cassandra-commits-archive@incubator.apache.org Received: (qmail 70653 invoked by uid 500); 1 Dec 2009 23:52:23 -0000 Mailing-List: contact cassandra-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: cassandra-dev@incubator.apache.org Delivered-To: mailing list cassandra-commits@incubator.apache.org Received: (qmail 70643 invoked by uid 99); 1 Dec 2009 23:52:23 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Dec 2009 23:52:23 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.130] (HELO eos.apache.org) (140.211.11.130) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Dec 2009 23:52:14 +0000 Received: from eos.apache.org (localhost [127.0.0.1]) by eos.apache.org (Postfix) with ESMTP id 64EE216E07; Tue, 1 Dec 2009 23:51:53 +0000 (GMT) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Apache Wiki To: Apache Wiki Date: Tue, 01 Dec 2009 23:51:53 -0000 Message-ID: <20091201235153.14441.77051@eos.apache.org> Subject: =?utf-8?q?=5BCassandra_Wiki=5D_Update_of_=22ClientExamples=22_by_Jonathan?= =?utf-8?q?Ellis?= X-Virus-Checked: Checked by ClamAV on apache.org Dear Wiki user, You have subscribed to a wiki page or wiki category on "Cassandra Wiki" for= change notification. The "ClientExamples" page has been changed by JonathanEllis. The comment on this change is: add C# example from http://www.ridgway.co.za= /archive/2009/11/06/net-developers-guide-to-getting-started-with-cassandra.= aspx (with permission). http://wiki.apache.org/cassandra/ClientExamples?action=3Ddiff&rev1=3D36&rev= 2=3D37 -------------------------------------------------- main() }}} = + =3D=3D C# =3D=3D + {{{ + namespace CassandraDemo + { + using System; + using System.Collections.Generic; + using System.Diagnostics; + = + using Apache.Cassandra; + using Thrift.Protocol; + using Thrift.Transport; + = + class Program + { + static void Main(string[] args) + { + TTransport transport =3D new TSocket("localhost", 9160); + TProtocol protocol =3D new TBinaryProtocol(transport); + Cassandra.Client client =3D new Cassandra.Client(protocol); + = + Console.WriteLine("Opening connection"); + transport.Open(); + = + System.Text.Encoding utf8Encoding =3D System.Text.Encoding.UT= F8; + = + long timeStamp =3D DateTime.Now.Millisecond; + ColumnPath nameColumnPath =3D new ColumnPath() = + { = + Column_family =3D "Standard1"= , = + Column =3D utf8Encoding.GetBy= tes("name") + }; + = + Console.WriteLine("Inserting name columns"); + = + //Insert the data into the column 'name' + client.insert("Keyspace1", + "1", + nameColumnPath, + utf8Encoding.GetBytes("Joe Bloggs"), + timeStamp, + ConsistencyLevel.ONE); + = + client.insert("Keyspace1", + "2", + nameColumnPath, + utf8Encoding.GetBytes("Joe Soap"), + timeStamp, + ConsistencyLevel.ONE); + = + //Simple single value get using the key to get column 'name' + ColumnOrSuperColumn returnedColumn =3D client.get("Keyspace1"= , "1", nameColumnPath, ConsistencyLevel.ONE); + Console.WriteLine("Column Data in Keyspace1/Standard1: name: = {0}, value: {1}", + utf8Encoding.GetString(returnedColumn.Colum= n.Name), + utf8Encoding.GetString(returnedColumn.Colum= n.Value)); + = + Console.WriteLine("Getting splice range"); + = + //Read an entire row + SlicePredicate predicate =3D new SlicePredicate() + { + Slice_range =3D new SliceRange() + { + //Start and F= inish cannot be null + Start =3D new= byte[0], = + Finish =3D ne= w byte[0], + Count =3D 10, + Reversed =3D = false + } + }; + = + ColumnParent parent =3D new ColumnParent() { Column_family = =3D "Standard1" }; + Dictionary> results =3D cl= ient.multiget_slice("Keyspace1", = + new= List() { "1", "2"}, = + par= ent, = + pre= dicate, = + Con= sistencyLevel.ONE); + = + foreach (KeyValuePair> resu= ltPair in results) + { + Console.WriteLine("Key: {0}", resultPair.Key); + = + foreach (ColumnOrSuperColumn resultColumn in resultPair.V= alue) + { + Column column =3D resultColumn.Column; + Console.WriteLine("name: {0}, value: {1}", utf8Encodi= ng.GetString(column.Name), utf8Encoding.GetString(column.Value)); + } + } + = + Console.WriteLine("Closing connection"); + transport.Close(); + } + } + } + }}} + = =3D=3D Notes =3D=3D = The Cassandra.Client object is always sending its request to the same Cas= sandra node in the cluster. The server then determines if and where the req= uest should be routed to (Server-based routing). DNS Round Robin or a Cassa= ndra.Client object pool connected to several servers in the cluster can be = used to get higher throughput and availability.