- 浏览: 1149079 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (411)
- Java Foundation (41)
- AI/机器学习/数据挖掘/模式识别/自然语言处理/信息检索 (2)
- 云计算/NoSQL/数据分析 (11)
- Linux (13)
- Open Source (12)
- J2EE (52)
- Data Structures (4)
- other (10)
- Dev Error (41)
- Ajax/JS/JSP/HTML5 (47)
- Oracle (68)
- FLEX (19)
- Tools (19)
- 设计模式 (4)
- Database (12)
- SQL Server (9)
- 例子程序 (4)
- mysql (2)
- Web Services (4)
- 面试 (8)
- 嵌入式/移动开发 (18)
- 软件工程/UML (15)
- C/C++ (7)
- 架构Architecture/分布式Distributed (1)
最新评论
-
a535114641:
LZ你好, 用了这个方法后子页面里的JS方法就全不能用了呀
页面局部刷新的两种方式:form+iframe 和 ajax -
di1984HIT:
学习了,真不错,做个记号啊
Machine Learning -
赵师傅临死前:
我一台老机器,myeclipse9 + FB3.5 可以正常使 ...
myeclipse 10 安装 flash builder 4.6 -
Wu_Jiang:
触发时间在将来的某个时间 但是第一次触发的时间超出了失效时间, ...
Based on configured schedule, the given trigger will never fire. -
cylove007:
找了好久,顶你
Editable Select 可编辑select
Redis is a key-value store NoSQL database。
性能高的原因在于大部分数据都被放在内存中,所以你可以将它看成是个内存数据库。
Problems:
key一定是String类型,怎么能够按照一定顺序,输出database中所有的keys?(keys * 不能保证有序) list all keys in some order?
Redis Documentation:
http://redis.io/documentation
Redis, from the Ground Up:
http://blog.mjrusso.com/2010/10/17/redis-from-the-ground-up.html#heading_toc_j_5
A whirlwind tour of the next bigthing in NoSQL data storage:
http://www.scribd.com/doc/33531219/Redis-Presentation
Install & Configuration & redis.conf:
安装redis server的正确方式参考 - Redis Quick Start:
http://redis.io/topics/quickstart
redis.conf 2.6版本说明:
https://raw.github.com/antirez/redis/2.6/redis.conf
其他参考资料:
Redis Administration - http://redis.io/topics/admin
Redis CLI:
# 连接至远程 redis server $ redis-cli -h hostOfRemoteServer -p portOfRemoteServer
Redis Data Types:
http://redis.io/topics/data-types
A fifteen minute introduction to Redis data types:
http://redis.io/topics/data-types-intro
Redis是个key-value store,所有的redis里数据都是以key-value的形式存的,key是数据的唯一标示;key只能也只会是(Redis里的)String类型,即使你存的是int或其他,内部也是转成Strings存的,参见:
http://stackoverflow.com/questions/7973228/storing-integers-in-a-redis-ordered-set
但是有一点必须明确:redis中的String类型,其实是以字节数组的形式存的(Redis是C写的,使用C中的byte[]作为其String类型的存储形式),这保证了,redis的String类型是二进制安全(binary-safe)的,String本身是可以包含任意类型的数据的(因为任意的数据,在计算机世界里,都是可以转化为binary sequence的),比如一个图片,或者一个序列化之后的java对象(当然也可以是一个普通的字符串,如java中的String类型对象)。
在这里我们说的Redis Data Types,指的是key-value store中value的数据类型。Redis中key-value之value支持以下5种内置的数据类型:
String:如上所说,redis里的String类型是可以包含任意类型的数据的。
List:元素为String类型,并且有序的列表。redis的List数据类型是基于链表(Linked List)的,因为是基于链表的,所以其优点是插入和删除快,但缺点是定位和查找慢。
Set:元素为String类型,不可以重复,并且没有顺序的集合。
Sorted Set(zset):元素为String类型,不可以重复,但有顺序的集合。
Hash:value(redis key-value store之value)为Hash类型,其实就是value本身又是key-value pairs集合,内层键值对儿的数量最多可达2^32-1个。使用Hash类型,你可以实现类似下面的两层的key-value键值对儿映射关系:key:{subkey1:subvalue1;subkey2:subvalue2;...},其中任意的key、value都是String类型的;内层的二级key也不可以重复。看的出来,其实redis的Hash类型,对应的就是java里的Map类型。通过Hash类型,你可以实现简单的两层的对象模型,如:
#为了存储userId为1000的用户的信息,我们使用Hash类型,以user:1000为key,将该用户的基本信息存入作为value的“多个二级内层key-value pairs”里: HMSET user:1000 username antirez password P1pp0 age 34可以看出,String类型是redis数据结构的核心,其他的list、set、zset、hash,其内部的元素(hash是内部key和内部value),都还(一定)是String类型的。
“key-value store structure”之value如果是list、set、zset、hash数据类型:
key在其声明使用之初被创建(如果尚未存在);
反之,如果因为删除等操作(list:lrem/lpop/rpop、set:srem、zset:zrem、hash:hdel等)致使这4种数据结构的元素数为0(hash是内部键值对儿数目为0),则对应的key也将自动从database中删除。
Redis数据模型设计:
通过对redis数据类型的分析,可以看的出来,Redis的所谓数据类型其实比较简单,远远不能应付复杂的业务数据模型场景。复杂业务数据模型,使用redis的话,可以在其“key-value store structure”的key上做文章,使key有业务含义,如下面的这些例子:
A case study: Design and implementation of a simple Twitter clone using only the Redis key-value store as database and PHP:
http://redis.io/topics/twitter-clone
引用
INCR global:nextUserId => 1000 SET uid:1000:username antirez SET uid:1000:password p1pp0We use the global:nextUserId key in order to always get an unique ID for every new user. Then we use this unique ID to populate all the other keys holding our user data. This is a Design Pattern with key-values stores! Keep it in mind.
http://doc.open-open.com/view/952fa31a0aa346ee9ccbe1d0b90632b6
Complex data structures Redis:
http://stackoverflow.com/questions/8810036/complex-data-structures-redis
Data modeling practices in Redis?
http://stackoverflow.com/questions/4908197/data-modeling-practices-in-redis
引用
Fundamentally Redis is a data structure server. How you structure your data depends almost entirely on what it is and how you need to access it。
Designing for Redis in my experience is more along the lines of "how simple is my structure?". Can you model your data via hash? If so, use the hash commands in Redis. Do you need to combine sets and key-values or hashes? Then do it the same in redis. Essentially, assume you were not using a database. If you did it entirely within your programming language and in memory, how would you model your data? Odds are that is how you'd do it in Redis - or close enough to figure the rest out.
Designing for Redis in my experience is more along the lines of "how simple is my structure?". Can you model your data via hash? If so, use the hash commands in Redis. Do you need to combine sets and key-values or hashes? Then do it the same in redis. Essentially, assume you were not using a database. If you did it entirely within your programming language and in memory, how would you model your data? Odds are that is how you'd do it in Redis - or close enough to figure the rest out.
Redis Server & instances & Databases:
一个运行中的Redis Server,就是一个Redis instance;每个Redis instance都和一个特定的host:port绑定;一个Redis instance中,可以有多个database;database的数目可以在redis.conf文件中指定,默认16个,使用0-based-index作为其唯一标示(默认的16个为0,1,...15);所有新的客户端连接,总是默认使用index为0的database(New connections always use DB 0)。
redis instance是单线程的,所以无法充分利用多核cpu的优势;如果你想充分利用多核的优势,你应该考虑启动多个redis instance。
引用
http://redis.io/topics/benchmarks
Redis is a single-threaded server. It is not designed to benefit from multiple CPU cores. People are supposed to launch several Redis instances to scale out on several cores if needed. It is not really fair to compare one single Redis instance to a multi-threaded data store.
Working with Multiple Databases:
Redis is a single-threaded server. It is not designed to benefit from multiple CPU cores. People are supposed to launch several Redis instances to scale out on several cores if needed. It is not really fair to compare one single Redis instance to a multi-threaded data store.
http://rediscookbook.org/multiple_databases.html
database相关命令:SELECT MOVE(注意move是把当前db的指定key移动到指定的db!而不是拷贝!当前db中不再有该key!) FLUSHDB FLUSHALL。
使用什么命令可以显示当前db的index?
没有提供这样的命令!
move只可以将当前db的单个key移至指定的另外一个db,怎么实现拷贝,而不是移动那?更进一步,怎么将一个database中所有的keys,或符合一定条件的keys,一次性全部拷贝入另一个database中?
Lock & Transaction & multi/exec/watch/discard:
http://redis.io/topics/transactions
Redis instance 的 single-threaded的特性,保证了每个基本命令都已经是原子性(atomic)的;假使多个client对一个Redis instance的同一个key做读取/处理,则因为redis instance是单线程的原因,当多个clienit出现了race conditions时,Redis instance是根据先到先处理的原则,其他排队等待(可设置为直接丢弃)。
但是,很多场景下,我们还是需要transaction,来保证让多个命令的组合被作为一个原子操作来执行。redis提供两种简单的锁机制:
1 multi & exec,这是一个悲观锁,被锁住的key将会无法再被其他client读取或写入;multi命令表征事务的开始,exec表示作为一个原子操作来执行multi和exec之间的命令组合;另外需要注意,与rdbms中事务不同的是,redis的锁机制下,如果事务中的某条命令执行失败,事务是不会回滚,只是将失败的命令丢弃掉,事务中的其他命令还是会被执行。
2 使用watch实现“Check and Set”(CAS) transactions(乐观锁):如果被watch的key在exec之前被修改了(可能是被其他的licents),则当前client的multi/exec间的事务被aborted。
引用
http://blog.mjrusso.com/2010/10/17/redis-from-the-ground-up.html#heading_toc_j_4
Redis transactions can be used to make a series of commands atomic. (Every Redis command is already atomic; transactions, however, allow us to combine a number of commands into a single atomic unit.)
MULTI delineates the start of a transaction block; EXEC is responsible for actually running the transaction (i.e., executing all commands between the MULTI and the EXEC, with no other commands executed in-between).
There is an important caveat: because the commands are queued and then executed sequentially (all at once, as if they were a single unit), it is not possible to read a value while a transaction is being executed and to then subsequently use this value at any point during the course of the same transaction.
To address this restriction, Redis supports “Check and Set” (CAS) transactions. CAS is available via the WATCH command.
Redis transactions can be used to make a series of commands atomic. (Every Redis command is already atomic; transactions, however, allow us to combine a number of commands into a single atomic unit.)
MULTI delineates the start of a transaction block; EXEC is responsible for actually running the transaction (i.e., executing all commands between the MULTI and the EXEC, with no other commands executed in-between).
There is an important caveat: because the commands are queued and then executed sequentially (all at once, as if they were a single unit), it is not possible to read a value while a transaction is being executed and to then subsequently use this value at any point during the course of the same transaction.
To address this restriction, Redis supports “Check and Set” (CAS) transactions. CAS is available via the WATCH command.
serialization & deserialization(java为例):
Commands:
http://redis.io/commands#
引用
set
get
setnx:SET-if-not-exists
del
INCR: atomically increment a number stored at a given key
EXPIRE: be sure a key-value pairs only exist for a certain length of time
格式:expire key secondNum 如:
TTL:time to live,test how long a key will exist。The -1 for the TTL of a particular key means that it will never expire. Note that if you SET a key, its TTL will reset.
使用list(A list is a series of ordered values)作为key的相关命令:
RPUSH puts the new value at the end of the list.
LPUSH puts the new value at the start of the list.
LLEN returns the current length of the list.
LRANGE gives a subset of the list. It takes the index of the first element you want to retrieve as its first parameter and the index of the last element you want to retrieve as its second parameter. A value of -1 for the second parameter means to retrieve all elements in the list.
LPOP removes the first element from the list and returns it.
RPOP removes the last element from the list and returns it.
使用set(each element in a set may only appear once)作为key的相关命令:
SADD adds the given value to the set.
SREM removes the given value from the set.
SISMEMBER tests if the given value is in the set.
SMEMBERS eturns a list of all the members of this set.
SUNION combines two or more sets and returns the list of all elements.
sorted set相关:
ZADD
ZRANGE
get
setnx:SET-if-not-exists
del
INCR: atomically increment a number stored at a given key
EXPIRE: be sure a key-value pairs only exist for a certain length of time
格式:expire key secondNum 如:
TTL:time to live,test how long a key will exist。The -1 for the TTL of a particular key means that it will never expire. Note that if you SET a key, its TTL will reset.
使用list(A list is a series of ordered values)作为key的相关命令:
RPUSH puts the new value at the end of the list.
LPUSH puts the new value at the start of the list.
LLEN returns the current length of the list.
LRANGE gives a subset of the list. It takes the index of the first element you want to retrieve as its first parameter and the index of the last element you want to retrieve as its second parameter. A value of -1 for the second parameter means to retrieve all elements in the list.
LPOP removes the first element from the list and returns it.
RPOP removes the last element from the list and returns it.
使用set(each element in a set may only appear once)作为key的相关命令:
SADD adds the given value to the set.
SREM removes the given value from the set.
SISMEMBER tests if the given value is in the set.
SMEMBERS eturns a list of all the members of this set.
SUNION combines two or more sets and returns the list of all elements.
sorted set相关:
ZADD
ZRANGE
Redis容错及灾难恢复:
一 Redis Persistence:
引用
http://redis.io/topics/persistence
redis提供两种持久化机制:
RDB:这是默认的持久化策略,默认的rdb文件名为dump.rdb。.rdb文件格式参考:
https://github.com/sripathikrishnan/redis-rdb-tools/wiki/Redis-RDB-Dump-File-Format
二 Redis master-slave Replication:
redis提供两种持久化机制:
RDB:这是默认的持久化策略,默认的rdb文件名为dump.rdb。.rdb文件格式参考:
https://github.com/sripathikrishnan/redis-rdb-tools/wiki/Redis-RDB-Dump-File-Format
引用
Redis *.rdb file is a binary representation of the in-memory store. This binary file is sufficient to completely restore Redis’ state
AOF: Append Only File。默认是关闭的,你可以通过将redis.conf中的“appendonly no”改为“appendonly yes”(或命令行下执行:config set appendonly yes)来开启该持久化机制;开启后aof文件的默认名字为appendonly.aofhttp://redis.io/topics/replication
srcs:
Redis几个认识误区:
http://timyang.net/data/redis-misunderstanding/
redis + java + nohm(node.js) 的一个例子:
http://www.ibm.com/developerworks/java/library/j-javadev2-22/index.html
发表评论
-
Database Table Partitioning
2013-04-09 11:58 1189http://en.wikipedia.org/wiki ... -
Scale-up(纵向扩展) vs Scale-out(横向扩展)
2013-04-08 14:56 3637Scale-up / Scale vertically / 纵 ... -
NOSQL 之 Document Database 之 MongoDB
2013-03-21 18:11 1309Official siste: http://www.mong ... -
Spring Batch: 大数据量批量并行处理框架
2013-01-11 16:19 4843Spring Batch Documentati ... -
Hadoop 异常 总结
2013-01-08 10:35 1180Directory /tmp/hadoop-lee/ ... -
NOSQL 之 Graph Database 之 neo4j
2012-12-28 11:31 1452The Neo4j Manual: http://doc ... -
Hadoop
2012-09-25 19:45 1235《Hadoop: The Definitive Guide》r ... -
海量数据 & Hadoop 面试题
2012-08-27 07:19 2558教你如何迅速秒杀99%的海量数据处理面试题 http://ww ... -
NOSQL
2012-08-23 15:45 1298NOSQL(Not Only SQL,不限于SQL)是一 ... -
云之前沿
2012-08-22 22:53 1861iaas, paas, saas: Google后Had ...
相关推荐
Redis(Remote Dictionary Server ),即远程字典服务,是一个开源的使用ANSI C语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API。其中有一个启动bat,启动后的端口号为6379
Redis(全称:Remote Dictionary Server 远程字典服务)是一个开源的使用ANSI C语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API。从2010年3月15日起,Redis的开发工作由...
redisRedis(Remote Dictionary Server)是一个开源的、使用ANSI C语言编写的、支持网络的、可基于内存亦可持久化的日志型Key-Value数据库,它提供了多种语言的API,并广泛应用于各种场景中。以下是关于Redis的详细...
Redis(Remote Dictionary Server ),即远程字典服务,是一个开源的使用ANSI C语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API
Redis,全称Remote Dictionary Server,是一款高性能的键值对存储系统,常被用作数据库、缓存和消息中间件。它的出现解决了传统缓存系统如Memcached的一些局限性,提供了丰富的数据结构支持,并且在性能上有着显著...
以下是对redis的介绍:Redis(Remote Dictionary Server ),即远程字典服务,是一个开源的使用ANSI C语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API。从2010年3月15日起...
它的全称是 Remote Dictionary Server,即远程字典服务,由意大利开发者 Salvatore Sanfilippo 创建。Redis 提供了丰富的数据结构,如字符串、哈希、列表、集合和有序集合,支持多种操作,并且具有持久化、主从复制...
Redis,全称Remote Dictionary Server,是一款高性能的键值对存储系统,常被用作数据库、缓存和消息中间件。本文将深入探讨Redis的安装、基本操作、核心原理以及高效数据处理的技巧。 首先,让我们从Redis的安装...
Redis(Remote Dictionary Server)是一个开源的、内存中的数据结构存储系统,它可以用作数据库、缓存和消息中间件。以下是一些学习Redis的基本步骤和要点: 了解Redis的基本概念和特性: Redis是一个基于内存的key...
Redis(Remote Dictionary Server ),即远程字典服务,是一个开源的使用ANSI C语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API。
Redis(Remote Dictionary Server)是一种基于键值对的数据存储服务,支持多种数据结构,如字符串、哈希、列表、集合和有序集合等。它以内存中的数据存储为主,同时支持定期或者按需将数据持久化到磁盘,确保数据的...
Redis(REmote DIctionary Server)是一个key-value存储系统,是当下互联网公司最常用的NoSQL数据库之一,是进入互联网行业的Java开发工程师必备技术。 在本课程中,你将了解Redis是什么、能干什么、如何用,了解...
Redis(Remote Dictionary Server,远程字典服务器)是一个开源的高性能键值对(key-value)数据库。它通常用作数据结构服务器,因为它支持多种类型的数据结构,如字符串(strings)、列表(lists)、集合(sets)、...
1.Redis(Remote Dictionary Server ),即远程字典服务,是一个开源的使用ANSI C语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API。 安装服务启动 @echo off cd /d %~dp0...
目前支持单机Redis和Redis Cluster模式Redis(Remote Dictionary Server)是一个开源的使用ANSI C语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API。1. Redis数据库完全在...
Redis 是 Remote Dictionary Server 的缩写,由意大利开发者 Salvatore Sanfilippo 创建。它是一个开源的、基于内存的、持久化的键值数据库,采用 ASCII 编码。Redis 使用单线程模型处理客户端的命令请求,通过事件...
Redis(REmote DIctionary Server)是一个key-value存储系统,是当下互联网公司最常用的NoSQL数据库之一,是进入互联网行业的Java开发工程师必备技术。 在本课程中,你将了解Redis是什么、能干什么、如何用,了解...
Redis源码解读,讲解Redis内部实现机制。...Redis(全称:Remote Dictionary Server 远程字典服务)是一个开源的使用ANSI C语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API