How to Allow Duplicate Fields when using HRANDFIELD in Redis

By default, Redis’s HRANDFIELD command returns distinct fields. In other words, it won’t return the same field multiple times – each field that’s returned by the command will only be returned once.

However, we can override this behaviour by using an negative count value for the count argument.

When we pass a negative count argument, the HRANDFIELD command allows non-distinct fields to be returned.

Continue reading

How to Reset a Sequence in SQL Server

In SQL Server, we can use sequences to generate sequence numbers that increment by a specified amount. This means that any new number generated by the sequence will be the next sequential increment as specified in the sequence’s definition.

Normally, this is exactly what we want. We want each number to adhere to the increment that we specified when defining the sequence.

But what if we want to reset the sequence, so that the numbering starts all over again? In other words, we want to restart the sequence from the beginning. Or what if we want to reset the sequence so that it increments in a different range?

Fortunately, we can reset a sequence with the ALTER SEQUENCE statement.

Continue reading

4 Ways to Clone a Table in MySQL

MySQL provides us with several ways to copy a database table. The method we use will depend on our requirements.

We can choose to copy the table, its data, and its indexes. Or we can copy just the table and data without the indexes. We can alternatively generate the code that will enable us to copy the table later.

Continue reading

Fix: “ERR wrong number of arguments for ‘smove’ command” in Redis

If you’re getting an error that reads “ERR wrong number of arguments for ‘smove’ command” in Redis, it’s because you’re calling the SMOVE command with the wrong number of arguments.

To fix this issue, make sure you’re passing the correct number of arguments. At the time of writing, the correct number of arguments for this command is three.

Continue reading