Questions tagged [redis]

Redis is an open source (BSD licensed), 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, geospatial indexes with radius queries and streams. It also provides pub-sub capabilities. Use this tag for questions related to Redis and in-memory system.

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.

  • Geo sets are sorted sets in which elements' scores are used for storing locations - longitude and latitude - as geohash-encoded values. Once stored in this fashion, the elements can be queried by their distance from an arbitrary position with the GEORADIUS command. Geospatial indexes are used by any location-based application and service, including: social networks, navigation & commuting assistance and fleet management.

  • 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.

  • Bit fields are strings that, similarly to bit operations, are treated as an array of bits. These allow referencing integers of varying types (unsigned or signed 1-bit to 64-bits and 63-bits, respectively) by offset or position. Each such bit field can be read, written or incremented and supports several overflow modes via the use of the BITFIELD command.

  • 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).

  • Streams, that are structures that provide an abstraction of log-like append-only data. Messages in the stream are added by producers with the XADD command, and the processing of these is done by consumers with the XREAD. Streams also support the concept of Consumer Groups via the XREADGROUP for simple and efficient scaling.

  • Modules, that are basically just dynamically-loaded server-side libraries, can developed and used by anyone and everyone for extending the core Redis platform with anything from custom data types (e.g. a Bloom Filter) to full-fledged servers (e.g. a search engine). Modules are supported as of v4.

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.

Persistency

There are two options for persistency in Redis:

  • RDB (Redis Database File): This option takes snapshot from database periodically.
  • AOF (Append Only File): Logs every write operation and reconstructs dataset at startup.

RDB is faster than AOF but loses created data after the latest snapshot.

Support

Support for Redis is provided by the following companies:

Certification

Redis has a Professional Certification program at no cost! There are three prerequisite courses that must be successfully completed before enrolling in the Developer Certification Program:

  1. Introduction to Redis Data Structures
  2. Redis Streams
  3. Any other elective Redis University class of your choice.

The Redis Certified Developer exam is a timed, 90-minute multiple-choice test. You can schedule your exam at any time and take it from any location, including your own home. You can learn more about the Redis Certified Developer Program from the official certification page.

Related tags

24955 questions
57
votes
7 answers

Sidekiq jobs stuck in enqueue

Sidekiq has been working in development mode just perfectly. Now that I am trying to use it in production, all the jobs are just sitting in enqueue and aren't ever being run. Could anyone point me in the right direction as to how to solve this…
groffcole
  • 871
  • 1
  • 7
  • 18
56
votes
2 answers

using different database at redis command prompt

dThe following works as expected. But how do I insert the data into forth database instead of default "0" from command prompt? # echo -n "testing" | /home/shantanu/redis-2.4.2/src/redis-cli -x set my_pass OK # echo -n "testing" |…
shantanuo
  • 31,689
  • 78
  • 245
  • 403
56
votes
4 answers

How to create own database in redis?

There are 0 to 15 databases in redis. I want to create my own database using redis-cli. Is there any command for it?
user3612181
  • 603
  • 1
  • 5
  • 8
56
votes
3 answers

SCAN vs KEYS performance in Redis

A number of sources, including the official Redis documentation, note that using the KEYS command is a bad idea in production environments due to possible blocking. If the approximate size of the dataset is known, does SCAN have any advantage over…
Jake
  • 7,565
  • 6
  • 55
  • 68
56
votes
1 answer

Redis / Get all keys & values from redis with prefix

I store my data in redis. I store in one raw it guid, createday, and it size. So I define the following: var dbclient1 = db.createClient(); dbclient1.hmset("doc:3743-da23-dcdf-3213", "date", "2015-09-06 00:00:01", "size",…
MIDE11
  • 3,140
  • 7
  • 31
  • 53
56
votes
2 answers

About char b prefix in Python3.4.1 client connect to redis

I am run into trouble .My code below.But I do not know why there is a char 'b' before output string "Hello Python". >>> import redis >>> redisClient = redis.StrictRedis(host='192.168.3.88',port=6379) >>> redisClient.set('test_redis', 'Hello…
Zhi Su
  • 573
  • 1
  • 4
  • 4
56
votes
1 answer

Are redis operations on data structures thread safe

How does Redis handle multiple threads (from different clients) updating the same data structure in Redis ? What is the recommended best practice for such a use case?
Soumya Simanta
  • 11,523
  • 24
  • 106
  • 161
56
votes
5 answers

What is the easiest way to find the biggest objects in Redis?

I have a 20GB+ rdb dump in production. I suspect there's a specific set of keys bloating it. I'd like to have a way to always spot the first 100 biggest objects from static dump analysis or ask it to the server itself, which by the way has ove 7M…
sscarduzio
  • 5,938
  • 5
  • 42
  • 54
55
votes
5 answers

Checking if a value exists in a list already Redis

I'm wondering if there's a way to check if a key already exists in a redis list? I can't use a set because I don't want to enforce uniqueness, but I do want to be able to check if the string is actually there. Thanks.
Reu
  • 1,257
  • 3
  • 15
  • 30
55
votes
4 answers

redis bgsave failed because fork Cannot allocate memory

all: here is my server memory info with 'free -m' total used free shared buffers cached Mem: 64433 49259 15174 0 3 31 -/+ buffers/cache: 49224 15209 Swap:…
Jim Gray
  • 571
  • 1
  • 4
  • 4
54
votes
11 answers

Redis raises "NOAUTH Authentication required" error but there is no password setting

I got error NOAUTH Authentication required when I connect to Redis server via command: redis-cli and run ping to check if Redis is working. I found answer for NOAUTH Authentication required error which describes that this error only happens when…
Thanh
  • 8,219
  • 5
  • 33
  • 56
54
votes
6 answers

Redis vs RocksDB

I have read about Redis and RocksDB, I don't get the advantages of Redis over RocksDB. I know that Redis is all in-memory and RocksDB is in-memory and uses flash storage. If all data fits in-memory, which one should I choose? do they have the same…
Guille
  • 2,248
  • 3
  • 24
  • 42
54
votes
7 answers

Redis is configured to save RDB snapshots, but is currently not able to persist on disk

I get the following error, whenever I execute any commands that modify data in redis Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis…
user462455
  • 12,838
  • 18
  • 65
  • 96
54
votes
5 answers

Redis Multi-Set With a TTL

In redis there is a SETEX command that allows me to set a key that expires, is there a multi-set version of this command that also has a TTL? both MSET and MSETNX commands do not have such an option.
Ian
  • 24,116
  • 22
  • 58
  • 96
54
votes
8 answers

Redis bind to more than one IP

In the redis.conf the normal setting is bind 127.0.0.1 I want redis to listen to another ip too (say my local development address) I tried bind 127.0.0.1, 123.33.xx.xx but this does not work. I cannot find any relevant in the document or by…
spacemilkman
  • 943
  • 1
  • 9
  • 15