Redis与Garnet性能比较
Redis环境
版本:7.2.4
Garnet环境
版本:v0.10.21 (.NET 8.0)
测试代码
import redis
import time
# 连接到Redis服务器
client = redis.Redis(host='localhost', port=6379, db=0)
# 测试写操作耗时
write_start_time = time.time()
for i in range(100000):
client.set(f'key{i}', f'value{i}')
write_end_time = time.time()
# 测试读操作耗时
read_start_time = time.time()
for i in range(100000):
value = client.get(f'key{i}')
read_end_time = time.time()
# 计算并输出耗时
write_duration = write_end_time - write_start_time
read_duration = read_end_time - read_start_time
print(f'Write 10,000 keys duration: {write_duration} seconds')
print(f'Read 10,000 keys duration: {read_duration} seconds')
# 平均耗时
average_write_time = write_duration / 100000
average_read_time = read_duration / 100000
print(f'Average write time: {average_write_time} seconds per write')
print(f'Average read time: {average_read_time} seconds per read')
测试结果
经过上方的代码测试Garnet
全方位碾压Redis
,但是为什么没人用Garnet
呢?