NoSQL专题

Redis安装

  Redis是开源的,的键 - 值数据存储服务器。它归于NoSQL数据库的key-value存储类别。不只是缓存服务器,而且是数据结构的服务器,因为它支持列表,集合,哈希和排序Set,有非常惊人的快速性能。

首先,从 from here 下载Redis。

$ wget http://redis.googlecode.com/files/redis-2.6.14.tar.gz

解压:

$ tar xzf redis-2.6.14.tar.gz /usr/ajduke/apps

构建:

$ cd /redis-2.6.14/src
$ make

测试:

make test

安装:

sudo  make install

检查版本信息

$ redis-server -v
Redis server v=2.6.14 sha=00000000:0 malloc=jemalloc-3.2.0 bits=64
$ redis-cli -v
redis-cli 2.6.14

启动Redis:

$ redis-server -h

如果没有规定参数,以-server启动,端口在6379 

指定端口:

$ redis-server --port 7793

使用指定配置:

$ redis-server /path/to/redis.conf

Redis CLI

启动cli:缺省连接6379

$redis-cli
redis 127.0.0.1:6379>

指定参数:

redis-cli -p
// in our case
$ redis-cli -p 5689
$redis 127.0.0.1:5689>

连接规定端口:

$redis-cli -h -p
// For e.g.
$redis-cli -h 192.68.0.116 -p 5263
$redis 192.168.0.116:5263>

一旦连接上得到提示,可以输入下面命令交互:

$ redis-cli
redis 127.0.0.1:6379> ping
PONG

redis 127.0.0.1:6379> info server
# Server
redis_version:2.6.14
redis_git_sha1:00000000
redis_git_dirty:0
redis_mode:standalone
os:Linux 3.8.0-27-generic x86_64
arch_bits:64
multiplexing_api:epoll
gcc_version:4.7.3
process_id:2700
run_id:ae48481c646364be1dc500cbbd7e4f9b415d78de
tcp_port:6379
uptime_in_seconds:5698
uptime_in_days:0
hz:10
lru_clock:1343599

redis 127.0.0.1:6379> time
1) "1376585153"
2) "935261"

redis 127.0.0.1:6379>

安装Redis作为一种服务:

$ cd /utils/
$ sudo ./install_server.sh
Welcome to the redis service installer
This script will help you easily set up a running redis server

Please select the redis port for this instance: [6379]
Selecting default: 6379

Please select the redis config file name [/etc/redis/6379.conf]
Selected default - /etc/redis/6379.conf

Please select the redis log filename [/var/log/redis_6379.log]
Selected default - /var/log/redis_6379.log

Please select the data directory for this instance [/var/lib/redis/6379]
Selected default - /var/lib/redis/6379

Please select the redis executable path [/usr/local/bin/redis-server]

s#^port [0-9]{4}$#port 6379#;s#^logfile .+$#logfile /var/log/redis_6379.log#;s#^dir .+$#dir /var/lib/redis/6379#;s#^pidfile .+$#pidfile /var/run/redis_6379.pid#;s#^daemonize no$#daemonize yes#;
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
update-rc.d: warning: /etc/init.d/redis_6379 missing LSB information
update-rc.d: see <http://wiki.debian.org/LSBInitScripts>
Adding system startup for /etc/init.d/redis_6379 ...
/etc/rc0.d/K20redis_6379 -> ../init.d/redis_6379
/etc/rc1.d/K20redis_6379 -> ../init.d/redis_6379
/etc/rc6.d/K20redis_6379 -> ../init.d/redis_6379
/etc/rc2.d/S20redis_6379 -> ../init.d/redis_6379
/etc/rc3.d/S20redis_6379 -> ../init.d/redis_6379
/etc/rc4.d/S20redis_6379 -> ../init.d/redis_6379
/etc/rc5.d/S20redis_6379 -> ../init.d/redis_6379
Success!
Starting Redis server...
Installation successful!

启动停止服务:

$ sudo service <redis_service_name> start
$ sudo service <redis_service_name> stop

 

介绍Redis数据结构hash

Redis Cluster快速安装指南

使用Spring Data + Redis实现缓存

基于Spring+redis实现pub/sub

猜你喜欢