最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - redis.exceptions.ResponseError: MOVED error in redis set operation - Stack Overflow

programmeradmin2浏览0评论

I have created a Redis cluster with 30 instances (15 masters/ 15 nodes). With python code i connected to these instances, i found the masters and then i wanted to add some keys to them.

def settomasters(port, host):
    r = redis.Redis( host=host, port=port )
    r.set("key"+port,"value")

Error:

redis.exceptions.ResponseError: MOVED 12539 127.0.0.1:30012

If i try to set key from redis-cli -c -p portofmyinstance sometimes i get a redirection message that tells where the keys stored.

I know that in case of get requests for example, a smart client is needed in order to redirect the requests to the correct node (the node that holds the key) otherwise a moved error occurs. Is it the same situation? I need to catch the redis.exceptions.ResponseError and try to set again?

while True:
    try:
        r.set("key","value")
        break
    except:
        print "error"
        pass

My first try was above code but without solution. The set operation never succeeds.

On the other hand below code in javascript does not throw an error and i cannot figure the reason:

var redis = require('redis-stream'),
client = new redis(30001, '127.0.0.1');

// Open stream
var stream = client.stream();

// Example of setting 200 records
for(var record = 0; record <200; record++) {
    var mand = ['set', 'qwerty' + record, 'QWERTYUIOP'];  
    stream.redis.write( redis.parse(mand) );
}

stream.on('close', function () {
console.log('Completed!');
});

// Close the stream after batch insert
stream.end();

Any help will be appreciated, thanks.

I have created a Redis cluster with 30 instances (15 masters/ 15 nodes). With python code i connected to these instances, i found the masters and then i wanted to add some keys to them.

def settomasters(port, host):
    r = redis.Redis( host=host, port=port )
    r.set("key"+port,"value")

Error:

redis.exceptions.ResponseError: MOVED 12539 127.0.0.1:30012

If i try to set key from redis-cli -c -p portofmyinstance sometimes i get a redirection message that tells where the keys stored.

I know that in case of get requests for example, a smart client is needed in order to redirect the requests to the correct node (the node that holds the key) otherwise a moved error occurs. Is it the same situation? I need to catch the redis.exceptions.ResponseError and try to set again?

while True:
    try:
        r.set("key","value")
        break
    except:
        print "error"
        pass

My first try was above code but without solution. The set operation never succeeds.

On the other hand below code in javascript does not throw an error and i cannot figure the reason:

var redis = require('redis-stream'),
client = new redis(30001, '127.0.0.1');

// Open stream
var stream = client.stream();

// Example of setting 200 records
for(var record = 0; record <200; record++) {
    var mand = ['set', 'qwerty' + record, 'QWERTYUIOP'];  
    stream.redis.write( redis.parse(mand) );
}

stream.on('close', function () {
console.log('Completed!');
});

// Close the stream after batch insert
stream.end();

Any help will be appreciated, thanks.

Share Improve this question asked Apr 4, 2017 at 13:07 e7lT2Pe7lT2P 1,9518 gold badges37 silver badges67 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 1

with a redis cluster you can use the normal redis client only if you "find for the certain key the slot that belongs and then the slots that each master serves. With this information i can set keys to the correct node without moved redirection errors." as @Antonis said. Otherwise you need http://redis-py-cluster.readthedocs.io/en/master/

发布评论

评论列表(0)

  1. 暂无评论