RedisStack Deployment/Persistence/Security/Integration with C# Projects
Docker deployment of RedisStack? Huh, just a basic operation. ACL permissions? Just a standard feature in Redis 6.0. C# integration? Using the official NRedisStack package, it's just one line of code.
目录8 个章节
Preface
Redis is really great—fast speed, supports many data types, and most importantly, it can now be used for vector search.
This article documents the deployment and configuration process of the officially provided redis-stack.
About redis-stack
redis-stack installs a Redis server with additional database capabilities and the RedisInsight.
Redis provides two images:
redis/redis-stackcontains both Redis Stack server and RedisInsight. This container is best for local development because you can use RedisInsight to visualize your data.redis/redis-stack-serverprovides Redis Stack but excludes RedisInsight. This container is best for production deployment.
The difference is whether RedisInsight, the web management interface, is included.
Since I need to use the web management interface, this article chooses the redis-stack image.
Deployment
As usual, deploy using docker-compose.
Map out Redis's port 6379 and RedisInsight's port 8001.
version: '3.4'
services:
redis:
image: redis/redis-stack:latest
container_name: redis-stack
restart: always
ports:
- "6379:6379"
- "8001:8001"
volumes:
- ./data:/data
networks:
default:
name: redis-stack
It is recommended to use Portainer for deploying and managing images.
Persistence here is achieved by mapping the dump.rdb file.
Security and ACL Commands
In versions of Redis prior to 6.0, logging into the Redis Server required only a password (assuming the requirepass configuration was set), without needing a username. Moreover, the password was stored in plaintext in the configuration file, offering limited security. Applications also used this same password to connect, granting them full permissions to manipulate data, which posed significant risks.
With the introduction of ACL (Access Control List) in Redis 6.0, these security concerns have been effectively addressed. It allows for the creation of different users with tailored permissions based on specific requirements.
Redis ACL is backward-compatible, meaning that by default, the user is default and uses the password configured with requirepass. If ACL functionality is not utilized, the behavior remains identical to older clients.
In RedisInsight, the Workbench interface provides a convenient way to execute Redis commands, and the command tutorial on the left side is incredibly cool!
A Few ACL Commands
ACL commands are straightforward, and they even have auto-completion in RedisInsight. Here's a brief introduction to a few of them:
acl help- Helpacl list- List all usersacl whoami- View the current useracl setuser- Set a user; this command is also used for setting passwords as needed
Set Password
Assuming you want to set the password for the default user to abc123
ACL SETUSER default on >abc123 sanitize-payload ~* &* +@all
If you no longer want the password, you can clear it with the following command
ACL SETUSER default on nopass sanitize-payload ~* &* +@all
Connect in the Program
Take C# as an example.
First, install the official nuget package.
dotnet add package NRedisStack
Demo code
using NRedisStack.RedisStackCommands;
using StackExchange.Redis;
var redis = await ConnectionMultiplexer.ConnectAsync("localhost", options => {
options.User = "default";
options.Password = "abc123";
});
var db = redis.GetDatabase();
var json = db.JSON();
// Write
json.Set("ext:1", "$", new { Age = 35, Name = "Alice" });
// Read
Console.WriteLine($"Read: {json.Get(key: "ext:1", path: "$", indent: "\t", newLine: "\n")}");
References
_EOF_
RedisStack Deployment/Persistence/Security/Integration with C# Projects
- 本文作者:
- 程序设计实验室
- 版权声明:
- 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
相关文章
Python中的三元表达式
一般语言的三元表达式都是这种形式: result = statement ? true : false // For examle result = a b ? a : b Python中的三元表达式比较特殊,用下面这种形式 result = true if statement else false # For example result = a if a b else b
2022-05-27 · Python · 约 1 分钟
Asp-Net-Core开发笔记:使用ActionFilterAttribute实现非侵入式的参数校验
用ActionFilterAttribute搞非侵入校验,省得重复写代码。支持Query、Body、Route、Header,HttpContext共享数据,但OAuth2.0边学边做,项目乱糟糟,功能凑合。
2024-05-17 · Asp-Net-Core开发笔记 · 约 1 分钟
我的2018:不念过往、不畏将来
刚刚手机提醒我剩余空间不足1%,打开Google的文件极客准备清理文件,这个时候突然意识到,2018年余额也已经不足1%了,那是时候写一波年度总结了。 单纯写「2018总结」,未免太单薄苍白了,所以把过去的这一年过了一遍,想到了齐白石的「不念过往,不畏将来」。稍稍翻阅了2018年的手帐和日记,我看到最多的字眼就是「熬夜」,其次是「生产力」,因此可以简单的概括一下我的2018,「前半年熬夜。后半年努
2022-11-07 · 2018 · 约 1 分钟
从细节入手改善用户体验,Flutter跨平台App开发中设置Android和iOS的启动页
前言 flutter开发App方便快捷,就是冷启动的时候要加载dart引擎有短暂的白屏,严重影响用户体验,这个时候我们就需要设置一个启动图片,像国内大部分App那样(例如微信那个地球),启动App的时候显示这个图片,加载完再进入App,不至于影响用户体验。 Android启动页 首先要准备好启动图,本文命名为splash.png,按照不同的分辨率添加到对应的mipmap-hdpi / mipmap
2021-12-18 · Flutter · 约 1 分钟
讨论
共 0 条加载评论中…