![]() You can move an individual key to another database in your Redis instance with the move command. If the specified key doesn’t exist, type will return none instead. You can use randomkey to return a random key from the currently selected database: ![]() Some of these commands are reviewed in the following section. There are a number of Redis commands that are useful for managing keys regardless of what type of data they hold. For more information on how keys works, read our tutorial on How To Troubleshoot Issues in Redis. KEYS: Instead of providing a specific key to migrate, you can enter an empty string ( "") and then use the syntax from the keys command to migrate any key that matches a pattern.REPLACE: Specifies that if the key already exists on the destination, the migrate operation should delete and replace it.COPY: Specifies that the key should not be deleted from the source instance.Note that this isn’t a time limit for the operation, but means that the operation should always make some level of progress within the defined length of timeĪdditionally, migrate allows the following options which you can add after the timeout argument: A timeout, in milliseconds, which defines the maximum amount of idle communication time between the two machines.The database number where you want to store the key on the destination instance.The name of the key you want to migrate.The hostname or IP address of the destination database. ![]() When you run migrate, the command must include the following elements in this order: This command ensures the key exists on the target instance before deleting it from the source instance. If you want to move a key to a different Redis instance, you can run migrate. Swapdb will return OK if the swap is successful. The following example will swap the data held in database 6 with the data in database 8, and any clients connected to either database will be able to implement changes immediately: To swap all the data held in one database with the data held in another, use the swapdb command. If you’ve selected a database other than 0, it will be reflected in the redis-cli prompt: However, you can change the database you’re using with the select command after you connect: Redis databases are numbered from 0 to 15 and, by default, you connect to database 0 when you connect to your Redis instance. These databases are effectively siloed off from one another, and when you run a command in one database, it doesn’t affect any of the data stored in other databases in your Redis instance. Out of the box, a Redis instance supports 16 logical databases. Then, you must either install Redli or set up a TLS tunnel in order to connect to the Managed Database over TLS. To provision a DigitalOcean Managed Database, follow our Managed Databases product documentation. Note that if you’re using a different Redis interface - Redli, for example - the exact output of certain commands may differ.Īlternatively, you could provision a managed Redis database instance to test these commands, but depending on the level of control allowed by your database provider, some commands in this guide may not work as described. We will demonstrate how these commands behave by running them with redis-cli, the Redis command line interface. To set up a similar environment, you can follow Step 1 of our guide on How To Install and Secure Redis on Ubuntu 22.04. The commands shown in this guide were tested on an Ubuntu 22.04 server running Redis version 6.0.16. We encourage you to jump to any section that is relevant to the task you’re trying to complete. This guide is written as a cheat sheet with self-contained examples. In this tutorial, you will learn how to select a database, move keys between databases, and manage and delete keys. Any given Redis instance includes a number of databases, each of which can hold many different keys of a variety of data types. A key-value data store is a type of NoSQL database in which keys serve as unique identifiers for their associated values. Redis is an open-source, in-memory key-value data store.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |