linux下相關redis命令 java
tar zxf redis-2.7.0.tar.gz
cd redis-2.7.0
make
安裝完畢。linux
mkdir /usr/local/redis
cd src
cp redis-server redis-benchmark redis-cli ../redis.conf /usr/local/redisweb
./redis-cli 客戶端連接 redis
/etc/init.d/redis status|start|stop| 查看狀態,啓動,中止spring
Redis配置文件(redis.conf)可在Redis的根目錄下找到。能夠經過Redis的CONFIG命令設置全部Redis的配置。服務器
進入客戶端後,命令 config get * 獲取全部的配置,maven
config set maxclients 1000 設置最大客戶端鏈接數,spa
config get maxclient 獲得最大客戶端鏈接數orm
maven redis依賴配置server
<sring-data-redis.version>1.5.0.RELEASE</sring-data-redis.version>
<jedis.version>2.6.2</jedis.version>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>${sring-data-redis.version}</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>${jedis.version}</version>
</dependency>
Spring相關配置
spring.redis.pool.host=10.13.0.179 redis服務器路徑
<!-- redis -->
<bean id="jedisConnFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="hostName" value="${spring.redis.pool.host}"/>
<property name="port" value="3333"/>
<property name="usePool" value="true"/>
</bean>
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="jedisConnFactory"/>
<property name="keySerializer">
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
</property>
<property name="valueSerializer">
<bean class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer"/>
</property>
<property name="hashKeySerializer">
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
</property>
<property name="hashValueSerializer">
<bean class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer"/>
</property>
</bean>
java實例代碼
@Autowired
private RedisTemplate<String,String> redisTemplate;
往redis裏添加一條鍵值對形式的數據,設置有效時間爲1分鐘。
redisTemplate.opsForValue().set(key, value, 1,TimeUnit.MINUTES);
redis採用隨機刪除方式,1分鐘之後並不必定會刪除該條數據,可是會標記該條記錄已無效。1分鐘後,經過get(key)方式獲取爲null,
redisTemplate.opsForValue().get(key);