Read and Write sample on Cassandra by using Aquiles...
来源:互联网 发布:麻将app源码出售 编辑:程序博客网 时间:2024/05/22 11:36
1. You need set your config file. Web.config or App.config
<?xml version="1.0"?><configuration> <configSections> <section name="aquilesConfiguration" type="Aquiles.Core.Configuration.AquilesConfigurationSection,Aquiles.Core"/> </configSections> <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup> <aquilesConfiguration> <clusters> <add friendlyName="ImageCluster"> <connection poolType="SIZECONTROLLEDPOOL" factoryType="FRAMED"> </connection> <endpointManager type="ROUNDROBIN" defaultTimeout="6000"> <cassandraEndpoints> <add address="10.0.125.231" port="9160"/> <add address="10.0.125.232" port="9160"/> </cassandraEndpoints> </endpointManager> </add> </clusters> </aquilesConfiguration></configuration>
static void Insert(string strKey, string strVal) { byte[] key = ByteEncoderHelper.UTF8Encoder.ToByteArray(strKey); ColumnParent columnParent = new ColumnParent() { Column_family = "UserToken", }; // column1 Column column = new Column() { // Column name is you defined on your command Name = ByteEncoderHelper.UTF8Encoder.ToByteArray("MyColumnName"), Value = ByteEncoderHelper.UTF8Encoder.ToByteArray(strVal), Timestamp = UnixHelper.UnixTimestamp }; ICluster cluster = AquilesHelper.RetrieveCluster("ImageCluster"); cluster.Execute(new ExecutionBlock(delegate(Cassandra.Client client) { client.insert(key, columnParent, column, ConsistencyLevel.ONE); return null; }), "Ks1"); }
static string Read(string strKey) { byte[] key = ByteEncoderHelper.UTF8Encoder.ToByteArray(strKey); ColumnPath columnPath = new ColumnPath() { Column = ByteEncoderHelper.UTF8Encoder.ToByteArray("MyColumnName"), Column_family = "UserToken", }; ICluster cluster = AquilesHelper.RetrieveCluster("ImageCluster"); ColumnOrSuperColumn column = (ColumnOrSuperColumn)cluster.Execute(new ExecutionBlock(delegate(Cassandra.Client client) { return client.get(key, columnPath, ConsistencyLevel.QUORUM); }), "Ks1"); string str = ByteEncoderHelper.UTF8Encoder.FromByteArray(column.Column.Value); return str;}
static void Rmove(string strKey) { byte[] key = ByteEncoderHelper.UTF8Encoder.ToByteArray(strKey); ColumnPath columnPath = new ColumnPath() { Column_family = "UserToken", }; ICluster cluster = AquilesHelper.RetrieveCluster("ImageCluster"); cluster.Execute(new ExecutionBlock(delegate(Cassandra.Client client) { client.remove(key, columnPath, UnixHelper.UnixTimestamp, ConsistencyLevel.ONE); return null; }), "Ks1"); }
Before running this, you need create KeySpace and ColumnFamily firstly.....
Used Namespaces:
using Aquiles.Helpers.Encoders;using Apache.Cassandra;using Aquiles.Helpers;using Aquiles.Cassandra10;using Aquiles.Core.Cluster;
- Read and Write sample on Cassandra by using Aquiles...
- How To Read and Write BLOB Data by Using ADO.NET with Visual C# .NET
- How To Read and Write BLOB Data by Using ADO.NET with Visual C# .NET
- Read and write raw PCM using GStreamer
- CASSANDRA READ or write timeout
- Read and Write XML
- Read and Write Excel
- file read and write
- write and read
- read and write files
- Python read and write
- rapidjson的read和write的sample
- rapidjson的read和write的sample
- rapidjson的read和write的sample
- rapidjson的read和write的sample
- Create, Read, Write, Copy, Move and Delete a Text File using C# and VB.NET
- Read and write excel file with format by pandas and xlwt libraries of python
- Read and Write to a Keyboard device in Linux using C++
- 传智播客——毕向东25--第8天总结-7
- 外观模式(Façade Pattern)
- 如何编程判断构件相交?
- Linux环境进程间通信(一):管道及有名管道
- Redhat EN 6.0下安装项目管理软件redmine
- Read and Write sample on Cassandra by using Aquiles...
- ListView中存在ImageButton,无法单击 无法调用onItemClick
- js 字符串转换为数字
- box2d 遍历世界中body列表的2种方法
- SMDKV310 开发板使用
- C#中对Winform中的DataGridView的控制技巧。(单独控制某单元格的按钮不显示、某单元格的ReadOnly)
- 福布斯:Hadoop——你不得不了解的大数据工具
- B哥的一年
- Linux环境进程间通信(二): 信号