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
4 answers

Sidekiq: NoMethodError: undefined method `perform'

Here is what I am trying to do: 2.1.2 :001 > UpdateStyleRanks.perform_async Here is the error: NoMethodError: undefined method `perform' for # Here is my worker: # app/workers/update_style_ranks.rb class…
Abram
  • 39,950
  • 26
  • 134
  • 184
8
votes
0 answers

Random NullReferenceException with Redis

I have an intermittent error which shows up in my code. When I debug it using Visual Studio, with break on all exceptions (caught & uncaught) it doesn't break, so I'm not sure what to do. It looks like it's the session state provider from the stack…
Faraday
  • 2,904
  • 3
  • 23
  • 46
8
votes
3 answers

How to synchronize market data frequently and show as a historical timeseries data

http://pubapi.cryptsy.com/api.php?method=marketdatav2 I would like to synchronize market data on a continuous basis (e.g. cryptsy and other exchanges). I would like to show latest buy/sell price from the respective orders from these exchanges on a…
Rpj
  • 5,348
  • 16
  • 62
  • 122
8
votes
1 answer

Redis add more than one item to Sorted Set

I was following this Redis tutorial http://redis.io/topics/twitter-clone At the end of the page they stated Note: LRANGE is not very efficient if the list of posts start to be very big, and we want to access elements which are in the middle of …
user3710273
  • 323
  • 3
  • 8
8
votes
1 answer

Redis as unique atomic id generator - Thread safe way for web app to avoid race condition

I plan to use redis as an unique atomic id generator. However, my concern there might be simulatoneous web requests from multiple browsers. I was wondering, what is the common practice to make the following operations atomic? get id from redis if id…
Cheok Yan Cheng
  • 47,586
  • 132
  • 466
  • 875
8
votes
2 answers

How can I tell if my SignalR Backplane (Redis) is really working as it should?

I'm currently playing SignalR 2.0.3, scaling out with a BackPlane that utilizes Redis for windows http://msopentech.com/blog/2013/04/22/redis-on-windows-stable-and-reliable/ I've integrated with the appropriate SignalR.Redis package in VS. I made…
JohnB
  • 3,921
  • 8
  • 49
  • 99
8
votes
1 answer

Accessing a database from a worker process

I'm trying to put jobs that need access to a database using Python, Redis and PostgreSQL. I'm doing the following: Put jobs in a Redis queue using RQ: def queue_data(self, json_data): Queue().enqueue(process_data, json.dumps(json_data)) In…
jlhonora
  • 10,179
  • 10
  • 46
  • 70
8
votes
2 answers

Async version of ObjectCache?

I'm considering implementing some distributed cache clients (Redis & Memcached) through the ObjectCache class. One thing I noticed is that all the methods on this abstract class are synchronous, meaning none of them return Tasks. Since the calls to…
Paul Fryer
  • 9,268
  • 14
  • 61
  • 93
8
votes
2 answers

Function to replicate the output of java.lang.String.hashCode() in python and node.js

I am trying to implement a function to generate java hashCode equivalent in node.js and python to implement redis sharding. I am following the really good blog @below mentioned link to achieve…
balyanrobin
  • 91
  • 1
  • 5
8
votes
1 answer

How does Redis fit into ASP.NET Web API OData world?

If you think about a large-scale solution where you've a second-level cache implemented using Redis or maybe your first data source is also Redis, I don't find how ASP.NET WebAPI OData implementation can work together with something like a key-value…
Matías Fidemraizer
  • 63,804
  • 18
  • 124
  • 206
8
votes
3 answers

What is the easiest way to simulate a database table with an index in a key value store?

What is the easiest way to simulate a database table with an index in a key value store? The key value store has NO ranged queries and NO ordered keys. The things I want to simulate (in order of priority): Create tables Add columns Create…
yazz.com
  • 57,320
  • 66
  • 234
  • 385
8
votes
4 answers

JedisPoolConfig is not assignable to GenericObjectPoolConfig

I have a Spring based java web application hosted on Heroku. I am attempting to utilize the Spring Caching abstraction using the Redis implementation. When the server starts, I get an error saying: Type 'redis/clients/jedis/JedisPoolConfig'…
user3089280
  • 381
  • 2
  • 4
  • 12
8
votes
3 answers

Redis Error 8 connecting localhost:6379. nodename nor servname provided, or not known

My environment is Mac OS 10.9.2, python3.3, redis-2.6.9 (64-bit). I have many threads (nealy 2000) that use the same redis instance to write data, but some threads throw the following exceptions: During handling of the above exception, another…
flyer
  • 9,280
  • 11
  • 46
  • 62
8
votes
1 answer

Using Redis over secured connection

I have a remote Linux box running a Redis server listening on an open port. I would like to encrypt the traffic, but Redis doesn't support SSH. The suggested solution is to use a SSH tunnel, but I haven't much experience with that. I tried to…
marce
  • 781
  • 1
  • 10
  • 20
8
votes
1 answer

What is meaning of 0/cache in redis://localhost:6379/0/cache

While adding redis as my cache store in Rails app, i added the redis url as redis://localhost:6379/0/cache. What is the meaning of 0/cache in the redis URL?