Questions tagged [redis]

Redis is an open source, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.

Redis

Redis is a BSD-licensed, advanced key-value store which works in-memory but provides disk persistence. It is often referred to as a data structure server since keys can contain as values different data structures:

  • Strings, which are binary safe and up to 512 MB in size.

  • Lists, offering O(1) push/pop/trim/length operations regardless of the number of elements contained inside the list. Lists also provide blocking operations (pop-style commands that block if there are no elements in the list), so Redis lists are often used in order to implement background jobs and other kinds of queues. There are very popular libraries like Resque and Sidekiq using Redis as a backend.

  • Hashes are field-value maps like in most programming languages. They are useful in order to represent objects and are very memory efficient for a small number of fields, yet very scalable supporting up to 2.14 billion fields per hash.

  • Sets are unordered collections of elements and are useful in order to add, remove, and test elements for existence in constant-time. Small sets of integers are extremely space efficient, and but sets scale up to 2.14 billion elements per set. It is possible to ask for random elements inside sets which is very useful. See SPOP and SRANDMEMBER for more information.

  • Sorted sets are very useful data structures where collections or elements are ordered by a floating point number called score. The data structure offers a set of very powerful operations running in logarithmic time: it is possible to add and remove elements, increment the score of elements, get ranges by rank and by score, given an element get its position (rank) or score, and so forth. A notable application is leader boards involving million of users: there are companies using Redis sorted sets in order to implement leader boards of popular games such as Facebook games.

  • Counters are not exactly a type per se, but actually operations you can use with strings that represent integers. For example, the command INCR mykey will automatically create a key with the string value "1" if the key does not exist. The next call will modify the value of the string into "2", and so forth. You can increment and decrement by floats or by any amount. Values are in the range of a signed 64-bit number even when using Redis on 32-bit architectures.

  • Bit operations like counters operate in strings in a different way. The user is basically able to treat the string as an array of bits, doing very memory-efficient operations. For example, if you have ten million users and want to store a boolean value for every user, you'll need just a bit more than 1 MB of memory! Because of the rich set of bitwise commands you can: count the number of set bits with BITCOUNT; perform bitwise AND, OR, XOR, and NOT between bitmaps using BITOP; find the first bit clear or set in a given range with BITPOS; and so forth.

  • HyperLogLog is a probabilistic data structure that efficiently (in terms of computational and memory complexity) addresses the count-distinct problem. The Redis implementation of HLL requires only 12KB for each counter and exhibits a standard error of 0.81%. HLLs can be added with items, merged and counted using the PFADD, PFMERGE and PFCOUNT commands, respectively (the PF prefix of the commands is in honor of Phillipe Flajolet, HyperLogLog's inventor).

To get started quickly, try Redis directly inside your browser, read this quick intro to Redis data types, or watch a great presentation by Peter Cooper.

Features as a data store

While Redis is an in-memory system, it offers a lot of features of a data store.

  • Tunable on-disk persistence with a point-in-time snapshotting persistence, or an Append Only File with tunable fsync policy.
  • Asynchronous replication.
  • Redis is also a very fast Pub/Sub server.
  • An API to configure Redis at runtime and automatically rewrite the configuration file.
  • Automatic failover and monitoring via Redis Sentinel.
  • Shared-nothing clustering is available from v3.

It has an impressive ecosystem of client libraries for all the mainstream and elite programming languages.

Community

The Redis community is big and willing to help.

Support

If you are looking for commercial support, please see the community page at http://redis.io/support for more information

48 questions
19
votes
2 answers

Redis takes up all the Memory and Crashes

A redis server v2.8.4 is running on a Ubuntu 14.04 VPS with 8 GB RAM and 16 GB swap space (on SSDs). However htop shows that redis alone is taking up 22.4 G of memory! redis-server eventually crashed due to out of memeory. Mem and Swp both hits 100%…
Nyxynyx
  • 1,131
  • 6
  • 18
  • 29
18
votes
2 answers

redis newbie - how to create hash within a hash?

I want to create this type of a structure in redis: (its basically json data) { "id": "0001", "name":"widget ABC", "model": "model123", "service":"standard", "admin_password": 82616416, "r1": { …
Happydevdays
  • 355
  • 1
  • 2
  • 9
6
votes
1 answer

WRONGPASS invalid username-password pair or user is disabled when connect to redis 6.0+

I am tried to connect redis 6.0+, this is the Python celery redis broker url I am config now: broker_url = redis://:default:123456@cruise-redis-headless.reddwarf-cache.svc.cluster.local:6379/5 celery_result_backend =…
Dolphin
  • 929
  • 5
  • 21
  • 40
5
votes
1 answer

Search a Redis Database

Imagine having a tun of hashes in a Redis Database, each representing a user object. How would you get the user with for example the lowest registration date? The user where ts_registered is the lowest. I searched a bit on the Commands Page on…
Jeroen
  • 163
  • 2
  • 8
5
votes
1 answer

What are 'Range' and 'Radius' queries and what is the difference between them?

While searching for easy and effective tools to improve performance of Data fetching for our application, we bumped into "Redis". In documentation of redis, there is following specific mention of these two types or categories of queries: It…
Karan Desai
  • 173
  • 8
5
votes
1 answer

Redis remove slave from replication along with sentinel

I have a 3-nodes Redis replication and a 3-nodes Sentinel. I want to remove one slave. I tried stop slave and remove slaveof 10.128.130.139 6379 from configuration. But it became slave again after I started it. And slaveof was back again in…
gzc
  • 323
  • 1
  • 4
  • 13
4
votes
1 answer

How to correctly use PostgreSQL to limit multiple and/or concurrent executions of a task

Let's assume you have a task FOO that can be queued once every minute, and a pool of 50 workers that can be paused. The queue is paused for 10 minutes, and 10 FOO tasks are queued. When the queue is resumed, the 10 FOO tasks will be executed almost…
Simone Carletti
  • 341
  • 3
  • 14
4
votes
0 answers

What's the best practice when deploying Redis replication cluster on 2 data centers connected by MPLS?

I deployed Redis replication cluster on 2 data centers (ping time between 2 DCs is around 1ms). I used Master (Node1 on DC 1) - Slave (Node2 in DC2) replication model and Sentinel to control promoting or demoting. I faced some scenarios with issues…
misamap
  • 41
  • 2
4
votes
1 answer

Lost persistance in long term in redis without TTL

Our keys are lost in some time and we cannot find the problem. We are using AOF and RDB at the sametime with configs below: RDB: save 900 1 save 300 10 save 60 10000 stop-writes-on-bgsave-error yes rdbcompression yes rdbchecksum yes dbfilename…
Lupus
  • 143
  • 5
3
votes
2 answers

MySQL configure as ACI vs Redis

i have an use case in my application where i need real time communication between users based on their position. Basically one user will create an "event" and it will be sent to near users. On the server side i'm planning use redis or mysql to…
RenkoSmith
  • 75
  • 1
  • 4
2
votes
1 answer

Distributing a semi-large key/value list

I have a semi-large (around 30 million records) key/value list which I want to load into redis. The data is stored in PostgreSQL (as master data) and we want to distribute this to clients for faster (local) lookups. The keys are Belgium telephone…
Gert
  • 121
  • 3
2
votes
0 answers

Sensor data from Postgres to Redis

I have a Postgres database with a table that is updated with new data every 5 minutes from a weather station. Now, as soon as the table is updated with a new record from the sensor, I would like this new record to be sent to a Redis Stream…
2
votes
1 answer

Are Delete operations written to AppendOnlyFile in Redis?

AppendOnlyFile in Redis logs every write operation done to the redis database. My Question is that when we delete data from the redis database, are those operations logged in the AppendOnlyFile ? And the data which is deleted from the database, is…
luv.preet
  • 135
  • 6
2
votes
2 answers

After lowering maxmemory, redis still has high RSS memory

I would like Redis to return some memory. I lowered the maxmemory by 10GB but noticed Redis is still "holding onto it" in RSS based on "used_memory_rss". Based on http://redis.io/topics/memory-optimization, it looks like Redis won't return the…
2
votes
1 answer

How to get old and new values on Redis notification?

I need to implement a feature like: once any specific key in Redis is updated, call a C function with the old and new values as arguments. Currently, I know Redis notification and I could use hiredis to subscribe a keyspace event. While Redis…
Qiu Yangfan
  • 157
  • 6
1
2 3 4