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 许可协议。转载请注明出处!
相关文章
Git command returns fatal error about the repository being owned by someone else
https://confluence.atlassian.com/bbkb/git-command-returns-fatal-error-about-the-repository-being-owned-by-someone-else-1167744132.html Summary When trying to execute a git command in a repository, suc
2023-03-20 · Git · 约 1 分钟
持续集成指南:GitHubAction 自动构建+部署AspNetCore项目
又一个无聊的自动化教程:GitHub Actions构建AspNetCore Docker镜像推送到阿里云,再用本地runner部署。简化workflow?谁在乎这些细节?代理配置太烦人。
2023-11-15 · DevOps · 约 1 分钟
浅谈次世代代码编辑器 Zed:Rust 原生性能、GPU 渲染
Zed?一群老司机在 Atom 失败后,用 Rust 重新造轮子?性能确实骚,GPU 渲染的丝滑感 VSCode 始终没学会。协作功能也挺有意思,但插件生态暂时还够看?
2026-03-25 · IDE · 约 1 分钟
你的SSH密钥可能已经过期了
SSH密钥过期?十年前还安全的RSA2048如今已摇摇欲坠,量子计算可不是开玩笑的。Ed25519才是正经货色,短小精悍还抗量子。别再拿祖传密钥当传家宝了,赶紧换上并设置个强密码。
2026-03-21 · SSH · 约 1 分钟
讨论
共 0 条加载评论中…