redis brief

Redis is an open source, BSD licensed, advanced key-value store.
It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.

Installation
Download, extract and compile Redis with:
$ wget http://download.redis.io/releases/redis-2.8.9.tar.gz
$ tar xzf redis-2.8.9.tar.gz
$ cd redis-2.8.9
$ make

The binaries that are now compiled are available in the src directory. Run Redis with:
$ src/redis-server
You can interact with Redis using the built-in client:

$ src/redis-cli
redis> set foo bar
OK
redis> get foo
"bar"


The proper way to configure Redis is by providing a Redis configuration file, usually called redis.conf.

The following is an example that stats a new Redis instance using port 6380 as a slave of the instance running at 127.0.0.1 port 6379.
./redis-server --port 6380 --slaveof 127.0.0.1 6379

特点:
1, redis目前提供四种数据类型:string,list,set及zset(sorted set)
键值的数据类型决定了该键值支持的操作

Protocol
Redis 协议在以下三个目标之间进行折中:
易于实现
可以高效地被计算机分析(parse)
可以很容易地被人类读懂

客户端和服务器通过 TCP 连接来进行数据交互, 服务器默认的端口号为 6379 。
客户端和服务器发送的命令或数据一律以 \r\n (CRLF)结尾

Redis 服务器接受命令以及命令的参数。
服务器会在接到命令之后,对命令进行处理,并将命令的回复传送回客户端。

Persistence:

RDB 持久化可以在指定的时间间隔内生成数据集的时间点快照.

AOF 持久化记录服务器执行的所有写操作命令,并在服务器启动时,通过重新执行这些命令来还原数据集。

RDB 是一个非常紧凑(compact)的文件,它保存了 Redis 在某个时间点上的数据集。 这种文件非常适合用于进行备份.

AOF 文件是一个只进行追加操作的日志文件(append only log), 因此对 AOF 文件的写入不需要进行 seek , 即使日志因为某些原因而包含了未写入完整的命令,redis-check-aof 工具也可以轻易地修复这种问题。

使用 AOF 持久化可以设置不同的 fsync 策略,比如无 fsync ,每秒钟一次 fsync ,或者每次执行写入命令时 fsync 。

Redis 还可以同时使用 AOF 持久化和 RDB 持久化。

If you wish, you can disable persistence at all.


Replication: in order to set up master-slave replication
配置一个从服务器非常简单, 只要在配置文件中增加以下的这一行就可以了:
slaveof 192.168.1.1 6379 // 将192.168.1.1 和 6379 替换成主服务器的I 和端口

另外一种方法是调用 SLAVEOF 命令, 输入主服务器的 IP 和端口, 然后同步就会开始
127.0.0.1:6379> SLAVEOF 192.168.1.1 10086


redis-server.exe redis服务器启动程序
redis-cli.exe redis命令行操作工具
redis-benchmark.exe 性能测试
redis-check-dump.exe 本地数据库检查
redis-check-aof.exe 日志检查


安装 hiredis client库:
https://github.com/redis/hiredis
$unzip hiredis-master.zip
$cd hiredis-master
$make
$make install

#include "hiredis.h"
redisContext *c = redisConnect("127.0.0.1", 6379);
redisReply *reply = redisCommand(c, "keys %s", "*");
freeReplyObject(reply);

参考:
http://redis.readthedocs.org/en/latest/topic/protocol.html
http://www.cnblogs.com/zhoujie/archive/2013/05/19/redis1.html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值