[转帖]Redis configuration

redis,configuration · 浏览次数 : 0

小编点评

**Redis Configuration File (redis.conf)** A Redis configuration file is a text file that contains Redis configuration directives. It is used to specify the server's configuration, including the server address, port, maximum memory, and other parameters. **Key Concepts in the Configuration File:** * **Keywords:** Keywords are used to specify configuration settings. For example, `replicaof` specifies that a server should replicate data with another server. * **Arguments:** Arguments are used to specify values for keywords. For example, `replicaof 127.0.0.1 6380` specifies that a server should replicate data with another server at the IP address 127.0.0.1 and on the port 6380. * **Strings with Spaces:** Strings with spaces can be quoted using either single or double quotes. For example, the following are valid arguments: ``` requirepass \"hello world\" Single-quoted string can contain characters escaped by backslashes ``` **Using the Configuration File:** To use the configuration file, you can pass it to the `redis` command-line tool or set environment variables. For example: ``` redis server.conf ``` **Passing Arguments via Command Line:** You can also pass Redis configuration parameters using the `redis` command-line tool. For example: ``` redis -h 127.0.0.1:6380 server.conf ``` **On the Fly Configuration Change:** It is possible to reconfigure Redis on the fly without stopping and restarting the service. You can use the `CONFIG` commands to set or modify configuration settings. **Note:** The configuration file is loaded when the `redis` server starts. It is not affected by changes made to the server after it has started.

正文

https://redis.io/docs/management/config/

 

Overview of redis.conf, the Redis configuration file

Redis is able to start without a configuration file using a built-in default configuration, however this setup is only recommended for testing and development purposes.

The proper way to configure Redis is by providing a Redis configuration file, usually called redis.conf.

The redis.conf file contains a number of directives that have a very simple format:

keyword argument1 argument2 ... argumentN

This is an example of a configuration directive:

replicaof 127.0.0.1 6380

It is possible to provide strings containing spaces as arguments using (double or single) quotes, as in the following example:

requirepass "hello world"

Single-quoted string can contain characters escaped by backslashes, and double-quoted strings can additionally include any ASCII symbols encoded using backslashed hexadecimal notation "\xff".

The list of configuration directives, and their meaning and intended usage is available in the self documented example redis.conf shipped into the Redis distribution.

Passing arguments via the command line

You can also pass Redis configuration parameters using the command line directly. This is very useful for testing purposes. The following is an example that starts a new Redis instance using port 6380 as a replica of the instance running at 127.0.0.1 port 6379.

./redis-server --port 6380 --replicaof 127.0.0.1 6379

The format of the arguments passed via the command line is exactly the same as the one used in the redis.conf file, with the exception that the keyword is prefixed with --.

Note that internally this generates an in-memory temporary config file (possibly concatenating the config file passed by the user, if any) where arguments are translated into the format of redis.conf.

Changing Redis configuration while the server is running

It is possible to reconfigure Redis on the fly without stopping and restarting the service, or querying the current configuration programmatically using the special commands CONFIG SET and CONFIG GET.

Not all of the configuration directives are supported in this way, but most are supported as expected. Please refer to the CONFIG SET and CONFIG GET pages for more information.

Note that modifying the configuration on the fly has no effects on the redis.conf file so at the next restart of Redis the old configuration will be used instead.

Make sure to also modify the redis.conf file accordingly to the configuration you set using CONFIG SET. You can do it manually, or you can use CONFIG REWRITE, which will automatically scan your redis.conf file and update the fields which don't match the current configuration value. Fields non existing but set to the default value are not added. Comments inside your configuration file are retained.

Configuring Redis as a cache

If you plan to use Redis as a cache where every key will have an expire set, you may consider using the following configuration instead (assuming a max memory limit of 2 megabytes as an example):

maxmemory 2mb
maxmemory-policy allkeys-lru

In this configuration there is no need for the application to set a time to live for keys using the EXPIRE command (or equivalent) since all the keys will be evicted using an approximated LRU algorithm as long as we hit the 2 megabyte memory limit.

Basically, in this configuration Redis acts in a similar way to memcached. We have more extensive documentation about using Redis as an LRU cache here.

与[转帖]Redis configuration相似的内容:

[转帖]Redis configuration

https://redis.io/docs/management/config/ Overview of redis.conf, the Redis configuration file Redis is able to start without a configuration file usin

[转帖]Redis configuration

Redis configuration Redis可以仅使用内建的默认配置启动,而不需要指定配置文件。但是,这种启动仅推荐用于测试和开发。 对于配置Redis恰当的方式是提供一个Redis配置文件,通常叫做redis.conf。redis.conf包含大量的指令,格式如下: keyword argu

[转帖]Redis key 乱码问题(springboot)

保存到redis中的key 前半段会出现乱码问题 原来配置: @Configuration@EnableCachingpublic class RedisCacheConfig { @Bean public CacheManager cacheManager(RedisTemplate

[转帖]Redis 7 参数 修改 说明

2022-06-16 14:491800原创Redis 本文链接:https://www.cndba.cn/dave/article/108066 在之前的博客我们介绍了Redis 7 的安装和配置,如下: Linux 7.8 平台 Redis 7 安装并配置开机自启动 操作手册https://ww

[转帖]Redis 7.0 三节点哨兵(Sentinel)高可用 环境搭建手册

2022-06-17 16:253480原创Redis 本文链接:https://www.cndba.cn/dave/article/108088 1 哨兵高可用架构说明 Redis 最早的高可用方案是主从复制,但这种方案存在一个问题,就是当主库宕机后,从库不会自动切成主库,需要人工干预。 所有在主

[转帖]Redis 备份与恢复(RDB/AOF) 说明

2022-06-16 20:364580原创Redis 本文链接:https://www.cndba.cn/dave/article/108068 1 RDB 方式 1.1 RDB 备份恢复说明 Redis 的备份恢复有两种方法:RDB和AOF。 其中RDB 文件是一个经过压缩的二进制文件,有两个R

[转帖]Redis 性能优化的 13 条军规!史上最全

https://zhuanlan.zhihu.com/p/118532234 Redis性能优化实战方案 Redis 是基于单线程模型实现的,也就是 Redis 是使用一个线程来处理所有的客户端请求的,尽管 Redis 使用了非阻塞式 IO,并且对各种命令都做了优化(大部分命令操作时间复杂度都是 O

[转帖]Redis性能调优万字总结,面试必问!

https://zhuanlan.zhihu.com/p/541745804 于哥你好,最近面试挺多的,尤其是在问到java面试题,Redis被问的特别多,比如 Redis的内存模型? Redis的底层数据结构是怎么的? Redis的多线程模型 Redis的集群原理 Redis的雪崩,击穿,穿透怎么

[转帖]Redis连接未释放,造成TCP连接数过多

https://segmentfault.com/a/1190000022704886 早上看到服务器告警通知,TCP连接数比较高,达到5000多,我设置的阈值是5000,正常TCP连接不会这么高,这样的一个阈值我可以提前知道有问题早点解决,不至于后面引起一系列问题,甚至拖垮服务器。 排查 登陆服务

[转帖]Redis客户端Jedis、Lettuce、Redisson

https://www.jianshu.com/p/90a9e2eccd73 在SpringBoot2.x之后,原来使用的jedis被替换为了lettuce Jedis:采用的直连,BIO网络模型 Jedis有一个问题:多个线程使用一个连接的时候线程不安全。 解决思路是: 使用连接池,为每个请求创建