nosql

Redis的11种Web应用场景

…衆ロ難τιáo~ 提交于 2019-12-20 00:29:05
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 在 “怎样让Redis在你的系统中发挥作用”一文 中,Salvatore 'antirez’ Sanfilippo告诉我们如何利用Redis独有的数据结构处理能力来解决一些常见问题。一些Redis原语命令比如LPUSH、LTRIM和LREM等等能够用来帮助开发者完成需要的任务——这些任务在传统的数据库存储中非常困难或缓慢。这是一篇非常有用并且实际的文章。那么要如何在你的框架中完成这些任务呢? 下面列出11种Web应用场景,在这些场景下可以充分的利用Redis的特性,大大提高效率。 1.在主页中显示最新的项目列表。 Redis使用的是常驻内存的缓存,速度非常快。LPUSH用来插入一个内容ID,作为关键字存储在列表头部。LTRIM用来限制列表中的项目数最多为5000。如果用户需要的检索的数据量超越这个缓存容量,这时才需要把请求发送到数据库。 2.删除和过滤。 如果一篇文章被删除,可以使用LREM从缓存中彻底清除掉。 3.排行榜及相关问题。 排行榜(leader board)按照得分进行排序。ZADD命令可以直接实现这个功能,而ZREVRANGE命令可以用来按照得分来获取前100名的用户,ZRANK可以用来获取用户排名,非常直接而且操作容易。 4.按照用户投票和时间排序。 这就像Reddit的排行榜

Understanding the x-ms-resource-usage in DocumentDB response header

被刻印的时光 ゝ 提交于 2019-12-19 19:49:01
问题 While performing a simple Get operation by Id where a single document is returned (not an array with one document) I get the following x-ms-resource-usage: x-ms-resource-usage:documentSize:0;documentsSize:288;collectionSize=307; Questions: Why is documentSize 0? What is the unit of measure? Bytes? What is the difference between documentSize and documentsSize ? Please note the query only returns one document. What is the collectionSize ? Is that the total number of documents in the collection?

Understanding the x-ms-resource-usage in DocumentDB response header

吃可爱长大的小学妹 提交于 2019-12-19 19:48:24
问题 While performing a simple Get operation by Id where a single document is returned (not an array with one document) I get the following x-ms-resource-usage: x-ms-resource-usage:documentSize:0;documentsSize:288;collectionSize=307; Questions: Why is documentSize 0? What is the unit of measure? Bytes? What is the difference between documentSize and documentsSize ? Please note the query only returns one document. What is the collectionSize ? Is that the total number of documents in the collection?

ORDER BY with 2ndary indexes is not supported

送分小仙女□ 提交于 2019-12-19 18:39:13
问题 I am using cassandra 2.1 with latest CQL. Here is my table & indexes: CREATE TABLE mydata.chats_new ( id bigint, adid bigint, fromdemail text, fromemail text, fromjid text, messagebody text, messagedatetime text, messageid text, messagetype text, todemail text, toemail text, tojid text, PRIMARY KEY(messageid,messagedatetime) ); CREATE INDEX user_fromJid ON mydata.chats_new (fromjid); CREATE INDEX user_toJid ON mydata.chats_new (tojid); CREATE INDEX user_adid ON mydata.chats_new (adid); When i

NOSQL:Redis主从复制和哨兵服务

半城伤御伤魂 提交于 2019-12-19 15:38:05
文章目录 主从复制概述 主从复制结构模式 主从复制工作模式 配置主从复制 配置从库 反客为主 配置带验证的主从复制 哨兵服务 哨兵服务介绍 配置哨兵服务 主从复制概述 主从复制结构模式 结构模式 –一主一从 –一主多从 –主从从 主从复制工作模式 工作原理 –slave向master发送sync命令 –master启动后存盘进程,并收集所有修改数据命令 –master完成后台存盘后,传送整个数据文件到slave –slave接受数据文件,加载带内存中完成首次完全同步 –后续有新数据产生时,master继续收集数据修改命令依次传给slave,完成同步 配置主从复制 一主一从 master:192.168.4.51/24 slave:192.168.4.52/24 client:192.168.4.50 配置从库 redis服务器运行后,默认都是master服务器 192.168 .4 .52 : 6352 > info replication #查看复制信息 192.168 .4 .52 : 6352 > slaveof 192.168 .4 .51 6351 #临时指定master,重启redis失效 192.168 .4 .52 : 6352 > info replication #再次查看复制信息 192.168 .4 .52 : 6352 > 永久生效: vim / etc

How would you model a collection of users and friends in Firebase?

馋奶兔 提交于 2019-12-19 10:05:11
问题 I'm trying to create a database (json) with Firebase. I searched the docs and the net but couldn't find a clear way to start. I want to have a database of users. each user (represented as UID) should have a nickname and a list of friends. I tried making a .json file that looks like this: { users:{ } } and adding it to the Firebase console to get started but it wouldn't work. How can I do it? the database should look like this: { users:{ UID:{ nickname: hello friends: UID2 } UID2:{ nickname:

Reading an array in mongodb?

若如初见. 提交于 2019-12-19 09:27:57
问题 Hi I have some trouble with arrays in mongodb. To read a document with java is no problem but to read an array what is in a document is a problem. Lets say I have a collection myCol: {"name": "lenny linux", "gender": "m", "computers": [{"name": "computer"}, {"name": "computer2"} {"name"...}]} So there is an array with computers. I could read the whole document with DBCollection myCol = getCollection(...); BasicDBObject query = new BasicDBObject(); query.put(name, "lenny linux"); DBCursor

压箱底的干货!干货!——Redis面试系列(一)

浪尽此生 提交于 2019-12-19 07:59:54
一、什么是 Redis? Redis(Remote Dictionary Server) 是一个使用 C 语言编写的,开源的(BSD许可)高性能非关系型(NoSQL)的键值对数据库,可以存储键和五种不同类型的值之间的映射。键的类型只能为字符串,值支持五种数据类型:字符串、列表、集合、散列表、有序集合。 与传统数据库不同的是 Redis 的数据是存在内存中的,所以读写速度非常快,因此 redis 被广泛应用于缓存方向,每秒可以处理超过 10万次读写操作,是已知性能最快的Key-Value DB。另外,Redis 也经常用来做分布式锁。除此之外,Redis 支持事务 、持久化、LUA脚本、LRU驱动事件、多种集群方案。 Redis 是完全开源免费的,遵守 BSD 协议,是一个高性能的 key-value 数据库。 二、Redis 与其他 key - value 缓存产品有以下三个特点: (1)Redis 支持数据的持久化,可以将内存中的数据保存在磁盘中,重启的时候可以再次加载进行使用。 (2)Redis 不仅仅支持简单的 key-value 类型的数据,同时还提供 list,set,zset,hash 等数据结构的存储。 (3)Redis 支持数据的备份,即 master-slave 模式的数据备份。 三、Redis有哪些优缺点 优点 (1)性能极高 – Redis 能读的速度是

Should I be using mySQL or MongoDB [closed]

江枫思渺然 提交于 2019-12-19 06:40:15
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . There is alot of talk at the moment about NoSQL from my understanding Mongodb is one of them, to me the NoSQL seems that it is SQL

Dynamodb: query using more than two attributes

随声附和 提交于 2019-12-19 06:34:55
问题 In Dynamodb you need to specify in an index the attributes that can be used for making queries. How can I make a query using more than two attributes? Example using boto. Table.create('users', schema=[ HashKey('id') # defaults to STRING data_type ], throughput={ 'read': 5, 'write': 15, }, global_indexes=[ GlobalAllIndex('FirstnameTimeIndex', parts=[ HashKey('first_name'), RangeKey('creation_date', data_type=NUMBER), ], throughput={ 'read': 1, 'write': 1, }), GlobalAllIndex('LastnameTimeIndex'