redisReply reply; redisContext c = redisConnect("127.0.0.1", 6379); reply = redisCommand(c, "cat redisMassDataLoader.txt | redis-cli --pipe");

this is my code and the text file (redisMassDataLoader.txt) contains, "*3\r\n$3\r\nSET\r\n$3\r\n123\r\n$5\r\n12345\r\n" after run this command it gives this Error: ERR unknown command 'cat' I'm using redis 2.6.12.

please help...

Comment From: antirez

Hello, this is about the hiredis library, not Redis itself, so I'm closing the issue.

Btw an hint: you can't use redisCommand() like that.

Comment From: charsyam

@subhash-rajapaksha hi guy. you used hiredis in a wrong way.

just use like this: reply = redisCommand(c, "*3\r\n$3\r\nSET\r\n$3\r\n123\r\n$5\r\n12345\r\n");

Comment From: subhash-rajapaksha

I need to load some what big MYSQL data table to REDIS memory from a C program. To test this I'm using hiredis libraries and a prototype text file which contains this line - "*3\r\n$3\r\nSET\r\n$3\r\n123\r\n$5\r\n12345\r\n". (got details from this link - http://redis.io/topics/mass-insert)

please give me a link for more information, sample code is preferred.

Thanks for sharing your knowledge....

This is the code i used which gives errors,

include

include

include

include

include "hiredis.h"

int main(void){

    redisReply *reply;
    long int i;

    //      Start measuring time
    clock_t start = clock();

    //      For local connections:
    redisContext *c = redisConnect("127.0.0.1", 6379);

    if (c->err) {
            printf("Error: %s\n", c->errstr);
    }else{
            printf("Connection Made! \n");
    }

    //      Get all keys for testing
    reply = redisCommand(c, "cat data.txt | redis-cli --pipe");

    if ( reply->type == REDIS_REPLY_ERROR )
            printf( "Error: %s\n", reply->str );
    else if ( reply->type == REDIS_REPLY_ARRAY )
            printf( "Unexpected type: %d\n", reply->type );
    else {
            printf( "Result:%lu: %s\n", i,reply->str );
    }

    printf( "Total Number of Results: %lu\n", i );
    //      Output Elapsed time
    printf ( "%f Seconds\n", ( (double)clock() - start ) /CLOCKS_PER_SEC );

    freeReplyObject(reply);

}

Comment From: charsyam

@subhash-rajapaksha if you dump yourl mysql data to data.txt, you don't need to use hiredis just use redis-cli like this:

in shell: cat data.txt | redis-cli --pipe

but if you need to use hiredis. open data.txt and read each line, and execute redisCommand in loop.

Comment From: subhash-rajapaksha

1) Since my requirement is to do the data insertion automatically, i have to use a code and then i have go for hiredis.

And when reading the file line by line and executing the command, it will take extra time as mentioned in http://redis.io/topics/mass-insert (for round trip time for each execution with each reply)

2) in redis-cli, when the command "cat data.txt | redis-cli --pipe" is run, it gives ERR unknown command 'cat' Don't know whether this is a configuration issue.

I'm totally new to Redis ans to hiredis.

AND THANKS FOR YOUR PROMPT REPLY

Comment From: badboy

@subhash-rajapaksha You seem to confuse things here. redis-cli is a command line tool to interact with redis. It features the --pipe mode to mass-insert data it reads from stdin. hiredis is the C library used internally. You can use it to directly send redis commands over the network. You cannot use it to execute shell commands.

So either you execute redis-cli and pipe the file in (you can do this from within C, too) or you read the file and call redisCommand as said above. To avoid the extra time this can cause use pipelining (a good start would be to read the code of redis-cli)

Comment From: subhash-rajapaksha

OK,

I have created a mass insertion prototype data file(text) which contains following data line.

*3\r\n$3\r\nSET\r\n$3\r\n123\r\n$5\r\n12345\r\n

then I tried to insert that data to redis memory in redis-cli using below command.

redis 127.0.0.1:6379> cat redisMassDataLoader.txt | redis-cli --pipe (error) ERR unknown command 'cat'

can somebody explain this then.

Comment From: badboy

Execute the cat file.txt | redis-cli --pipe on the shell, NOT IN redis-cli. You should really read a bit about how the shell, redis and the libraries involved work.

Comment From: subhash-rajapaksha

Finally got it.thanks a lot everybody... :-)

Comment From: HydTechie

With IP address the error is resolved, as below: cat dataload.txt | redis-cli -h -p -c --pipe

Without IP address this command says "cat" is unknown command.

Comment From: MilkTeaDrink

你真的懂了吗?

Comment From: vikramsalunkhe49

In the file, you can add values like the below and save that file student.txt

HMSET STUDENT:Id:123 ID "123" NAME"JONE DOE" HMSET STUDENT:Id:121 ID "121" NAME"JONE DOE1"

Now open the command prompt/terminal and hit the below command

cat student.txt | sed 's/$/\r/g' | redis-cli --pipe

  • If Redis have the password then hit the below command. cat student.txt | sed 's/$/\r/g' | redis-cli -a "password" --pipe