Hot answers tagged

17

Redis doesn't support nested data structures, and specifically it doesn't support a Hash inside a Hash :) You basically have a choice between two options: either serialize the internal Hash and store it in a Hash field or use another Hash key and just keep a reference to it in a field of the outer Hash.


10

Use the maxmemory to set a limit to how much your Redis database can grow too. Failing to do so, Redis will grow until the OS will kill it once memory is exhausted (per your current experience). The usage of maxmemory should be coupled with maxmemory-policy - you can choose from different eviction policies depending on your use case's requirements. For ...


5

This is almost certainly memory fragmentation, as redis is well-known and loved in production and you probably haven't found a memory leak. The recommendations about setting the size of the pool won't help fragmentation. You'll have to specifically lower the Redis size - lower than your actual memory size - because Redis can't account for fragmentation - ...


5

Redis doesn't come out of the box with the ability to search/index inside hashes, but it gives you all the tools you need to accomplish your task. Your challenge could be solved, for example, by keeping a key in the database called last_user_registered or similar, and SETting it every time that a user registers to that user's ID. When you want to fetch the ...


5

I should read sentinel doc carefully. It's mentioned in sections Adding or removing Sentinels and Removing the old master or unreachable slaves. These are steps: Shut down the redis slave to be removed. Remove slaveof statement from conf # Generated by CONFIG REWRITE slaveof 10.128.130.139 6379 Send a SENTINEL RESET mastername command to all Sentinel ...


5

Range stands for one-dimensional distance while radius is standing for two-dimensional one. Let's the data is the timestamp. It is one-dimensional and you can define part of data "in range" or timestamp BETWEEN a AND b. If your data represents the plane of points x:y then you can define part of them as "points closer than radius Z to the given point" or (x-...


3

Preface: keys in Redis do not get deleted, unless explicitly requested or when the server is configured with an eviction policy (and RAM is pressured). Regrettably, the most common cause for missing keys is security, or rather the lack of it. Script kids, leet haxors and regular bad guys take advantage of unprotected servers and cause all kinds of havoc. ...


3

Yes. Every modification (also delete) of data gets written to AOF. See Redis persistence demystified blog posting. Append only file The Append Only File, usually called simply AOF, is the main Redis persistence option. The way it works is extremely simple: every time a write operation that modifies the dataset in memory is performed, the operation ...


3

Actually there is but not where you'd intuitively think of looking for it. Have a look at SORT - this should do what you need: SORT myset BY nosort STORE mylist


3

I had the same problem and this answer was helpful. even though Redis isn’t using the memory anymore, the allocator just hasn’t released the memory back to the OS yet. Reds v4 has a MEMORY PURGE command to tell the allocator to release the memory it isn’t using, but unfortunately that isn’t available to you on v3.2.


3

Redis doesn't do scheduling of jobs/scripts - you'll have to use something (e.g. cron) to trigger the script. The script itself sounds simple enough - LRANGE should be used to iterate the list's elements, sum them up, SET total-count to the result and DEL the list. Lua would be perfect for this but you can also .sh with redis-cli for example. What bothers ...


2

Since you're trying to serialize work, I'd update a record in a table. CREATE TABLE task_keys ( task varchar(10) primary key, last_executed timestamp with time zone not null, by_worker_id integer ); INSERT INTO task_keys(task, last_executed) VALUES ('FOO', '-infinity'); then to see if you can run a task yet: UPDATE task_keys SET last_executed = ...


2

It is possible to reconfigure redis on the fly but it won't re-read the config file until the next restart. To do this you have to use the CONFIG command to change the value. Snippet from http://redis.io/topics/config Changing Redis configuration while the server is running It is possible to reconfigure Redis on the fly without stopping and restarting ...


2

See Looking at Redis from Percona (they are primary MySQL experts). They describe differences between Redis and MySQL. The blog posting is a little bit dated (2009). Redis and MySQL have different use case. I call Redis semi-persistent because it does not store the data on disk immediately but rather dumps its all database every so often – you have a ...


2

There are too many differences to enumerate. The choice between them is heavily based on your application, which you have not described. That setting affects writes, not reads. If you are not exceeding 100 queries per second on slow spinning drives, MySQL will do just fine. Or, if it does not, then we should look at your indexes and queries.


2

TL;DR you should only use one sequence for all conversations. – a_horse_with_no_name Sequence per Conversation DDL statements are known to be expensive. Additionally, it usually requires serialization to the Data Dictionary. You cannot create multiple sequences simultaneously. This method is a "bad idea". Value in a Table To prevent duplicate IDs, ...


2

My experience is mostly in Oracle. But from a database perspective getting a sequence is like a Java singleton. One process can get one sequence at a time. The more sequences that you need to generate and the more nodes that are generating sequences the higher the latency for inserts. You can look at using uuids. Natural keys are best. Like a user_id and ...


1

Yes. If your primary instance crashes and restarts it will be empty; at this point your replica will also become empty, that would be a disaster. Have a read of the replication docs https://redis.io/topics/replication . It suggests if you really want to avoid writing to storage in your primary (which really shouldn’t be a big deal with modern hardware), you ...


1

Redis is a Key-Value (KV) store, and KV stores generally are well suited for cache however provide additional functionality. KV stores can provide synchronisation between a variety of stateless front ends which is what this commands provide.


1

If you can install Mysql UDF Plugin, you can using lib_mysqludf_redis plugin to synchronous records between Mysql and Redis by Mysql trigger. Here is a example: CREATE TABLE `player_channel_log` ( id int AUTO_INCREMENT PRIMARY KEY, date datetime, player int, channel varchar(32) ); set up a trigger for the table and call redis ...


1

Redis respects the maxmemory configuration directive. When set to 0 (the default), Redis will try to allocate as much memory as needed. Once it over does it, the OS will kill it. Setting maxmemory to any positive value limits the amount of RAM that Redis will consume for data. When you reach the limit, Redis' behavior will depend on the maxmemory-policy ...


1

An RDB would be the fastest way to replace/create an entire dataset. You can prepare the bi-annual forklift update beforehand at HQ at your convenience and ship it out to the customers. Do note that loading from RDB requires downtime. As for the 0.1-1K updates/day per client-local Redis database - some of the real questions are: How many updates are done ...


1

As a workaround, you could have a field OLD_VALUE that is filled by your application logic together with the real field in a transaction. Doing so, you would also get a notification for the old value


1

a Foreign Data Wrapper (fdw) point and interpret the data (keep no data),its like a view. Is the redis_fdw compiled on the slave side? if not complile it and master and salve points to your RD1-Table.


1

I suggest ReJSON. It is built to handle these issues exactly. You can use the path notation to access nested elements.


1

I can save all user_id under a key 'New York', but that's ugly isn't it. No, it isn't ugly and it's very much what any RDBMS does when it maintains an index. The difference with Redis is that it doesn't do that for you so you'll have to do these keys' management in the code. But, what should I do if want to get all user younger than 20, or all user live ...


1

I'm just throwing this out there but have you thought of using a MQ for writes? We're using RabbitMQ for writes and federating it out to multiple data centers where each one has a flexihash cluster of ~20 Redis servers. So far it's working well for us and you can increase or decrease the size of each cluster independently as long as your rebalancing them ...


Only top voted, non community-wiki answers of a minimum length are eligible