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 许可协议。转载请注明出处!
相关文章
漫步者HECATE G3Mpro鼠标开箱
漫步者HECATE G3Mpro,颜值在线,静音微动翻倍爽。三模切换?滚轮+后退键三秒搞定,比玄熊猫那破开关强多了。63g超轻,70H续航,天天用,真香。驱动简单,键盘手感稀烂?呵。
2025-10-28 · 鼠标 · 约 1 分钟
新盟M75-Pro键盘开箱
某人误选静音轴,手感如按棉花,反馈全无,真是失策。新盟M75-Pro屏幕精致,做工尚可,却因音量旋钮和键帽割手而减分,价格虽香,但轴体选择失误。
2025-10-28 · 键盘 · 约 1 分钟
项目完成小结-民政局项目-Django3.x版本-开发部署小结
前言 最近因为政企部门的工作失误,导致我们的项目差点挂掉,客户意见很大,然后我们只能被动进入007加班状态,忙得嗷嗷叫,直到今天才勉强把项目改完交付,是时候写一个小结。 技术 因为前期需求不明确,数据量不大,人手也不多,所以我直接用Django做了后端,Django自带的admin可以作为管理后台使用,可以很快完成这个需求。 我们的前端有两个,一个数据展示大屏,一个可视化地图。前者使用Vue+El
2022-04-25 · 项目开发小结系列 · 约 1 分钟
在Windows上将git与ssh-agent搭配使用
Windows git 还自带 ssh?真是老土的兼容性思路。一行配置就能解决,不过得先管好 ssh-agent 的连接。 ProxyCommand 居然又添乱,难怪老出毛病。
2025-08-21 · Windows · 约 1 分钟
讨论
共 0 条加载评论中…