zoukankan      html  css  js  c++  java
  • Redis分布式缓存

    1, 背景

    使用GemfireCache缓存的话经常出现OOM的问题,因为GemfireCache内嵌在application中,而且有可能不同的application使用的是相同的数据,也就是说相同数据会重复放在好几个GemfireCache中,这对内存是一种浪费,所以需要将缓存从application中剥离出来。

    2, Gemfire vs Redis

    为了对比GemfireCahe 和 Redis, 我们使用GemfireCache(v8.2) 和 Redis(v3)建立了集群,并在其中存储了20万条数据进行增删改查,下面是性能比较,也对EHCache作了对比。

    Gemfire Cluster(ms)

    Redis Cluster(ms)

    Embedded EHCache(ms)

    Query by key

    113

    1

    31.6

    Save item

    111

    0.84

    0.15

    Update by key

    12

    3.1

    31.3

    Delete by key

    4

    1.9

    43.5

              Notes: Connection pool is enabled for Gemfire/Redis.

    3,Redis版本

    Redis约定次版本号(小数点后的数字)为偶数的版本是稳定版,如2.4, 2.6版本。技术版本为非稳定版,如2.5, 2.7版本

    4,启动Redis

    • 直接启动
    $ redis-server 

    默认段口号是6379

    也可以通过使用--port自定义段口号

    $ redis-server --port 6380
    • 通过初始化脚本启动(推荐用法)

    这是Redis源码目录utils文件夹中名为redis_init_script的初始化脚本:

    #!/bin/sh
    #
    # Simple Redis init.d script conceived to work on Linux systems
    # as it does use of the /proc filesystem.
    
    REDISPORT=6379
    EXEC=/usr/local/bin/redis-server
    CLIEXEC=/usr/local/bin/redis-cli
    
    PIDFILE=/var/run/redis_${REDISPORT}.pid
    CONF="/etc/redis/${REDISPORT}.conf"
    
    case "$1" in
        start)
            if [ -f $PIDFILE ]
            then
                    echo "$PIDFILE exists, process is already running or crashed"
            else
                    echo "Starting Redis server..."
                    $EXEC $CONF
            fi
            ;;
        stop)
            if [ ! -f $PIDFILE ]
            then
                    echo "$PIDFILE does not exist, process is not running"
            else
                    PID=$(cat $PIDFILE)
                    echo "Stopping ..."
                    $CLIEXEC -p $REDISPORT shutdown
                    while [ -x /proc/${PID} ]
                    do
                        echo "Waiting for Redis to shutdown ..."
                        sleep 1
                    done
                    echo "Redis stopped"
            fi
            ;;
        *)
            echo "Please use start or stop as first argument"
            ;;
    esac

    5, 轻量级Redis

    Redis是轻量级的,一个空Redis实例占用的内存只有1MB左右,所以不用担心多个Redis实例会额外占用很多内存。

  • 相关阅读:
    autopoi升级到4.0版本修改方法
    JeecgBoot的前端Form升级为FormModel用法(支持 v-model 绑定)
    如何设计一张带二维码的打印报表?
    低代码概念报表-JimuReport1.1.09 版本发布
    分组报表怎么做,积木报表十分钟搞定!
    JeecgBoot 2.4.2 积木报表版本发布,基于SpringBoot的低代码平台
    低代码开发是如何解决企业招聘技术人才难题?
    JimuReport积木报表1.1.05 版本发布,免费的企业级 Web 报表工具
    Docker安装elasticsearch 7.7.0
    Jeecg 文件上传漏洞补丁说明
  • 原文地址:https://www.cnblogs.com/IvySue/p/7535443.html
Copyright © 2011-2022 走看看