ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
db = redis.GetDatabase();
EndPoint ep = db.IdentifyEndpoint();
server = redis.GetServer(ep);
//Add Resid by Key-Value
RedisValue v = "a";
db.StringSet("stringKey", v);
Dictionary<RedisKey, RedisValue> dics = new Dictionary<RedisKey, RedisValue>() {
{"stringKeyA", "S_1"},
{"stringKeyB", "S_2"}
};
db.StringSet(dics.AsQueryable().ToArray(), When.Always, CommandFlags.None);
//Add to Resid by Set Value
RedisValue[] values = { "d", "e", "f" };
long size = db.SetAdd("SetKey", values);
IEnumerable<RedisValue> setvalue = db.SetScan("SetKey");
//Add to Redis by List Value
db.ListRightPush("ListKey", "abcdefghijklmnopqrstuvwxyz".Select(x => (RedisValue)x.ToString()).ToArray());
RedisValue[] listvalue = db.ListRange("ListKey", 0, -1);
//Key Confirm
foreach (RedisKey k in server.Keys()) {
MessageBox.Show(k.ToString());
}
2015년 6월 17일 수요일
Redis with StackExchange.Redis.StrongName(Sample Code)
라벨:
.NET Framework,
Redis
2014년 10월 23일 목요일
2014년 4월 22일 화요일
MMF 테스트
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading.Tasks;
using System.IO.MemoryMappedFiles;
using System.Diagnostics;
namespace MMFs {
class Program {
static void Main(string[] args) {
int SIZE = 1000000;
//Random rnd = new Random();
//double[] rndv = new double[SIZE];
//for(int i = 0; i < rndv.Length; i++) {
// rndv[i] = rnd.NextDouble() * 10000;
//}
//using(BinaryWriter swr = new BinaryWriter(new FileStream(@"c:\randomdata.data", FileMode.Create, FileAccess.Write))) {
// for(int i = 0; i < rndv.Length; i++) {
// swr.Write(rndv[i]);
// }
//}
double[] dbldata = new double[SIZE];
MemoryMappedFile mmf = MemoryMappedFile.CreateFromFile(@"c:\randomdata.data");
MemoryMappedViewAccessor access = mmf.CreateViewAccessor();
int sizedbl = sizeof(double);
int pos = 0;
for(int i = 0; i < SIZE; i++) {
double bucket = 0;
access.Read<double>(pos, out bucket);
pos += sizedbl;
dbldata[i] = bucket;
}
Stopwatch sw = Stopwatch.StartNew();
pos = 0;
for(int i = 0; i < SIZE; i++) {
double bucket = 0;
access.Read<double>(pos, out bucket);
pos += sizedbl;
dbldata[i] = bucket;
}
sw.Stop();
Console.WriteLine(sw.ElapsedMilliseconds + ", " + (1000 * 60) / sw.ElapsedMilliseconds);
Console.ReadLine();
}
}
}
라벨:
.NET Framework
2014년 3월 21일 금요일
INotifyPropertyChanged Test
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication6 {
public partial class UCtlCompA : UserControl,
INotifyPropertyChanged {
public UCtlCompA() {
InitializeComponent();
this.textBox2.DataBindings.Add("Text",
this,
"SumName",
false,
DataSourceUpdateMode.OnPropertyChanged);
}
private void txtTitle_TextChanged(object sender, EventArgs e) {
ProdName = txtTitle.Text;
SumName = ProdName + " / " + UserName;
}
private void textBox1_TextChanged(object sender,
EventArgs e) {
UserName = textBox1.Text;
SumName = ProdName + " / " + UserName;
}
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "") {
if (PropertyChanged != null) {
PropertyChanged(this,
new PropertyChangedEventArgs(propertyName));
}
}
public string ProdName {
get { return this._prodname; }
set {
if (value != this._prodname) {
this._prodname = value;
NotifyPropertyChanged();
}
}
}
public string UserName {
get { return this._username; }
set {
if (value != this._username) {
this._username = value;
NotifyPropertyChanged();
}
}
}
public string SumName {
get { return this._sumname; }
set {
if (value != this._sumname) {
this._sumname = value;
NotifyPropertyChanged();
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
private string _prodname = string.Empty;
private string _username = string.Empty;
private string _sumname = string.Empty;
}
}
라벨:
.NET Framework
2014년 3월 18일 화요일
.Net Framework SourceCode 살펴보기
어찌보면 MS는 대단한 대인배인 듯 하다.
물론 .net Reflactor 같은 것을 이용하면 되겠지만
남이 하는 거와 그냥 내 걸 볼 수 있게 아예 사이트를 만들어 놓는 건 좀 다른 듯 하다.
아무튼 .Net Framework의 소스를 쭉 살펴볼 수 있는 공식 사이트...
http://referencesource.microsoft.com/
물론 .net Reflactor 같은 것을 이용하면 되겠지만
남이 하는 거와 그냥 내 걸 볼 수 있게 아예 사이트를 만들어 놓는 건 좀 다른 듯 하다.
아무튼 .Net Framework의 소스를 쭉 살펴볼 수 있는 공식 사이트...
http://referencesource.microsoft.com/
라벨:
.NET Framework
2014년 3월 13일 목요일
Performance Profiler by RealProxy
http://vunvulearadu.blogspot.kr/2014/02/aop-using-realproxy-custom.html
위에서 제시된 코드를 기반으로(사실 똑같다)
내 손으로 다시 쳐서 구현해본 코드이다.
PostSharp보다 좀 불편해보이는 방식이긴 한데
Pre-Processing되는 PostSharp의 경우
간혹 불안정하게 동작하는 경우가 있고
이를 해결할 방법이 뾰족하게 없으나
이렇게 직접 코드를 작성하는 경우는
결국 안정성은 본인의 몫이기 때문에 잘만 한다면
PostSharp보다 나을도 있겠다 싶다.
물론 상용Tool인 PostSharp은 좋은 제품인 건 맞다.
위에서 제시된 코드를 기반으로(사실 똑같다)
내 손으로 다시 쳐서 구현해본 코드이다.
PostSharp보다 좀 불편해보이는 방식이긴 한데
Pre-Processing되는 PostSharp의 경우
간혹 불안정하게 동작하는 경우가 있고
이를 해결할 방법이 뾰족하게 없으나
이렇게 직접 코드를 작성하는 경우는
결국 안정성은 본인의 몫이기 때문에 잘만 한다면
PostSharp보다 나을도 있겠다 싶다.
물론 상용Tool인 PostSharp은 좋은 제품인 건 맞다.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.Remoting.Proxies;
using System.Runtime.Remoting.Messaging;
namespace AOPWithRealProxy {
class Program {
static void Main(string[] args) {
PerfProfilingDynamicProxy<itest> testProfiling
= new PerfProfilingDynamicProxy<itest>(new Test());
ITest test = (ITest)testProfiling.GetTransparentProxy();
test.TestMethod();
Console.ReadLine();
}
}
public class PerfProfilingDynamicProxy : RealProxy {
public PerfProfilingDynamicProxy(T decorated)
: base(typeof(T)) {
_decorated = decorated;
}
public override IMessage Invoke(IMessage msg) {
IMethodCallMessage methodcall = (IMethodCallMessage)msg;
MethodInfo methodInfo = methodcall.MethodBase as MethodInfo;
PerfProfilingAttribute profilingAttribute
= (PerfProfilingAttribute)methodInfo.GetCustomAttributes(typeof(PerfProfilingAttribute)).FirstOrDefault();
if(profilingAttribute == null) {
return NormalInvoke(methodInfo, methodcall);
}
else {
return ProfiledInvoke(methodInfo,
methodcall,
profilingAttribute.Message);
}
}
private IMessage NormalInvoke(MethodInfo methodInfo,
IMethodCallMessage methodCall) {
try {
var result = methodInfo.Invoke(_decorated, methodCall.InArgs);
return new ReturnMessage(result,
null,
0,
methodCall.LogicalCallContext,
methodCall);
}
catch(Exception err) {
return new ReturnMessage(err, methodCall);
}
}
private IMessage ProfiledInvoke(MethodInfo methodInfo,
IMethodCallMessage methodCall,
string attrMessage) {
Stopwatch sw = null;
try {
sw = Stopwatch.StartNew();
var result = methodInfo.Invoke(_decorated, methodCall.InArgs);
sw.Stop();
Console.WriteLine(sw.ElapsedMilliseconds);
long tick = sw.ElapsedTicks;
return new ReturnMessage(result,
new object[] { tick },
1,
methodCall.LogicalCallContext,
methodCall);
}
catch(Exception err) {
return new ReturnMessage(err, methodCall);
}
finally {
if(sw != null && sw.IsRunning) {
sw.Stop();
}
}
}
private readonly T _decorated;
}
public class PerfProfilingAttribute : Attribute {
public PerfProfilingAttribute(string message) {
Message = message;
}
public PerfProfilingAttribute() {
Message = string.Empty;
}
public string Message { get; set; }
}
public interface ITest {
[PerfProfiling]
DateTime TestMethod();
}
public class Test : ITest {
public DateTime TestMethod() {
double sumv = 0.0;
for(int i = 0; i < 100000; i++) {
Random rnd = new Random(575);
sumv += rnd.NextDouble();
}
return DateTime.Now;
}
}
}
라벨:
.NET Framework
2014년 3월 12일 수요일
2014년 3월 11일 화요일
Distributed Caching
http://msdn.microsoft.com/en-us/magazine/dd942840.aspx
실제 훌륭한 .Net용 Distributed Cache 솔루션을 가지고 있는
NCache사 사장 (사장이 이런 내용의 글을 쓰다니...,
우리가 알고 있는 그런 "관리의 사장"은 아닌 듯)
이 작성한 글이다.
딱 느낌이 많이 해본 솜씨...
실제로 이 부분을 작업하면서 항상 부딪쳤던 문제들인데
잘 정리해둔 것 같다.
특히 Caching Relational Data 부분은 미리 알았더라면
많은 수고를 들 수 있었던 부분이 아닌가 싶다.
실제 훌륭한 .Net용 Distributed Cache 솔루션을 가지고 있는
NCache사 사장 (사장이 이런 내용의 글을 쓰다니...,
우리가 알고 있는 그런 "관리의 사장"은 아닌 듯)
이 작성한 글이다.
딱 느낌이 많이 해본 솜씨...
실제로 이 부분을 작업하면서 항상 부딪쳤던 문제들인데
잘 정리해둔 것 같다.
특히 Caching Relational Data 부분은 미리 알았더라면
많은 수고를 들 수 있었던 부분이 아닌가 싶다.
라벨:
.NET Framework
2014년 3월 1일 토요일
.Net Reflector 대체제
앞선 글을 읽다보면 .net Reflector에 관련된 이야기가 나온다.
컴파일된 실행파일을 Decompiling해서 원래 소스코드로 전환해주는 프로그램으로
유명한 .net Reflector가 그것이다.
그런데 원래 Freeware였던 이 프로그램이 다른 상용업체(redgate)에 인수합병되면서
상용프로그램으로 변경되었다.
그리 비싸진 않지만(Standard : 95$, Pro 199$) 그래도 상용이다 보니 늘상 사용하는
경우가 아니면 구매하기 쉽지 않다.
적당한 대체제를 찾다보니 원하는 바를 딱 맞게 분석해놓은 글이 있다.
Alternative for .net Reflector
이 글에 따르면 IL Spy(http://wiki.sharpdevelop.net/ILSpy.ashx) 가
가장 적절한 대체제인 듯 하다.
실제로 IL Spy 사이트에 가서 받아사용해보니 적절하게 Decompiling 해주는 듯 하다.
물론 늘상 Decompiler를 사용하는 사람이라면 .Net Reflector를 이용하는 것이
바람직하겠지만 어쩌다 한번씩 사용하는 사람이라면 IL Spy를 사용하는 것도 괜찮을 듯 하다.
컴파일된 실행파일을 Decompiling해서 원래 소스코드로 전환해주는 프로그램으로
유명한 .net Reflector가 그것이다.
그런데 원래 Freeware였던 이 프로그램이 다른 상용업체(redgate)에 인수합병되면서
상용프로그램으로 변경되었다.
그리 비싸진 않지만(Standard : 95$, Pro 199$) 그래도 상용이다 보니 늘상 사용하는
경우가 아니면 구매하기 쉽지 않다.
적당한 대체제를 찾다보니 원하는 바를 딱 맞게 분석해놓은 글이 있다.
Alternative for .net Reflector
이 글에 따르면 IL Spy(http://wiki.sharpdevelop.net/ILSpy.ashx) 가
가장 적절한 대체제인 듯 하다.
실제로 IL Spy 사이트에 가서 받아사용해보니 적절하게 Decompiling 해주는 듯 하다.
물론 늘상 Decompiler를 사용하는 사람이라면 .Net Reflector를 이용하는 것이
바람직하겠지만 어쩌다 한번씩 사용하는 사람이라면 IL Spy를 사용하는 것도 괜찮을 듯 하다.
라벨:
.NET Framework
[.Net] StringBuilder 내부구조 변화
.net StringBuilder 내부구조가 변경되었나 보다.
StringBuilder 다시보기 (at SimpleIsBest.Net)
프로그래밍하다보면 제일 많이 사용하는 함수 중 하나가 이 함수이다.
그러고 보니 이 글이 작성되게 된 원인과 분석내용(아래)을 읽다보니
예전에 유사한 경우를 마주한 적이 있었던 기억이 난다.
.net의 StringBuilder가 너무해 by 미친병아리 (원인)
StringBuilder 에서의 OutOfMemoryException 오류 원인 분석 (분석)
결론적으로는 이제는 StringBuilder가 과다한 메모리를
순간적으로 사용하지는 않는다는 것,
그리고 여전히 StringBuilder 초기화 시점에 Capacity를 지정해주는 것이
바람직하다는 것이 되겠다.
StringBuilder 다시보기 (at SimpleIsBest.Net)
프로그래밍하다보면 제일 많이 사용하는 함수 중 하나가 이 함수이다.
그러고 보니 이 글이 작성되게 된 원인과 분석내용(아래)을 읽다보니
예전에 유사한 경우를 마주한 적이 있었던 기억이 난다.
.net의 StringBuilder가 너무해 by 미친병아리 (원인)
StringBuilder 에서의 OutOfMemoryException 오류 원인 분석 (분석)
결론적으로는 이제는 StringBuilder가 과다한 메모리를
순간적으로 사용하지는 않는다는 것,
그리고 여전히 StringBuilder 초기화 시점에 Capacity를 지정해주는 것이
바람직하다는 것이 되겠다.
라벨:
.NET Framework
피드 구독하기:
글 (Atom)