Redis Management

Redis Management in bereveal.com hosting panel
Redis is an open source, in-memory data structure store, used as a database, cache and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs and geospatial indexes with radius queries. Redis has built-in replication, Lua scripting, LRU eviction, transactions and different levels of on-disk persistence, and provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster. Many popular languages use Redis bindings, including: ActionScript, C, C++, C#,Java, JavaScript (Node.js), Perl, PHP, Pure Data, Python and Ruby.
Related help topics
  • What is Redis?

    Redis means REmote DIctionary Server. Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache, and message broker. Redis provides data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes, and streams.

    You can run atomic operations on these types, like appending to a string; incrementing the value in a hash; pushing an element to a list; computing set intersection, union and difference; or getting the member with highest ranking in a sorted set.

    To achieve top performance, Redis works with an in-memory dataset. Depending on your use case, you can persist your data either by periodically dumping the dataset to disk or by appending each command to a disk-based log. You can also disable persistence if you just need a feature-rich, networked, in-memory cache.

    Redis also supports asynchronous replication, with very fast non-blocking first synchronization, auto-reconnection with partial resynchronization on net split.

  • What is the Redis memory footprint?

    To give you a few examples (all obtained using 64-bit instances):

    An empty instance uses ~ 3MB of memory.

    1 Million small Keys -> String Value pairs use ~ 85MB of memory.

    1 Million Keys -> Hash value, representing an object with 5 fields, use ~ 160 MB of memory.

    Testing your use case is trivial. Use the redis-benchmark utility to generate random data sets then check the space used with the INFO memory command.

    64-bit systems will use considerably more memory than 32-bit systems to store the same keys, especially if the keys and values are small. This is because pointers take 8 bytes in 64-bit systems. But of course the advantage is that you can have a lot of memory in 64-bit systems, so in order to run large Redis servers a 64-bit system is more or less required. The alternative is sharding.

  • What happens if Redis runs out of memory?

    Each instance goes with 16 MB of memory which is why the Redis instances go with Redis memory.

    Redis will either be killed by the Linux kernel OOM killer, crash with an error, or will start to slow down. With modern operating systems malloc() returning NULL is not common, usually the server will start swapping (if some swap space is configured), and Redis performance will start to degrade, so you'll probably notice there is something wrong.

    Redis has built-in protections allowing the user to set a max limit to memory usage, using the maxmemory option in the configuration file to put a limit to the memory Redis can use. If this limit is reached Redis will start to reply with an error to write commands (but will continue to accept read-only commands), or you can configure it to evict keys when the max memory limit is reached in the case where you are using Redis for caching.

    The INFO command reports the amount of memory Redis is using so you can write scripts that monitor your Redis servers checking for critical conditions before they are reached.

  • How to use Redis?

    To use Redis, please enable the Redis extension from the control panel at Advanced -> PHP Settings -> Edit php.ini -> Redis On.

    To have Redis enabled your plan needs to have Redis instances available. In case you need to add one or more, you can purchase it as an upgrade from the Add/Upgrade service(s) section in the hosting control panel.

    Each instance goes with 16 MB of memory which is why the Redis instances go with Redis memory.

    Important: many applications require host and port to link them with Redis. On our system the Redis works on a Socket instead of Port.

    In this case you need to use

    Redis hostname(IP): unix:///home/sys/redis.sock

    Redis Port: 0

    Example:

    # Update with Redis instance details
    env_variables:
    REDISHOST: 'unix:///home/sys/redis.sock'
    REDISPORT: '0'

    # Update with Serverless VPC Access connector details
    vpc_access_connector:
    name: 'projects/<PROJECT_ID>/locations/<REGION>/connectors/<CONNECTOR_NAME>'

    Redis Persistence

    Redis provides a different range of persistence options:

    Persistence Yes: The RDB persistence performs point-in-time snapshots of your dataset at specified intervals.
    Persistence No: If you wish, you can disable persistence completely, if you want your data to just exist as long as the server is running.

    Parameters: If you do not specify a parameter for your Redis instance, then a default parameters appropriate to your engine version will be used. You can't change the values of any parameters in the default parameter group. However, you can add a custom parameter and assign it to your instance at any time.

  • Top Redis Use Cases

    1. Session Cache
    One of the most apparent use cases for Redis is using it as a session cache. The advantages of using Redis over other session stores, such as Memcached, is that Redis offers persistence. While maintaining a cache isn’t typically mission critical with regards to consistency, most users wouldn’t exactly enjoy if all their cart sessions went away, now would they?

    Luckily, with the steam Redis has picked up over the years, it’s pretty easy to find documentation on how to use Redis appropriately for session caching. Even the well-known ecommerce platform Magento has a plug in for Redis!

    2. Full Page Cache (FPC)
    Outside of your basic session tokens, Redis provides a very easy FPC platform to operate in. Going back to consistency, even across restarts of Redis instances, with disk persistence your users won’t see a decrease in speed for their page loads—a drastic change from something like PHP native FPC.

    To use Magento as an example again, Magento offers a plugin to utilize Redis as a full page cache backend.

    As well, for your WordPress users out there, Pantheon has an awesome plugin named wp-redis to help you achieve the fastest page loads you’ve ever seen!

    3. Queues
    Taking advantage of Redis’ in memory storage engine to do list and set operations makes it an amazing platform to use for a message queue. Interacting with Redis as a queue should feel native to anyone used to using push/pop operations with lists in programming languages such as Python.

    If you do a quick Google search on “Redis queues,” you’ll soon see that there are tons of open-source projects out there aimed at making Redis an awesome backend utility for all your queuing needs.

    4. Leaderboards/Counting
    Redis does an amazing job at increments and decrements since it’s in-memory. Sets and sorted sets also make our lives easier when trying to do these kinds of operations, and Redis just so happens to offer both of these data structures.

    5. Pub/Sub
    Last (but certainly not least) is Redis’s Pub/Sub feature. The use cases for Pub/Sub are truly boundless. I’ve seen people use it for social network connections, for triggering scripts based on Pub/Sub events, and even a chat system built using Redis Pub/Sub!

Post a Comment

Previous Post Next Post