??xml version="1.0" encoding="utf-8" standalone="yes"?>成人在线啊v,欧美大片va欧美在线播放,日韩a在线观看http://www.aygfsteel.com/stevenjohn/category/53002.html那些青春的岁?/description>zh-cnThu, 24 Sep 2015 12:57:26 GMTThu, 24 Sep 2015 12:57:26 GMT60Redis的三U启动方?/title><link>http://www.aygfsteel.com/stevenjohn/archive/2015/09/10/427258.html</link><dc:creator>abin</dc:creator><author>abin</author><pubDate>Thu, 10 Sep 2015 13:02:00 GMT</pubDate><guid>http://www.aygfsteel.com/stevenjohn/archive/2015/09/10/427258.html</guid><wfw:comment>http://www.aygfsteel.com/stevenjohn/comments/427258.html</wfw:comment><comments>http://www.aygfsteel.com/stevenjohn/archive/2015/09/10/427258.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/stevenjohn/comments/commentRss/427258.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/stevenjohn/services/trackbacks/427258.html</trackback:ping><description><![CDATA[W一U:直接启动<br />安装Q?br /><div>tar zxvf redis-2.8.9.tar.gz</div><div>cd redis-2.8.9</div><div>#直接make ~译</div><div>make</div><div>#可用root用户执行`make install`Q将可执行文件拷贝到/usr/local/bin目录下。这样就可以直接敲名字运行程序了?/div><div>make install</div><div></div>启动Q?br /><div>#加上`&`号redis以后台程序方式运?/div><div>./redis-server &</div>:<br /><div>#后台进E是否存?/div><div>ps -ef |grep redis</div><div></div><div>#?379端口是否在监?/div><div>netstat -lntp | grep 6379</div><div></div><div>#使用`redis-cli`客户端检连接是否正?/div><div>./redis-cli</div><div>127.0.0.1:6379> keys *</div><div>(empty list or set)</div><div>127.0.0.1:6379> set key "hello world"</div><div>OK</div><div>127.0.0.1:6379> get key</div><div>"hello world"</div><br />停止Q?br /><div>#使用客户?/div><div>redis-cli shutdown</div><div>#因ؓRedis可以妥善处理SIGTERM信号Q所以直接kill -9也是可以?/div><div>kill -9 PID</div><br /><br />W二U:通过指定配置文g启动<br /><br /><div>配置文g</div><div>可ؓredis服务启动指定配置文gQ配|文?redis.conf 在Redis根目录下?/div><div>#修改daemonize为yesQ即默认以后台程序方式运行(q记得前面手动?amp;号强制后台运行吗Q?/div><div>daemonize no</div><div>#可修攚w认监听端?/div><div>port 6379</div><div>#修改生成默认日志文g位置</div><div>logfile "/home/futeng/logs/redis.log"</div><div>#配置持久化文件存放位|?/div><div>dir /home/futeng/data/redisData<br /><br /></div><div>启动时指定配|文?/div><div>redis-server ./redis.conf</div><div>#如果更改了端口,使用`redis-cli`客户端连接时Q也需要指定端口,例如Q?/div><div>redis-cli -p 6380<br /></div><div>其他启停?直接启动 方式。配|文件是非常重要的配|工P随着使用的逐渐深入显得尤为重要,推荐在一开始就使用配置文g?/div><br /><br /><br />W三U:<br /><div>使用Redis启动脚本讄开启动</div><div>启动脚本</div><div></div><div>推荐在生产环境中使用启动脚本方式启动redis服务。启动脚?redis_init_script 位于位于Redis?/utils/ 目录下?/div><br /><div>#大致览下该启动脚本Q发现redis?fn)惯性用监听的端口名作ؓ配置文g{命名,我们后面也遵循这个约定?/div><div>#redis服务器监听的端口</div><div>REDISPORT=6379</div><div>#服务端所处位|,在make install后默认存放与`/usr/local/bin/redis-server`Q如果未make install则需要修改该路径Q下同?/div><div>EXEC=/usr/local/bin/redis-server</div><div>#客户端位|?/div><div>CLIEXEC=/usr/local/bin/redis-cli</div><div>#Redis的PID文g位置</div><div>PIDFILE=/var/run/redis_${REDISPORT}.pid</div><div>#配置文g位置Q需要修?/div><div>CONF="/etc/redis/${REDISPORT}.conf"</div><br /><div>配置环境</div><div></div><div>1. Ҏ(gu)启动脚本要求Q将修改好的配置文g以端口ؓ名复制一份到指定目录。需使用root用户?/div><div>mkdir /etc/redis</div><div>cp redis.conf /etc/redis/6379.conf</div><div> 2. 启动脚本复制到/etc/init.d目录下,本例启动脚本命名ؓredisdQ通常都以dl尾表示是后台自启动服务Q?/div><div>cp redis_init_script /etc/init.d/redisd</div><br /><div> 3.  讄为开启动</div><div></div><div>此处直接配置开启自启动 chkconfig redisd on 报错误Q?service redisd does not support chkconfig </div><div>参照 此篇文章 Q在启动脚本开头添加如下两行注释以修改其运行别:</div><div>#!/bin/sh</div><div># chkconfig:   2345 90 10</div><div># description:  Redis is a persistent key-value database</div><div>#</div><div> 再设|即可成功?/div><br /><br /><div>#讄为开启动服务?/div><div>chkconfig redisd on</div><div>#打开服务</div><div>service redisd start</div><div>#关闭服务</div><div>service redisd stop</div><br /><br /><div>http://www.tuicool.com/articles/aQbQ3u</div><br /><br /><br /><br /><br /><br /><br /><img src ="http://www.aygfsteel.com/stevenjohn/aggbug/427258.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/stevenjohn/" target="_blank">abin</a> 2015-09-10 21:02 <a href="http://www.aygfsteel.com/stevenjohn/archive/2015/09/10/427258.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>redis和memcached比较http://www.aygfsteel.com/stevenjohn/archive/2015/04/05/424127.htmlabinabinSat, 04 Apr 2015 21:45:00 GMThttp://www.aygfsteel.com/stevenjohn/archive/2015/04/05/424127.htmlhttp://www.aygfsteel.com/stevenjohn/comments/424127.htmlhttp://www.aygfsteel.com/stevenjohn/archive/2015/04/05/424127.html#Feedback0http://www.aygfsteel.com/stevenjohn/comments/commentRss/424127.htmlhttp://www.aygfsteel.com/stevenjohn/services/trackbacks/424127.html
    ׃Redis只用单核,而Memcached可以使用多核Q所以^均每一个核上Redis在存储小数据时比Memcached性能更高。而在100k以上的数据中QMemcached性能要高于RedisQ虽然Redis最q也在存储大数据的性能上进行优化,但是比v MemcachedQ还是稍有逊色?br />

因ؓ Redis 的操作都非常快?#8212;—它的数据全部在内存里Q完全不需要访问磁盘。至于ƈ发,Redis 使用多\ I/O 复用技术,本n的ƈ发效率不成问题?/p>

当然Q单?Redis q程没办法用多核(M时刻只能跑在一?CPU 核心上)Q但是它本来׃是非常计密集型的服务。如果单核性能不够用,可以多开几个q程?/p>

Redis 单线E?多\复用io模型

?div>2、内存用效率对比:
    使用单的key-value存储的话QMemcached的内存利用率更高Q而如果Redis采用hashl构来做key-value存储Q由于其l合式的压羃Q其内存利用率会高于Memcached?/div>
3、数据类型:
    Redis相比Memcached来说Q拥有更多的数据l构和ƈ支持更丰富的数据操作Q通常在Memcached 里,你需要将数据拿到客户端来q行cM的修改再set回去。这大大增加了网lIO的次数和数据体积。在Redis中,q些复杂的操作通常和一般的 GET/SET一样高效。所以,如果需要缓存能够支持更复杂的结构和操作Q那么Redis会是不错的选择?/div>
4、安全机?br />    memcached采用cas机制Q而redis有事务机制?br />5、事件模?br />    memcached采用了libevent事g模型Q多U程模型可以发挥多核作用QRedis实现了自q一套和libeventcM的事仉动机Ӟ两者都采用了epoll通信模型和非d机制?p>    epoll是在2.6内核中提出的Q是之前的select和poll的增强版本。相对于select和poll来说Qepoll更加灉|Q没有描q符限制。epoll使用一个文件描q符理多个描述W,用户关pȝ文g描述W的事g存放到内核的一个事件表中,q样在用L(fng)间和内核I间的copy只需一ơ?/p>
 最后讲?Z么epoll会比select高效Q主要从三方面来q行?
        Q?QelectҎ(gu)q符状态的改变是通过轮询来进行查扄Q而epoll是当描述W状态发生改变时dq行通知内核Q这是所谓的Reactor事g处理机制。可以用“好莱坞原?#8221;q行描述Q不要打?sh)话l我们,我们会打?sh)话通知你。相比之下,select的机制就好比面试l束后不停给面试官打?sh)话询问面试l果。效率孰高孰低,可见一 斑?
        
       Q?Qselect的文件描q符是用链表进行组l的Q而epoll是用红黑树(wi)q一高效数据l构l织的?
        
       Q?Qselect从内核到用户I间传递文件描q符上发送的信息是用内存复制的方式q行的;而epoll是采用共享内存的方式? 
6、内存管理方?/div>
  Memcached使用预分配的内存池的方式Q用slab和大不同的chunk来管理内存,ItemҎ(gu)大小选择合适的chunk存储Q内存池的方式可以省ȝ?释放内存的开销Qƈ且能减小内存片产生Q但q种方式也会带来一定程度上的空间浪费,q且在内存仍然有很大I间Ӟ新的数据也可能会被剔除,原因可以参考Timyang的文章:http://timyang.net/data/Memcached-lru-evictions/
  Redis使用现场甌内存的方式来存储数据Qƈ且很用free-list{方式来优化内存分配Q会在一定程度上存在内存片QRedis跟据存储命o参数Q会把带q期旉的数据单独存攑֜一Pq把它们UCؓ临时数据Q非临时数据是永q不会被剔除的,即便物理内存不够Q导致swap也不会剔除Q何非临时数据(但会试剔除部分临时数据)Q这点上Redis更适合作ؓ存储而不是cache?br />7、redisq发

Redis 是一个高性能的key-value数据库?redis的出玎ͼ很大E度补偿?a >memcachedq类keyvalue存储的不I在部 分场合可以对关系数据库v到很好的补充作用。它提供了PythonQRubyQErlangQPHP客户端,使用很方ѝ?/p>

性能试l果Q?/p>

SET操作每秒?110000 ơ,GET操作每秒?81000 ơ,服务器配|如下:

Linux 2.6, Xeon X3320 2.5Ghz.

stackoverflow |站使用 Redis 做ؓ~存服务器?/p>





abin 2015-04-05 05:45 发表评论
]]>spring redis整合(一)http://www.aygfsteel.com/stevenjohn/archive/2012/11/14/391344.htmlabinabinWed, 14 Nov 2012 15:17:00 GMThttp://www.aygfsteel.com/stevenjohn/archive/2012/11/14/391344.htmlhttp://www.aygfsteel.com/stevenjohn/comments/391344.htmlhttp://www.aygfsteel.com/stevenjohn/archive/2012/11/14/391344.html#Feedback2http://www.aygfsteel.com/stevenjohn/comments/commentRss/391344.htmlhttp://www.aygfsteel.com/stevenjohn/services/trackbacks/391344.html
http://www.springsource.org/download/community?project=Spring%2520Data%2520Redis&version=1.0.1.RELEASE


//spring-redis.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:oxm="http://www.springframework.org/schema/oxm"
xmlns:p="http://www.springframework.org/schema/p" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd  
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd  
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd  
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd">
<context:annotation-config />
<context:component-scan base-package="com.abin.lee.spring.redis"></context:component-scan>
<context:property-placeholder location="classpath:com/abin/lee/spring/redis/redis.properties" />
<!-- 对象池配|: -->
<bean
id="jedisPoolConfig"
class="redis.clients.jedis.JedisPoolConfig">
<property
name="maxActive"
value="${redis.pool.maxActive}" />
<property
name="maxIdle"
value="${redis.pool.maxIdle}" />
<property
name="maxWait"
value="${redis.pool.maxWait}" />
<property
name="testOnBorrow"
value="${redis.pool.testOnBorrow}" />
</bean>
<!-- 工厂实现Q?-->
<bean
id="jedisConnectionFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property
name="hostName"
value="${redis.ip}" />
<property
name="port"
value="${redis.port}" />
<property
name="poolConfig"
ref="jedisPoolConfig" />
</bean>
<!--模板c: -->
<bean
class="org.springframework.data.redis.core.RedisTemplate"
p:connection-factory-ref="jedisConnectionFactory" />
</beans>






//User.java
package com.abin.lee.spring.redis.pojo;
import java.io.Serializable;
public class User implements Serializable {
/**
*/
private static final long serialVersionUID = 2668307865623183776L;
private String uid;
private String address;
public User() {
super();
}
public User(String uid, String address) {
super();
this.uid = uid;
this.address = address;
}
public String getUid() {
return uid;
}
public void setUid(String uid) {
this.uid = uid;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
@Override
public String toString() {
return "User [uid=" + uid + ", address=" + address + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((address == null) ? 0 : address.hashCode());
result = prime * result + ((uid == null) ? 0 : uid.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
User other = (User) obj;
if (address == null) {
if (other.address != null)
return false;
} else if (!address.equals(other.address))
return false;
if (uid == null) {
if (other.uid != null)
return false;
} else if (!uid.equals(other.uid))
return false;
return true;
}
}






//UserDao.java
package com.abin.lee.spring.redis.dao;
import com.abin.lee.spring.redis.pojo.User;
public interface UserDao {
/**
* @param uid
* @param address
*/
void save(User user);
/**
* @param uid
* @return
*/
User read(String uid);
/**
* @param uid
*/
void delete(String uid);
}





//UserDaoImpl.java
package com.abin.lee.spring.redis.dao.impl;
import java.io.Serializable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Repository;
import com.abin.lee.spring.redis.dao.UserDao;
import com.abin.lee.spring.redis.pojo.User;
@Repository("userDao")
public class UserDaoImpl implements UserDao{
@Autowired
private RedisTemplate<Serializable, Serializable> redisTemplate;
@Override
public void save(final User user) {
redisTemplate.execute(new RedisCallback<Object>() {
@Override
public Object doInRedis(RedisConnection connection)
throws DataAccessException {
connection.set(
redisTemplate.getStringSerializer().serialize(
"user.uid." + user.getUid()),
redisTemplate.getStringSerializer().serialize(
user.getAddress()));
return null;
}
});
}
@Override
public User read(final String uid) {
return redisTemplate.execute(new RedisCallback<User>() {
@Override
public User doInRedis(RedisConnection connection)
throws DataAccessException {
byte[] key = redisTemplate.getStringSerializer().serialize(
"user.uid." + uid);
if (connection.exists(key)) {
byte[] value = connection.get(key);
String address = redisTemplate.getStringSerializer()
.deserialize(value);
User user = new User();
user.setAddress(address);
user.setUid(uid);
return user;
}
return null;
}
});
}
@Override
public void delete(final String uid) {
redisTemplate.execute(new RedisCallback<Object>() {
public Object doInRedis(RedisConnection connection) {
connection.del(redisTemplate.getStringSerializer().serialize(
"user.uid." + uid));
return null;
}
});
}
}


//UserDaoTest.java
package com.abin.lee.spring.redis.dao.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.abin.lee.spring.redis.dao.UserDao;
import com.abin.lee.spring.redis.pojo.User;
public class UserDaoTest {
private ApplicationContext app;
private UserDao userDao;
@Before
public void before() throws Exception {
app = new ClassPathXmlApplicationContext("com/abin/lee/spring/redis/spring-redis.xml");
userDao = (UserDao) app.getBean("userDao");
}
@Test
public void crud() {
// -------------- Create ---------------
String uid = "u123456";
String address1 = "上v";
User user = new User();
user.setAddress(address1);
user.setUid(uid);
userDao.save(user);
// ---------------Read ---------------
user = userDao.read(uid);
System.out.println("address1="+user.getAddress());
assertEquals(address1, user.getAddress());
// --------------Update ------------
String address2 = "北京";
user.setAddress(address2);
userDao.save(user);
user = userDao.read(uid);
System.out.println("address2Save="+user.getAddress());
assertEquals(address2, user.getAddress());
// --------------Delete ------------
userDao.delete(uid);
user = userDao.read(uid);
System.out.println("addressdel="+user.getAddress());
assertNull(user);
}
}







abin 2012-11-14 23:17 发表评论
]]>
Redis在windows下的安装使用 http://www.aygfsteel.com/stevenjohn/archive/2012/11/12/391227.htmlabinabinMon, 12 Nov 2012 12:45:00 GMThttp://www.aygfsteel.com/stevenjohn/archive/2012/11/12/391227.htmlhttp://www.aygfsteel.com/stevenjohn/comments/391227.htmlhttp://www.aygfsteel.com/stevenjohn/archive/2012/11/12/391227.html#Feedback0http://www.aygfsteel.com/stevenjohn/comments/commentRss/391227.htmlhttp://www.aygfsteel.com/stevenjohn/services/trackbacks/391227.html下蝲的windows版本是redis-2.0.2Q解压到D盘下Q?/p>

D:\redis-2.0.2


q到该目录下Q有下列文gQ?/p>

 redis-server.exeQ服务程?/p>

   redis-check-dump.exeQ本地数据库?/p>

   redis-check-aof.exeQ更新日志检?/p>

   redis-benchmark.exeQ性能试Q用以模拟同时由N个客L(fng)发送M?SETs/GETs 查询 (cM? Apache 的ab 工具).

启动Redis服务Qconf文g指定配置文gQ若不指定则默认Q:

D:\redis-2.0.2>redis-server.exe redis.conf



启动cmdH口要一直开着Q关闭后则Redis服务关闭?/p>

q时服务开启着Q另外开一个窗口进行,讄客户端:

D:\redis-2.0.2>redis-cli.exe -h 202.117.16.133 -p 6379

然后可以开始玩了:



--------------------------------------------------------------------------------------------------------------------------------

 

Redis提供了多U语a的客L(fng)Q包括JavaQC++Qpython?/p>

 

Redis官网上推荐的Java包是JedisQ去下蝲JedisQ在Java目中导入Jedis包,开始发现有错误Q是因ؓ~少org.apache.commonsq个包,

ȝ上找此包Q下载导入后QJedis没有错误了?/p>


可以开始了Q用Jedis来操作RedisQ?br />

package test;
import redis.clients.jedis.Jedis;
public class Client {
    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Jedis jj = new  Jedis("localhost");
        jj.set("key1", "I am value 1");
        String ss = jj.get("key1");
        System.out.println(ss);
    }
    
}



abin 2012-11-12 20:45 发表评论
]]>
windows下redis安装(一)http://www.aygfsteel.com/stevenjohn/archive/2012/11/12/391226.htmlabinabinMon, 12 Nov 2012 12:44:00 GMThttp://www.aygfsteel.com/stevenjohn/archive/2012/11/12/391226.htmlhttp://www.aygfsteel.com/stevenjohn/comments/391226.htmlhttp://www.aygfsteel.com/stevenjohn/archive/2012/11/12/391226.html#Feedback0http://www.aygfsteel.com/stevenjohn/comments/commentRss/391226.htmlhttp://www.aygfsteel.com/stevenjohn/services/trackbacks/391226.html

首先下蝲一个redis的安装包:

windows:http://code.google.com/p/servicestack/wiki/RedisWindowsDownload

linux:http://code.google.com/p/redis/downloads/list

redis-2.0.0版本: redis-2.4.5-win32-win64.zip (506)

解压?得到一个redis的文件夹,打开文g夹得到如下图的一些文?

安装包中是不提供redis.conf?关于配置可以到网上搜索一?或者从q里直接下蝲:

启动后的效果囑֦?

当前服务端没?个客L(fng)q接,因此昄0 clients,

现在分别启动两个客户?如下?

q里值得注意的是:当你dredis-cli.exe的时?服务端ƈ没有到客户端的存在,也就是在客户端执行了W一ơ操作以?服务端才到q个状?



















abin 2012-11-12 20:44 发表评论
]]>
վ֩ģ壺 ɽ| | | | ʱ| ˷| | | | ¡| | | ɽ| ½| ڶ| ˮ| ʡ| Խ| ʻ| | ̩| ˮ| | | | °Ͷ| | | | ˳| | | | | ͨ| ɽʡ| Ȫ| | Ӣ| | |