Redis Learning

来源:互联网 发布:淘宝店铺怎么查排名 编辑:程序博客网 时间:2024/06/08 17:17

应用场景:
redis 适用于小而热的数据

  • Redis应用场景
  • Redis作者谈Redis应用场景
    我们在应用redis的场景是 缓存
    将收到的post报文缓存下,然后批量插入redshift

github上的scala版redis client
官方推荐了好几款开源的scala 版客户端,都不知道选哪个比较好了,应该迅速读一遍scala 并发编程


Redis is an open source(BSD Licensed),in-memory data structure store,
used as a database,
cache,
and message broker.
It supports data structures such as strings,hashes,lists,sets,sorted sets with range queries,bitmaps,hyperloglogs and geospatial indexes with radius queries.
build-in:

  • replication
  • Lua scripting
  • LRU eviction
  • transaction
  • different levels of on-disk persistence
  • provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster.

    You can run atomic operations on these types, like appending to a string; incrementing the value in a hash; pushing an element to a list; computing set intersection, union and difference; or getting the member with highest ranking in a sorted set.

in-memory dataset:

In order to achieve its outstanding performance, Redis works with an in-memory dataset. Depending on your use case, you can persist it either by dumping the dataset to disk every once in a while, or by appending each command to a log. Persistence can be optionally disabled, if you just need a feature-rich, networked, in-memory cache.

no-blocking replication:

Redis also supports trivial-to-setup master-slave asynchronous replication, with very fast non-blocking first synchronization, auto-reconnection with partial resynchronization on net split.

transcation数据库事务
彻底搞懂事务

6379-为何Redis选择它作为默认端口号?
redis 使用服务器端/客户端架构的数据库架构
通过client去连接redis服务端

  • 我们可以通过redis-cli去连接redis数据库,这是学习测试redis最好的方法,这时redis-cli就是一个client
  • 之前连接关系型数据库一般都是通过JDBC的方式连接的,这个redis是怎么连接上去的我暂时还没有搞清楚,官方推荐了很多类似与sdk的工具库,使用这些库可以很方便的连接redis,

  • redis 持久化
    有两种方式做持久化,其一是RDB,定期备份数据库的状态;其二是AOF,记录数据库的相关命令
    优先使用AOF方式


使用list来存储数据,LPUSH mylist "1"
// BRPOP mylist 0 取出最先放入的元素,
每分钟生成一个key,同步数据只处理之前的key里面的数据
做一个事务,保证该元素处理的原子性
因为BRPOP 只能取出最后一个元素,所以应该使用BPOPLPUSH


原创粉丝点击