PostgreSQL has an extensive collection of built-in string functions that allow us to manipulate text values. One task we might want to perform is to extract a substring from a larger string. Fortunately, PostgreSQL caters for our needs with at least two functions that make this a breeze.
Continue readingTag: string
14 Commands that Set Strings in Redis
I thought I’d compile a list of Redis commands that can be used to set strings. Each command has its own specific use, and so the command used will depend on the situation.
In any case, here are 14 commands that set strings in Redis.
Continue reading7 Commands that Get the String Value from a Key in Redis
I decided to compile a list of commands that can be used to get the string value from a key in Redis. These are all string commands – commands that can be used when working with strings. In other words, the assumption is that the key holds a string value.
Continue readingHow to Get a Substring in Redis
If we have a key that holds a string value, we can use the GETRANGE
command to get a substring from that value.
Redis also has a SUBSTR
command that does the same thing, but that was deprecated in Redis 2.0.0, in favour of the GETRANGE
command.
How to Return a Key’s Value and Set its Expiry in a Single Operation in Redis
In Redis, typically when we want to return a key’s value, we use the GET
command. But there’s also a GETEX
command (introduced in Redis 6.2.0) that allows us to get the value and return it’s expiry at the same time.
6 Ways to Set a String in Redis
When working with Redis, we have a number of options for setting keys that store string values.
Here are six ways to set a string value in Redis.
Continue readingHow to Update a Key and Return its Old Value in a Single Operation in Redis
When using the SET
command to set a key in Redis, we can use the GET
option to return its old value. This allows us to update the value of a key while returning the value that we’re replacing it with.
Note that this option was introduced in Redis 7.0.0, so if it doesn’t work, check your Redis version. If using an earlier version, try the GETSET
command instead (which is deprecated from Redis version 6.2.0).
How to Get the Length of a String in Redis
In Redis, we can use the STRLEN
command to get the length of a given string value, based on its key.
We can also use the HSTRLEN
command to get the string length of a value stored in a hash.
How to Append a Value to a String in Redis
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.
How to Return Multiple Keys at Once in Redis
In Redis, the GET
command is typically used to return the value of a single key that holds a string. But what if we need the values from multiple keys?
We can use the MGET
command.