通过R将大型数据帧存储在redis中

use*_*199 6 r redis dataframe

我在R中有许多大型数据帧,我打算用redis存储它们.我对redis完全不熟悉,但今天一直在阅读它,并一直在使用R包rredis.

我一直在玩小数据,并使用redisSet()redisGet()函数保存和检索小数据帧.但是,当使用代码保存我的较大数据帧(其中最大的数据为430万行,365MB保存为.RData文件)时,redisSet('bigDF', bigDF)我收到以下错误消息:

Error in doTryCatch(return(expr), name, parentenv, handler) : 
  ERR Protocol error: invalid bulk length
In addition: Warning messages:
1: In writeBin(v, con) : problem writing to connection
2: In writeBin(.raw("\r\n"), con) : problem writing to connection
Run Code Online (Sandbox Code Playgroud)

大概是因为数据帧太大而无法保存.我知道redisSet将数据帧写为字符串,这可能不是使用大型数据帧的最佳方法.有谁知道最好的方法吗?

编辑:我创建了一个非常大的虚拟数据框我重新创建了错误:

bigDF <- data.frame(
'lots' = rep('lots',40000000),
'of' = rep('of',40000000),
'data' = rep('data',40000000),
'here'=rep('here',40000000)
)
Run Code Online (Sandbox Code Playgroud)

跑步redisSet('bigDF',bigDF)给我错误:

 Error in .redisError("Invalid agrument") : Invalid agrument
Run Code Online (Sandbox Code Playgroud)

第一次,然后立即再次运行它我得到错误

Error in doTryCatch(return(expr), name, parentenv, handler) : 
  ERR Protocol error: invalid bulk length
In addition: Warning messages:
1: In writeBin(v, con) : problem writing to connection
2: In writeBin(.raw("\r\n"), con) : problem writing to connection
Run Code Online (Sandbox Code Playgroud)

谢谢

dar*_*zig 7

简而言之:你做不到.Redis可以在String值中存储最多512 Mb的数据,并且您的序列化演示数据框大于:

> length(serialize(bigDF, connection = NULL)) / 1024 / 1024
[1] 610.352
Run Code Online (Sandbox Code Playgroud)

技术背景:

serialize.cerealize在包的功能中调用via redisSetrredis:::.redisCmd:

> rredis:::.cerealize
function (value) 
{
    if (!is.raw(value)) 
        serialize(value, ascii = FALSE, connection = NULL)
    else value
}
<environment: namespace:rredis>
Run Code Online (Sandbox Code Playgroud)

Offtopic:为什么你会在redis中存储这么大的数据集呢?Redis适用于小键值对.另一方面,我通过在那里添加压缩作为附件,在CouchDBMongoDB(使用GridFS)中存储大R数据集取得了一些成功RData.