rgsync icon indicating copy to clipboard operation
rgsync copied to clipboard

Add support for skip history (write last state to sink)

Open gkorland opened this issue 4 years ago • 7 comments

In case when only the last key state is relevant we should be able to skip updates.

e.g.

HSET person:1 name v1
HSET person:1 name v2
HSET person:1 name v3

Only one call to the DB should sent

UPDATE person SET name = v3 WHERE id=1; 

gkorland avatar May 25 '20 12:05 gkorland

@gkorland could this be generalised as a feature of streams?

K-Jo avatar May 25 '20 16:05 K-Jo

Hi, is it possible to write only first key occurrence (in final database table) and dont' make a "REPLACE INTO" if a replicated key is inserted in redis? Thanks

mcazzador avatar Oct 18 '20 17:10 mcazzador

@mcazzador Theoretically, it's possible but requires some code changes, if you describe a little more the usecase and why you need it maybe we can come up with a solution.

MeirShpilraien avatar Oct 18 '20 17:10 MeirShpilraien

Hi, "REPLACE INTO" is not the best solution for me because i need to flag every DB records inserted on backend. REPLACE INTO in case of duplicate key (I want to protect myself from a possible case of this type without bloking error), erase my previous update fields. Maybe i can change REPLACE INTO with something like that:

INSERT INTO tablename (id, value...) VALUES('$id', '$value',....) ON DUPLICATE KEY UPDATE ....

I thought it was already implemented in the code.

mcazzador avatar Oct 18 '20 17:10 mcazzador

@mcazzador you can easily change the add query by inheriting the MySqlConnector (for example in case of mysql backend) and override def PrepereQueries(self, mappings): https://github.com/RedisGears/rgsync/blob/c16a7374b8a2b21b81503818a69dd57fd6108c8b/rgsync/Connectors/sql_connectors.py#L181 Then you can use your new connector as it was MySql connector.

Is this helps?

MeirShpilraien avatar Oct 18 '20 17:10 MeirShpilraien

Thank's a lot

mcazzador avatar Oct 18 '20 17:10 mcazzador

I do that, maybe it could be doing better, thanks

def GetUpdateQuery_noreplace(tableName, mappings, pk): query = 'INSERT INTO %s' % tableName values = [val for kk, val in mappings.items() if not kk.startswith('_')] values = [self.pk] + values values.sort() query = '%s(%s) values(%s) ON DUPLICATE KEY UPDATE %s=:%s' % (query, ','.join(values), ','.join([':%s' % a for a in values]),pk,pk) return query

mcazzador avatar Oct 26 '20 08:10 mcazzador