If we need to append a value to a string in Redis, we can use the APPEND command to do just that. All we need to do is call the command with the key name and the value to append.
2 Ways to Check if a Table has a Generated Column in PostgreSQL
PostgreSQL has supported generated columns since version 12. Generated columns can be created easily with the CREATE TABLE and ALTER TABLE statements.
We can check whether a table contains a generated column or not with the following methods.
Set an Expiry on an Existing Key in Redis, But Only When the Key Already Has an Expiry
When setting a timeout for a key in Redis, we have the option of setting it only if the key already has an expiry. So, if the key doesn’t already have an associated timeout, the new timeout won’t apply. The new timeout will only apply if the key already has an existing timeout. In such cases the expiry will be reset to the new expiry.
We can do this with the XX option of the EXPIRE command. We can also use the XX option on commands such as EXPIREAT, PEXPIRE, and PEXPIREAT.
Fix “cannot add a STORED column” in SQLite
If you’re trying to add a generated column in SQLite, and you’re getting the “cannot add a STORED column” error, it’s probably because you’re trying to add a stored column.
In SQLite, we can only add virtual columns to existing tables.
4 Ways to Increment a Key in Redis
In Redis, we have several options for incrementing a key. For example, if we set a key to 1, we can increment it by 1 to make 2. Or we can increment it by whatever amount we desire.
Below are four ways to increment a key in Redis.
Redis SUBSTR Equivalent
Many SQL databases have a SUBSTR() or equivalent function that returns a substring from a specified string.
Redis has a SUBSTR command, but it was deprecated in Redis 2.0.0.
However, Redis also has the GETRANGE command, that basically does the same thing. Basically, anything that was possible with the Redis SUBSTR command, is now possible with the GETRANGE command.
And the GETRANGE command does basically the same thing that most of the SUBSTR() and SUBSTRING() functions do in the SQL world – gets a substring from a string.
4 Ways to Return a Key’s Expiry in Redis
There are several ways to return a key’s expiry in Redis. The method used depends on how we want the expiry to be returned.
We can use the TTL command to return the timeout in seconds. We can alternatively use the PTTL command to return it in milliseconds. Another way to do it is to use the EXPIRETIME which returns the absolute Unix timestamp of the key in seconds, or the PEXPIRETIME command which returns the absolute Unix timestamp of the key in milliseconds.