Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SELECT failed: ERR invalid DB index BUG db is db0 #390

Closed
luoxun opened this issue Nov 11, 2016 · 13 comments
Closed

SELECT failed: ERR invalid DB index BUG db is db0 #390

luoxun opened this issue Nov 11, 2016 · 13 comments

Comments

@luoxun
Copy link

luoxun commented Nov 11, 2016

we are using laravel predis , but now we are having a problem as follow:
SELECT failed: ERR invalid DB index

I use command line to connect ,it works fine, I use db0, set and get work fine;
but in laravel predis ,when i use db 0, got a problem "SELECT failed: ERR invalid DB index
"; when I changed it into db1 ,db2,......,it's fine

here is my predis version
predis/predis v1.1.x-dev 0e17edb Flexible and feature-complete
and this is my redis version
redis-server redis_version:3.2.5

pls tell me how to fix this ,thx a lot

@nrk
Copy link
Contributor

nrk commented Nov 11, 2016

I don't use Laravel so I don't know what it does under the hood to configure Predis but setting database=0 (or "database" => 0 if using named arrays) in the connection parameters of Predis\Client works as expected. You should try using Predis alone and do the same to see if you get the same error response from Redis. If it works as expected, then this is not an issue related to Predis.

@nrk nrk closed this as completed Nov 17, 2016
@JackSW
Copy link

JackSW commented Dec 12, 2016

@luoxun I just had a similar issue with laravel. When specifying the index, make sure to put the 0 in quotes, otherwise it just gets evaluated as false which ends up passing an empty string to the predis client.
REDIS_DATABASE = 0 gets turned into "database":"" and gives ERR invalid DB index
REDIS_DATABASE = "0" results in "database":"0" and works

@itsmylab
Copy link

itsmylab commented Sep 2, 2019

I know I'm bumping a old thread, but for me setting REDIS_CACHE_DB to 0 sorted things out

@ybizeul
Copy link

ybizeul commented Sep 15, 2019

Finally figured it out. not sure I understand though.

I'musing docker links, and naming my redis server : redis. That's an issue because of environment variable conflict, so I changed my redis server to redis-server.

But then I ried using just the url parameter as tcp://redis-server:6379 but kept getting the same error.

I finally commented out urland use hostand it works.

    'redis' => [

        'client' => env('REDIS_CLIENT', 'predis'),

        'options' => [
            'cluster' => env('REDIS_CLUSTER', 'predis'),
            'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'),
        ],

        'default' => [
            #'url' => 'tcp://redis-server:6379/',
            'host' => env('REDIS_HOST', 'redis-server'),
            'password' => env('REDIS_PASSWORD', null),
            'port' => env('REDIS_PORT', 6379),
            'database' => env('REDIS_DB', 0),
        ],
    ],

@gjae
Copy link

gjae commented Oct 29, 2019

Finally figured it out. not sure I understand though.

I'musing docker links, and naming my redis server : redis. That's an issue because of environment variable conflict, so I changed my redis server to redis-server.

But then I ried using just the url parameter as tcp://redis-server:6379 but kept getting the same error.

I finally commented out urland use hostand it works.

    'redis' => [

        'client' => env('REDIS_CLIENT', 'predis'),

        'options' => [
            'cluster' => env('REDIS_CLUSTER', 'predis'),
            'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'),
        ],

        'default' => [
            #'url' => 'tcp://redis-server:6379/',
            'host' => env('REDIS_HOST', 'redis-server'),
            'password' => env('REDIS_PASSWORD', null),
            'port' => env('REDIS_PORT', 6379),
            'database' => env('REDIS_DB', 0),
        ],
    ],

THANKYOU!!! it work!

@osahady
Copy link

osahady commented Mar 25, 2020

in .env file just add the following
REDIS_CACHE_DB=0

and it works

@PetengDedet
Copy link

Finally figured it out. not sure I understand though.
I'musing docker links, and naming my redis server : redis. That's an issue because of environment variable conflict, so I changed my redis server to redis-server.
But then I ried using just the url parameter as tcp://redis-server:6379 but kept getting the same error.
I finally commented out urland use hostand it works.

    'redis' => [

        'client' => env('REDIS_CLIENT', 'predis'),

        'options' => [
            'cluster' => env('REDIS_CLUSTER', 'predis'),
            'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'),
        ],

        'default' => [
            #'url' => 'tcp://redis-server:6379/',
            'host' => env('REDIS_HOST', 'redis-server'),
            'password' => env('REDIS_PASSWORD', null),
            'port' => env('REDIS_PORT', 6379),
            'database' => env('REDIS_DB', 0),
        ],
    ],

THANKYOU!!! it work!

You saved my day

@Mllexx
Copy link

Mllexx commented Jan 8, 2021

in .env file just add the following
REDIS_CACHE_DB=0

and it works

This worked for me thanks.

@pratik-nickelfox
Copy link

I know I'm bumping a old thread, but for me setting REDIS_CACHE_DB to 0 sorted things out

Thank you so much.. :)

@MCKLtech
Copy link

MCKLtech commented Nov 1, 2021

+1 for adding REDIS_CACHE_DB equal to zero in the .env file (I'm using Heroku)

If anyone could explain why this would be the case, I'd be curous.

@rintoug
Copy link

rintoug commented Mar 12, 2022

in .env file just add the following REDIS_CACHE_DB=0

and it works

This worked for me in Laravel Version 7 and redislab free plan

@obipascal
Copy link

Setting the REDIS_CACHE_DB=1 or greater works fine!

@eskayamadeus
Copy link

Setting the REDIS_CACHE_DB=1 or greater works fine!

Brilliant. In my understanding, the value of REDIS_CACHE_DB just points to a name that should be used for the database. Therefore, any value at all should work, not just 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests