美文网首页
高并发扩容之缓存

高并发扩容之缓存

作者: 磊_5d71 | 来源:发表于2018-11-05 17:03 被阅读0次
图片.png
图片.png

缓存

图片.png
图片.png 图片.png

缓存 Guava Cache

图片.png
图片.png
图片.png 图片.png
  • 学习redis网站 redis.cn

  • RedisConfig

package com.alan.concurrency.example.cache;


import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

@Configuration
public class RedisConfig {


    @Bean(name="redisPool")
    public JedisPool jedisPool(@Value("${jedis.host}") String host,
                               @Value("${jedis.port}") int port){

        return new JedisPool(host,port);
    }

}
  • RedisClient
package com.alan.concurrency.example.cache;


import org.springframework.stereotype.Component;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import javax.annotation.Resource;

@Component
public class RedisClient {


    @Resource(name="redisPool")
    private JedisPool jedisPool;


    public void set(String key,String value) throws Exception{

        Jedis jedis = null;

        try {
            jedis = jedisPool.getResource();
            jedis.set(key,value);

        } finally {

            if (jedis != null){
                jedis.close();
            }
        }
    }


    public String get(String key) throws Exception{
        Jedis jedis = null;

        try {
            jedis = jedisPool.getResource();
            return  jedis.get(key);

        } finally {

            if (jedis != null){
                jedis.close();
            }
        }

    }

}
  • CacheController
package com.alan.concurrency.example.cache;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/cache")
public class CacheController {


    @Autowired
    private RedisClient redisClient;


    @RequestMapping("/set")
    @ResponseBody
    public String set(@RequestParam("k") String k , @RequestParam("v") String v) throws  Exception{

        redisClient.set(k,v);
        return "SUCCESS";

    }


    @RequestMapping("/get")
    @ResponseBody
    public String get(@RequestParam("k") String k) throws  Exception{
         return  redisClient.get(k);

    }

}

高并发场景下缓存常见问题

图片.png 图片.png
图片.png 图片.png

相关文章

  • 高并发扩容之缓存

    缓存 缓存 Guava Cache 学习redis网站 redis.cn RedisConfig RedisCli...

  • (3)限流-削峰填谷<架构解决方案>

    高并发常规手段:扩容、静态化、限流、缓存、队列 概要:guava的RateLimit、Nginx + redis ...

  • 并发的解决场景

    1.高并发场景的解决方案1.1 扩容1.2 缓存(Redies Memache)1.3 消息队列 (kafak M...

  • 网站架构

    提升系统性能 扩容 加缓存来提升系统并发能力 使用队列进行流量削峰 异步并发机制提升吞吐量或者接口性能 高并发原则...

  • 13 高并发之扩容

    1️⃣为什么需要扩容 前面我们提到过每个线程都有自己的工作内存,占用内存的大小取决于工作内存里变量的多少与大小,单...

  • Java 高并发之扩容思路

    高并发处理扩容 扩容 什么是扩容, 什么时候要扩容. 了解Java 内存结构的伙伴应该都知道 , 每个线程都有自己...

  • 高并发与缓存

    本文主要讲述高并发下缓存会出现的问题。 在高并发下,缓存会出现的问题有:缓存一致性、并发问题、穿透问题、缓存的雪崩...

  • 高并发缓存架构:总览

    在高并发里面,缓存结构是不可避免的。 要搭建高可用,高并发的系统,需要一个复杂的缓存架构。 在高并发的时候,会遇到...

  • 14 高并发之缓存

    1️⃣缓存简介 在现在互联网的环境下,内容越来越复杂用户越来越多而服务的资源是有限的,数据库一定时间内能处理的请求...

  • Java 高并发之缓存

    Java并发编程与高并发解决方案 https://coding.imooc.com/class/195.html ...

网友评论

      本文标题:高并发扩容之缓存

      本文链接:https://www.haomeiwen.com/subject/rzxdxqtx.html