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

Script.Run() NOSCRIPT fallback not working in pipeline context #3228

Open
angus-langchain opened this issue Jan 13, 2025 · 0 comments
Open

Comments

@angus-langchain
Copy link

Expected Behavior

When using Script.Run() within a Redis pipeline/transaction, if a script hasn't been loaded (triggering NOSCRIPT), the method should automatically fall back to EVAL as it does in non-pipeline contexts. This is the documented behavior in the Run() method comment: "Run optimistically uses EVALSHA to run the script. If script does not exist it is retried using EVAL."

Current Behavior

When using Script.Run() within a pipeline/transaction, the NOSCRIPT fallback mechanism fails to work. The pipeline execution fails with "NOSCRIPT No matching script. Please use EVAL" instead of automatically falling back to EVAL.

Steps to Reproduce

  1. Create a new Redis client and flush existing scripts
  2. Create a pipeline
  3. Attempt to run a script using Script.Run() within the pipeline
  4. Execute the pipeline

Minimal reproduction:

package main

import (
    "context"
    "testing"
    
    "github.com/redis/go-redis/v9"
    "github.com/stretchr/testify/assert"
)

func TestScriptRunPipelineFallback(t *testing.T) {
	ctx := context.Background()
	client := redis.NewClient(&redis.Options{
		Addr: "localhost:6379",
	})
	defer client.Close()

	err := client.ScriptFlush(ctx).Err()
	assert.NoError(t, err)

	script := redis.NewScript(`
        return ARGV[1]
    `)

	pipe := client.TxPipeline()

	script.Run(ctx, pipe, []string{}, "test_value")

	_, err = pipe.Exec(ctx)
	assert.NoError(t, err) // This fails with NOSCRIPT error
}

Context (Environment)

  • go-redis version: v9
  • Go version: 1.23.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant