Getting Started with Redis

June 19, 2023


Installing Redis on Ubuntu

sudo apt-get update

sudo apt-get install redis-server

Start Redis

redis-server


Check if Redis is running

redis-cli

Commands (case insensitive)

Add: set ${key} $(value)

Query: get $(key)

Delete: del $(key)


Java integration with self-built redis sample

@SpringBootApplication
@RestController
public class RedisDemoApplication {
@Autowired
StringRedisTemplate stringRedisTemplate;

public static void main(String[] args) {
        SpringApplication.run(RedisDemoApplication.class, args);
    }

    @GetMapping("/hello")
    public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
        stringRedisTemplate.opsForValue().set("name", name);
        return String.format("Hello %s!", name);
    }

}

YMAL configuration

spring:
  redis:
    host: 127.0.0.1
    port: 6379
    password:
    timeout: 1000
    pool:
    max-active: 8
    max-wait: -1
    max-idle: 8
    min-idle: 0


Reference:

https://www.1ju.org/redis/redis-quick-guide

Redis official website:( http://www.redis.io/ )