Garnet技术实战测试开发:像使用Redis一样使用Garnet

一、Garnet简介

最近一段时间,看到非常多的文章描述和转发Garnet项目,比如说:

  1. .NET的集群Redis实现版本: Garnet – 一种开源、下一代 …
  2. Garnet发布 Redis不再是唯一选择 - Setli - 博客园
  3. Garnet: 力压Redis的C#高性能分布式存储数据库 - InCerry …
  4. 蓝点网:微软研究院开源Garnet缓存系统 具有高吞吐量低延迟可扩展等特点
  5. 系统极客:Microsoft 开源 Garnet:新一代远程缓存系统
  6. IT之家: 3 月 20 日消息,微软近日推出了名为 Garnet 的全新缓存存储系统
  7. MSDN:微软推出 Garnet 缓存存储系统:高吞吐量、低延迟、可扩展
  8. 新浪科技:微软开源性能遥遥领先的Garnet!开抢年入上亿美元Redis饭碗
  9. QQ新闻:微软发布开源缓存存储系统Garnet,提升大数据处理性能
  10. 中关村在线:微软开源Garnet缓存系统:性能超高

关于Garnet详细介绍,我这里就不在赘述了。
在这里插入图片描述
根据其官网的信息,我们来进行实战测试。
开源仓库地址:https://github.com/microsoft/garnet
文档地址:https://microsoft.github.io/garnet/

二、部署Garnet Server

1、从GitHub仓库中Clone仓库到本地,然后编译构建项目。
在这里插入图片描述
本地编译无任何异常后,启用docker安装
2、查看docker-compose.yml和dockerfile文件内容

version: '3.4'

services:
  garnet:
    restart: always
    image: garnet
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "3278:3278"
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /source

# Copy files
COPY . .
RUN dotnet restore
RUN dotnet build -c Release

# Copy and publish app and libraries
WORKDIR /source/main/GarnetServer
RUN dotnet publish -c Release -o /app --self-contained false -f net8.0

# Final stage/image
FROM mcr.microsoft.com/dotnet/runtime:8.0
WORKDIR /app
COPY --from=build /app .

# Run GarnetServer with an index size of 128MB
ENTRYPOINT ["/app/GarnetServer", "-i", "128m"]

3、通过docker指令安装&成功启动

docker-compose up

在这里插入图片描述
4、Image安装成功
查看Images
在这里插入图片描述
查看Containers
在这里插入图片描述

三、测试连接到Garnet

Garnet默认端口为3278。因为Garnet使用Redis的RESP协议作为其主要通信协议,因此可以使用大多数编程语言中现成的Redis客户端。这里我就使用常规的工具。
1、测试连接
在这里插入图片描述
2、测试写入键值对
在这里插入图片描述

四、C#开发连接Garnet

1、新建GarnetApp项目

dotnet new console -n "GarnetApp"

2、引入StackExchange.Redis库
在这里插入图片描述3、编写测试代码

using StackExchange.Redis;

namespace GarnetApp
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string garnetConnectionString = "localhost:3278"; // garnet 服务器地址

            // 建立连接
            ConnectionMultiplexer connection = ConnectionMultiplexer.Connect(garnetConnectionString);
            IDatabase garnet = connection.GetDatabase();

            // 写入数据
            garnet.StringSet("myKey", "Hello, Grant!");

            // 读取数据myKey
            string value = garnet.StringGet("myKey");
            Console.WriteLine(value);

            // 读取数据key01
            string value01 = garnet.StringGet("key01");
            Console.WriteLine(value01);

            connection.Close();

            Console.ReadKey();
        }
    }
}

4、运行查看测试结果
在这里插入图片描述

五、编写其他测试代码

1、将 C# 对象序列化为 JSON 或其他格式,并存储到 Garnet中,以及从 Garnet 中取出并反序列化对象。

private static void TestObject(IDatabase garnet)
{
    // 定义一个示例对象
    var person = new { Name = "Alice", Age = 30 };

    // 将对象序列化为 JSON
    string json = JsonConvert.SerializeObject(person);

    // 存储 JSON 数据到 garnet
    garnet.StringSet("person:1", json);

    // 从 garnet 中获取 JSON 数据
    string jsonFromgarnet = garnet.StringGet("person:1");

    // 将 JSON 数据反序列化为对象
    var personFromgarnet = JsonConvert.DeserializeObject<Person>(jsonFromgarnet);

    // 输出反序列化后的对象属性
    Console.WriteLine($"Name: {personFromgarnet.Name}, Age: {personFromgarnet.Age}");
}

在这里插入图片描述
2、常用的数据结构
列表(List):使用 Garnet 的列表数据结构实现消息队列或者简单的日志记录功能。

string garnetConnectionString = "localhost:3278"; // garnet 服务器地址
// 建立连接
ConnectionMultiplexer connection = ConnectionMultiplexer.Connect(garnetConnectionString);
IDatabase garnet = connection.GetDatabase();
// 向列表中推入消息
for (int i = 1; i <= 5; i++)
{
    garnet.ListLeftPush("message_queue", $"Message {i}");
}
// 从列表中弹出消息
string message = garnet.ListRightPop("message_queue");
Console.WriteLine("Popped message: " + message);
connection.Close();

在这里插入图片描述

六、关于Garnet Server的配置项

默认配置下内容如下:
在这里插入图片描述
官网解释基本用法:
Garnet 服务器(GarnetServer.exe)可以使用配置文件进行配置(例如,garnet.conf、redis.conf、defaults.conf),同时命令行参数可用于覆盖文件中指定的任何设置。未在配置文件或命令行参数中指定的任何设置将被设置为文件中指定的默认值(可以通过命令行参数覆盖此文件的路径)。

Garnet 目前支持两种配置文件格式:

  • garnet.conf 文件格式(默认)- 一组以 JSON 格式排列的设置
  • redis.conf 文件格式 - 以 Redis 配置文件格式排列的设置:
    keyword argument1 argument2 argument3 … argumentN

请参阅 Redis 文档以获取参考信息。重要提示:并非所有 redis.conf 关键字都受到 Garnet 的支持。为了实现完整的配置设置覆盖,请使用 garnet.conf 格式。

通过命令行参数可以指定配置文件路径(和默认文件路径)。

对于 garnet.conf:

GarnetServer.exe --config-import-path <file-path>

对于 redis.conf:

GarnetServer.exe --config-import-path <file-path> --config-import-format RedisConf

注意:要更改默认配置文件的路径(和/或格式),分别使用 config-default-import-path 和 config-default-import-format 关键字。

七、总结

本文关于如何使用Garnet 作为Server,以及使用大多数编程语言中现成的Redis客户端连接和使用StackExchange.Redis库连接,进行简单的测试和使用。如果本文对你有任何帮助,我将非常荣幸。

如果你喜欢我的文章,谢谢三连:关注、点赞、分享吧!!!

  • 34
    点赞
  • 54
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
摘要 全固态锂电池因其高能量密度、高安全性和长循环寿命等优点受到广泛关注。然而,其电化学性能仍存在一些问题,例如低离子导电性和缺乏活性材料。为了解决这些问题,本研究将石榴石作为掺杂材料,探究其对全固态锂电池电化学性能的影响。 采用固相法制备了Li7La3Zr2O12(LLZO)石榴石材料,通过XRD、SEM、TEM和EDS等技术对其进行了表征。结果表明,石榴石材料成功掺杂到LLZO电解质中,形成了LLZO-石榴石复合材料。石榴石的掺杂不仅未改变LLZO晶体结构和晶格参数,而且可以提高LLZO电解质的离子导电性。 采用LLZO-石榴石复合材料作为电解质,制备了全固态锂电池,并对其进行了电化学性能测试。结果表明,与未掺杂的LLZO电解质相比,掺杂石榴石的LLZO电解质具有更高的离子导电性和更好的电化学稳定性。此外,全固态锂电池的循环性能和放电容量也得到了显著提高。 本研究表明,掺杂石榴石可以有效提高全固态锂电池的电化学性能,具有很好的应用前景。 关键词:全固态锂电池;石榴石;离子导电性;电化学性能 Abstract Solid-state lithium batteries have attracted widespread attention due to their high energy density, high safety and long cycle life. However, there are still some problems with their electrochemical performance, such as low ion conductivity and lack of active materials. In order to solve these problems, this study explores the effect of garnet as a doping material on the electrochemical performance of solid-state lithium batteries. Li7La3Zr2O12 (LLZO) garnet material was prepared by solid-phase method, and was characterized by XRD, SEM, TEM and EDS. The results showed that the garnet material was successfully doped into the LLZO electrolyte, forming the LLZO-garnet composite material. The doping of garnet not only did not change the crystal structure and lattice parameters of LLZO, but also improved the ion conductivity of LLZO electrolyte. Using the LLZO-garnet composite material as the electrolyte, solid-state lithium batteries were prepared and their electrochemical performance was tested. The results showed that compared with the undoped LLZO electrolyte, the LLZO electrolyte doped with garnet had higher ion conductivity and better electrochemical stability. In addition, the cycle performance and discharge capacity of the solid-state lithium battery were also significantly improved. This study shows that doping garnet can effectively improve the electrochemical performance of solid-state lithium batteries, and has good application prospects. Keywords: Solid-state lithium battery; Garnet; Ion conductivity; Electrochemical performance 目录 第一章 绪论 1 1.1 研究背景和意义 1 1.2 研究现状 2 1.3 研究内容和方法 4 1.4 论文结构 5 第二章 实验部分 6 2.1 实验材料 6 2.2 实验方法 6 2.2.1 固相法制备LLZO石榴石材料 6 2.2.2 制备LLZO-石榴石复合材料 7 2.2.3 制备全固态锂电池 8 2.2.4 电化学性能测试 9 第三章 结果和讨论 10 3.1 表征结果 10 3.1.1 XRD分析 10 3.1.2 SEM和TEM分析 11 3.1.3 EDS分析 12 3.2 电化学性能测试结果 13 3.2.1 离子导电性测试 13 3.2.2 电化学稳定性测试 14 3.2.3 循环性能测试 15 3.2.4 放电容量测试 16 3.3 讨论 17 第四章 结论和展望 19 4.1 结论 19 4.2 展望 20 参考文献 21 附录 23 图表目录 表1 LLZO石榴石材料的晶体结构参数 11 表2 全固态锂电池的电化学性能 14 图1 LLZO石榴石材料的XRD谱图 10 图2 LLZO石榴石材料的SEM图像 11 图3 LLZO-石榴石复合材料的TEM图像 12 图4 全固态锂电池的离子导电性测试结果 13 图5 全固态锂电池的电化学稳定性测试结果 14 图6 全固态锂电池的循环性能测试结果 15 图7 全固态锂电池的放电容量测试结果 16 图8 石榴石掺杂对LLZO电解质离子导电性的影响 17 图9 石榴石掺杂对全固态锂电池电化学性能的影响 18

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小乖兽技术

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值