?
幾家做seo無恥公司名單
?
http://www.byywee.com?
http://www.cosdiv.com
?
通過在自已網(wǎng)站加入別人網(wǎng)站連接,這種網(wǎng)站專門對新開通的網(wǎng)站做連接,從而達到宣傳他們目的,
?
http://www.renrenaj.com/about/copyright.html
1、下載Thrift
兩個文件:
2、獲取Thrift.dll
解壓后,找到源代碼:
thrift-0.7.0\lib\csharp\src,在Visual Studio中打開Thrift.csproj,重新編譯生成dll。
3、生成C#代碼
將thrift-0.7.0.exe復制到Cassandra安裝目錄的interface目錄中。
在命令提示符工具中進入interface目錄,執(zhí)行以下命令:
thrift-0.7.0.exe --gen csharp cassandra.thrift
完畢后會在這個目錄中生成一個文件夾:gen-csharp。
4、獲取Apache.Cassandra.dll
新建一個類庫項目,把這些文件加到這個項目中,編譯生成一個dll文件。
別忘了添加引用上邊生成的Thrift.dll文件。
5、編寫測試程序
在Visual Studio中創(chuàng)建一個項目,這里以用戶令牌為例,給出兩個方法:
(1)、插入數(shù)據(jù)
public string SetUserToken() { string keySpaceName = "UserTokenSpace"; string columnFamilyName = "UserToken"; string columnName = "Token"; string key = "1001"; string token = "we9g872m9f5l"; Encoding utf8Encoding = Encoding.UTF8; long timeStamp = DateTime.Now.Ticks; TTransport frameTransport = null; try { // 通過Thrift建立到Cassandra的連接 frameTransport = new TFramedTransport(new TSocket("localhost", 9160)); TProtocol protocol = new TBinaryProtocol(frameTransport); TProtocol frameProtocol = new TBinaryProtocol(frameTransport); Cassandra.Client client = new Cassandra.Client(protocol, frameProtocol); frameTransport.Open(); // 先刪除已經(jīng)創(chuàng)建的KeySpace,以便于測試 try { client.system_drop_keyspace(keySpaceName); } catch { } // KeySpace 定義 KsDef ks = new KsDef() { Name = keySpaceName, Replication_factor = 1, Strategy_class = "org.apache.cassandra.locator.SimpleStrategy", // Column Family 定義 Cf_defs = new List<CfDef>() { new CfDef(){ Name = columnFamilyName, Keyspace = keySpaceName, Comparator_type = "BytesType", // Column 定義 Column_metadata = new List<ColumnDef>(){ new ColumnDef(){ Index_name = columnName, Index_type = IndexType.KEYS, Name = utf8Encoding.GetBytes("Token"), Validation_class = "BytesType" } } } } }; // 添加KeySpace client.system_add_keyspace(ks); //設置當前KeySpace client.set_keyspace(keySpaceName); // 要插入數(shù)據(jù)的路徑 ColumnParent tokenColumnParent = new ColumnParent() { Column_family = columnFamilyName }; // 要插入數(shù)據(jù)的Column Column tokenColume = new Column() { Name = utf8Encoding.GetBytes(columnName), Value = utf8Encoding.GetBytes(token), Timestamp = timeStamp }; //插入數(shù)據(jù) client.insert(utf8Encoding.GetBytes(key), tokenColumnParent, tokenColume, ConsistencyLevel.ONE); } finally { if (frameTransport != null) { frameTransport.Close(); } } return token; }
(2)、獲取數(shù)據(jù)
public static string GetUserToken(string userId) { string keySpaceName = "UserTokenSpace"; string columnFamilyName = "UserToken"; string columnName = "Token"; System.Text.Encoding utf8Encoding = System.Text.Encoding.UTF8; long timeStamp = DateTime.Now.Millisecond; TTransport frameTransport = null; try { // 通過Thrift建立到Cassandra的連接 frameTransport = new TFramedTransport(new TSocket("localhost", 9160)); TProtocol protocol = new TBinaryProtocol(frameTransport); TProtocol frameProtocol = new TBinaryProtocol(frameTransport); Cassandra.Client client = new Cassandra.Client(protocol, frameProtocol); frameTransport.Open(); // 設置當前KeySpace client.set_keyspace(keySpaceName); // 查找路徑 ColumnPath nameColumnPath = new ColumnPath() { Column_family = columnFamilyName, Column = utf8Encoding.GetBytes(columnName) }; // 獲取Column ColumnOrSuperColumn returnedColumn = client.get(utf8Encoding.GetBytes(userId), nameColumnPath, ConsistencyLevel.ONE); return utf8Encoding.GetString(returnedColumn.Column.Value); } catch { } finally { // 別忘了關閉連接 if (frameTransport != null) { frameTransport.Close(); } } return string.Empty; }
?
使用ThriftAPI進行數(shù)據(jù)操作還是很繁瑣的,nosql的操作規(guī)范沒有sql那么好啊,不過效率肯定有保證。接下來的文章會介紹一些高級API的使用。
更多文章、技術交流、商務合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
