码迷,mamicode.com
首页 > 其他好文 > 详细

redis使用

时间:2018-03-28 20:30:48      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:否则   pen   microsoft   post   red   目录   soft   artifact   div   

1,下载

有两种方式:

直接下载编译好安装程序 :https://github.com/MicrosoftArchive/redis/releases
下载源码编译: https://github.com/MicrosoftArchive/redis

2,配置

安装程序可以把Redis安装成服务,3.2 之后有些新特性,需要设置,否则跨机器会连接不上。

安装目录下有两个配置文件,分别对应不同的运行方式
redis.windows.conf
redis.windows-service.conf

1)打开配置文件把下面对应的注释掉
# bind 127.0.0.1
2)保护模式
protected-mode no

3)Redis默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes启用守护进程,设置为no
daemonize no --可以不修改

3,使用

引入jedis-2.9.0.jar, commons-pool2.jar包

<dependency> 
    <groupId>org.apache.commons</groupId> 
    <artifactId>commons-pool2</artifactId> 
    <version>2.4.2</version> 
</dependency>

3.1 不能连接沲的用法

<bean id="Jedis" class="redis.clients.jedis.Jedis">
    <constructor-arg value="xxxx.xxxx.xxxx.xxxx"></constructor-arg>
</bean>
@Autowired private Jedis jedis;
jedis.lpush(key, value);

3.2 用连接沲的用法

<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
    <property name="maxIdle" value="300"/> <!--最大能够保持idel状态的对象数-->
    <property name="maxTotal" value="60000"/><!--最大分配的对象数-->
    <property name="testOnBorrow" value="true"/><!--当调用borrow Oject方法时,是否进行有效性检查-->
</bean>

<bean id="jedisPool" class="redis.clients.jedis.JedisPool">
    <constructor-arg index="0" ref="jedisPoolConfig"/>
    <constructor-arg index="1" value="xxxx.xxxx.xxxx.xxxx" type="String" />
    <constructor-arg index="2" value="6379" type="int"/>
</bean>
@Autowired private JedisPool jedisPool;
Jedis redis = jedisPool.getResource();    
String ID = redis.rpop(myBean.getCust_id());// 查询该机器中最早的一条指令
redis.close();

 

注意:要及时close以便释放资源。

简易教程:http://www.redis.net.cn/tutorial/3503.html

详情中文教程:http://www.redis.cn/

redis使用

标签:否则   pen   microsoft   post   red   目录   soft   artifact   div   

原文地址:https://www.cnblogs.com/season2009/p/8665696.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!