????????????????
<p></p>
<p>??????????????redis???????????????????????????????????????base64????????????????ο?????????????</p>
<p></p>
<h1><a name="t3"></a>4.Java????redis</h1>
<p>redis??????????????????????????Java??</p>
<p>???????????redis??java????jedis.jar???????????????????<a target="_blank" href="http://download.csdn.net/detail/jmppok/6834151">redis??Java?????jedis</a></p>
<p>??????£?</p>
<p></p>
<pre code_snippet_id="151033" snippet_file_name="blog_20140110_4_2824204" name="code" class="java">Jedis jedis = new Jedis("192.168.150.135");
jedis.set("100"??"this is a test");
String data = jedis.get("100");
</pre><br>
<br>
<p></p>
<h1><a name="t4"></a>5.???????</h1>
<p>???????????redisд???1M??????????д10?Σ???10?Σ?????????????C++??Java?????汾???в????<br>
</p>
<h2><a name="t5"></a>C++???????</h2>
<p></p>
<pre code_snippet_id="151033" snippet_file_name="blog_20140110_5_8505805" name="code" class="cpp">#include <stdio.h>
#include "hiredis.h"
#include <string.h>
#include <time.h>
int main(int argc?? char **argv)
{
printf("CLOCKS_PER_SEC:%d "??CLOCKS_PER_SEC);
redisContext *c;
redisReply *reply;
c = redisConnect((char *)"one-60"??6379);
char * pData;
reply = (redisReply *)redisCommand(c??"GET 0");
int size = strlen(reply->str);
pData = new char[size+1];
strcpy(pData??reply->str);
freeReplyObject(reply);
clock_t start?? finish;
start = clock();
for(int i=0;i<10; i++)
{
reply = (redisReply *)redisCommand(c??"GET %d"??i);
freeReplyObject(reply);
}
finish = clock();
double duration = (double)(finish - start) / CLOCKS_PER_SEC*1000;
printf("GET Time used:%f ms. "??duration);
start = clock();
for(int i=0;i<10; i++)
{
reply = (redisReply *)redisCommand(c??"SET %d %s"??i??pData);
freeReplyObject(reply);
}
finish = clock();
duration = (double)(finish - start) / CLOCKS_PER_SEC*1000;
printf("SET Time used:%f ms. "??duration);
delete []pData;
redisFree(c);
}
</pre>??????
<p></p>
<p></p>
<pre code_snippet_id="151033" snippet_file_name="blog_20140110_6_1363508" name="code" class="plain">CLOCKS_PER_SEC:1000000
GET Time used:190.000000 ms.
SET Time used:70.000000 ms.
</pre><br>
<br>
<p></p>
<h2><a name="t6"></a>Java???????<br>
</h2>
<p></p>
<pre code_snippet_id="151033" snippet_file_name="blog_20140110_7_633160" name="code" class="java">import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.Date;
import redis.clients.jedis.Jedis;
public class JedisTest {
public static void main(String[] args)
{
Jedis jedis = new Jedis("10.100.211.232");
String f = "/tmp/e2.txt.backup";
try
{
File file = new File(f);
BufferedReader reader = new BufferedReader(new FileReader(file));
String data = reader.readLine();
reader.close();
Date start = new Date();
for(int i=0; i<10; i++)
{
jedis.set(i+""?? data);
}
Date end = new Date();
System.out.println("Set used(ms):"+(end.getTime()-start.getTime()));
start = new Date();
for(int i=0; i<10; i++)
{
String v = jedis.get(i+"");
}
end = new Date();
System.out.println("Get used(ms):"+(end.getTime()-start.getTime()));
}catch (Exception e)
{
e.printStackTrace();
}
jedis.disconnect();
}
}</pre><br>
??????????
<p></p>
<p></p>
<pre code_snippet_id="151033" snippet_file_name="blog_20140110_8_8615272" name="code" class="plain">Set used(ms):1212
Get used(ms):1437</pre><br>
????6.???
<p></p>
<p>redisЧ?????????????д1M?????????????????10ms?????<br>
</p>
<p><br>
</p>
<pre></pre>
<pre></pre>
</pre></pre></pre></pre></pre></pre>