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
8
votes
1 answer

redis: EVAL and the TIME

I like the Lua-scripting for redis but i have a big problem with TIME. I store events in a SortedSet. The score is the time, so that in my application i can view all events in given time-window. redis.call('zadd', myEventsSet, TIME, EventID); Ok,…
Thomas Deutsch
  • 2,344
  • 2
  • 27
  • 36
8
votes
2 answers

Flask: passing around background worker job (rq, redis)

I want to do a very simple thing: Launch a worker to something and then return the answer to user. I'm trying to do so using a combination of Flask and RQ. import os from flask import Flask, session from somewhere import do_something from rq import…
Julius
  • 81
  • 1
  • 3
8
votes
3 answers

unable to install redis 2.7+ on ubuntu 12.04

I am new to redis. and I just followed cli to install redis sudo apt-get install redis. but the install server version is 2.2.12 . If I want to update this version and I want to install redis 2.7 + then how can I do this thing, please help. I am…
Rohitashv Singhal
  • 4,517
  • 13
  • 57
  • 105
8
votes
1 answer

How to ensure multiple redis instances running on different cores?

I've a 4-core server and I want to run redis on it. To fully utilize the capabilities of the 4 cores, it is expected to launch 4 redis instances, since redis is designed to be single-threaded. However, I'm curious how to ensure that the 4 instances…
ciphor
  • 8,018
  • 11
  • 53
  • 70
8
votes
0 answers

{solve}redis: localhost:6379. Cannot assign requested address

UPDATE: I have solved the problem,from the log, I saw that the db was opening and closing frequently. I had put the redis creation in a for loop. So...foolish question,if anyone's log like me, check for looping. I tried shutting it down and…
kuafu
  • 1,466
  • 5
  • 17
  • 28
8
votes
1 answer

Column family stores vs document stores

I've read several posts, such as this one, that compare document stores like MongoDb, CouchDb and CouchBase with column family stores like Cassandra. One comparison is the fact that document stores work at a higher level of granularity as opposed to…
Kailash
  • 785
  • 1
  • 8
  • 17
8
votes
2 answers

socket.io broadcast function & Redis pub/sub architecture

i would appreciate if somebody could help me with a small doubt. Whats the difference between using socket.io broadcast function and designing the architecture with pub/sub on Redis?. For instance, on the further example, the node.js server is…
user1106811
  • 297
  • 4
  • 14
8
votes
1 answer

HAproxy for redis slaves

We are using node_redis client to access the redis at present. I need to use HAProxy in front of redis slaves which in my case is 3 nos. I installed the HAProxy and configured it to load balance the redis slaves. But when I tried to create…
user1386776
  • 395
  • 3
  • 8
  • 13
8
votes
1 answer

Can Redis be run in-process w/.net?

Is it possible to run Redis in process under .NET? I understand the general use case is for Redis is out of process, and likely on another server. The app I'm working on has needs for both in-process caching and out of process caching. My thinking…
EBarr
  • 11,826
  • 7
  • 63
  • 85
8
votes
2 answers

How do you kill a redis client when there is no connection?

I have a valid server configuration in which redis can't be accessed, but the server can function correctly (I simply strip away features when redis can't be found). However, I can't manage the connection errors well. I'd like to know when a…
Greg
  • 2,559
  • 4
  • 28
  • 46
8
votes
1 answer

node.js / socket.io, cookies only working locally

I'm trying to use cookie based sessions, however it'll only work on the local machine, not over the network. If I remove the session related stuff, it will however work just great over the network... You'll have to forgive the lack of quality code…
BenOfTheNorth
  • 2,904
  • 1
  • 20
  • 46
8
votes
3 answers

PHP Redis Error: Uncaught exception ‘RedisException’

I use Redis to build a IOS SNS App (for restful api). As more user use it, errors happened. It throws out : Uncaught exception 'RedisException' with message 'read error on connection' in /data1/www/htdocs/11/iossns/Model/Core/Redis.php I don't…
taogogo
  • 81
  • 1
  • 3
7
votes
2 answers

Configure Redis slave to stop saving data to file

Can I configure Redis slave to stop saving dumps? I have omitted all save instructions in config file but slave is still doing dumps.
Sebastian Sito
  • 163
  • 3
  • 10
7
votes
1 answer

Redis: Excluding values from sorted set based on hash field value

I was wondering if anyone could provide some suggestions on how to make sorted set generation more efficient? I am working on a project where ranking data is calculated on an hourly basis and stored in a database. The data can be filtered by member…
Bobby Sciacchitano
  • 851
  • 1
  • 10
  • 19
7
votes
2 answers

can multiple clients access same list concurrently without getting blocked in Redis?

Suppose there are two clients which are accessing same redis list datastructure. One is doing LPOP and other is doing RPUSH on the same list. Will there be a any contention between these two clients if they are running in parallel ? Will Redis lock…
Ameliorator
  • 417
  • 1
  • 5
  • 10
1 2 3
99
100